Help with MATLAB code on low rank assumption using nuclear norm using CVX and Matlab!

17 ビュー (過去 30 日間)
Karim Wahdan
Karim Wahdan 2021 年 1 月 18 日
コメント済み: Bob Thompson 2021 年 1 月 25 日
I have created code on low rank assumption using nuclear norm using CVX. For some reason my code isnt working and I'm getting the following error message. Any help will be appreciated Thanks!
Error message -
Error using * (line 40)
Inner matrix dimensions do not agree.
Error in Untitled (line 17)
A*Xe(:)==y
Below is my code -
r = 2; % the rank;
n = 32; % the dimension
a = randn(n,r);
b = randn(n,r);
X = a*b'; % low rank Matrix;
m=fix(n^2-1);
A = randn(n, n);
y = trace(A*X);
% low rank approximation using nuclear norm
cvx_begin
variable Xe(n,m)
minimize norm_nuc(Xe)
subject to
A*Xe(:)==y
cvx_end
error = norm(X-Xe)
for m = 1 : 10 : n^2
for mc = 1 : MONTE_CARLO
% Generate measurements
y = zeros(m, 1);
for i_m = 1 : m
A_i = randn(n, n);
y(i_m) = trace(A_i*X);
end
% Solve problem
for i_m = 1 : m
y(i_m) == trace(A_i*Xe);
end
% Store results
end
end
  6 件のコメント
Bob Thompson
Bob Thompson 2021 年 1 月 19 日
Xe is a single value? It looks like you're defining Xe to have n x m size. I'm not super familiar with cvx, so I could be wrong...
Karim Wahdan
Karim Wahdan 2021 年 1 月 19 日
編集済み: Karim Wahdan 2021 年 1 月 19 日
Yes Xe is a variable to hold n and m size. To me the code looks correct so im not sure whats wrong?

サインインしてコメントする。

回答 (1 件)

Bob Thompson
Bob Thompson 2021 年 1 月 19 日
I believe the issue is with calling Xe(:) instead of Xe. Others who know more might be able to correct me, but my working theory is that A*Xe works because it's doing matrix math, and the inner dimensions agree, but A*Xe(:) does not work because it's now trying to compare A to each element of Xe, but the number of elements in A does not match the number of elements of Xe.
Are you trying to multiple the two matrices together, or to multiply the elements of the two matrices together?
  3 件のコメント
Karim Wahdan
Karim Wahdan 2021 年 1 月 22 日
編集済み: Karim Wahdan 2021 年 1 月 22 日
@Bob Thompson But I actually have another question after I done this I get a error code -
Unrecognized function or variable 'A_i'.
Error in Untitled3 (line 21)
y(i_m) == trace(A_i)*Xe;
How do I fix this?
Bob Thompson
Bob Thompson 2021 年 1 月 25 日
One issue you're going to have is that you're only going to be comparing y(i_m) == trace(A_i*Xe) using the last A_i array. Yes, I know that doesn't address the issue.
For the issue of undefined A_i, I would double check that you don't have a typo. The code you posted previously does not cause an issue of undefined function/variable. Have you changed the bit of code within the loop that defines the generation of A_i?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by