Dear All,
I have written a code using the Manopt toolbox for matrix optimization, but unfortunately, I encountered an error while running it (please see the attached error message).
I would greatly appreciate any guidance or suggestions you might have to help resolve these issues. If you could provide insights on the possible causes or direct me to relevant resources, it would be incredibly helpful.
Thank you in advance for your assistance! I look forward to hearing from you.
function low_rank_matrix_completion_barrier
% Matrix dimensions and rank
m = 50; % Number of rows
n = 40; % Number of columns
r = 5; % Target rank
% Generate a random low-rank matrix A of rank r
U = randn(m,r);
V = randn(n,r);
A = U * V'; % A is a rank-r matrix
% Set of known entries S
S = rand(m,n) > 0.5; % Random mask for observed entries
% Manifold of m x n matrices of fixed rank r
manifold = fixedrankembeddedfactory(m, n, r);
% Objective function: Frobenius norm on the known entries
function F = frob_objective(X)
X_full = X.U * X.V'; % Reconstruct full matrix from factored form
P_X = S .* (X_full - A); % Projection onto known entries
F = 0.5 * norm(P_X, 'fro')^2;
end
% Barrier function to enforce non-negativity constraint
function B = barrier_function(X, mu)
X_full = X.U * X.V'; % Reconstruct full matrix from factored form
P_X = S .* (X_full - A); % Projection onto known entries
% Add log barrier for non-negative constraint
barrier_term = -mu * sum(log(X_full(X_full > 0)), 'all'); % Log barrier
B = 0.5 * norm(P_X, 'fro')^2 + barrier_term; % Objective + barrier
end
% Initial guess on the manifold
X0 = randn(m,r) * randn(n,r)';
% Set up the options for the Manopt solver
options.maxiter = 100; % Maximum number of iterations
options.tolgradnorm = 1e-6; % Tolerance for stopping
% Initial barrier parameter
mu_k = 1;
tol_mu = 1e-6; % Stopping condition for the barrier parameter
% Solve iteratively, reducing the barrier parameter
Xk = X0; % Initial guess
while mu_k > tol_mu
% Solve the unconstrained problem with the barrier term
problem.M = manifold;
problem.cost = @(X) barrier_function(X, mu_k);
problem.egrad = @(X) manifold.egrad(frob_objective(X)); % Gradient
[Xk, xcost, info] = trustregions(problem, Xk, options);
% Print information about the iteration
fprintf('mu = %f, cost = %f\n', mu_k, xcost);
% Decrease barrier parameter
mu_k = mu_k / 2;
end
% Final solution
disp('Final solution found:');
disp(Xk.U * Xk.V'); % Reconstruct final low-rank matrix
end
Error Mesage: > In trustregions (line 327)
In low_rank_matrix_completion_barrier (line 53)
Dot indexing is not supported for variables of this type.
Error in low_rank_matrix_completion_barrier/barrier_function (line 27)
X_full = X.U * X.V'; % Reconstruct full matrix from factored form
^^^
Error in low_rank_matrix_completion_barrier>@(X)barrier_function(X,mu_k) (line 50)
problem.cost = @(X) barrier_function(X, mu_k);
^^^^^^^^^^^^^^^^^^^^^^^^^
Error in getCost (line 59)
cost = problem.cost(x);
^^^^^^^^^^^^^^^
Error in getCostGrad (line 89)
cost = getCost(problem, x, storedb, key);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in trustregions (line 401)
[fx, fgradx] = getCostGrad(problem, x, storedb, key);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in low_rank_matrix_completion_barrier (line 53)
[Xk, xcost, info] = trustregions(problem, Xk, options);