problem.cost = @cost;
function f = cost(X)
Xmat = X.U*X.S*X.V';
f = .5*norm( P.*Xmat - A, 'fro')^2;
end
problem.egrad = @egrad;
function G = egrad(X)
Xmat = X.U*X.S*X.V';
G = P.*Xmat - A;
end
%% Pick the manifold of matrices of size mxn of fixed rank k.
problem.M = fixedrankembeddedfactory(K, K, r);
%% Define the problem cost function f(X) = 1/2 * || P.*(X-A) ||^2
problem.cost = @cost; % The input X is a structure with fields U, S, V representing a rank k matrix as U*S*V'.
function f = cost(X)
Xmat = X.U*X.S*X.V';
f = .5*norm( P.*Xmat - eye(K), 'fro')^2;
end
%% Define the Euclidean gradient of the cost function nabla f(X) = P.*(X-A)
problem.egrad = @egrad;
function G = egrad(X)
% Same comment here about Xmat.
Xmat = X.U*X.S*X.V';
G = P.*Xmat - eye(K);
end
checkgradient(problem);
[U, S, V] = svds(eye(K), r); X0.U = U; X0.S = S; X0.V = V;
%% Notice that for this solver, the Hessian is not needed.
[Xcg, xcost] = conjugategradient(problem, X0);
function foo()
K = 200; r = 3; P = round(rand(K)); P(1:(K+1):end) = 1; A = eye(K); PA = P.*A;
%% Pick the manifold of matrices of size mxn of fixed rank k. problem.M = fixedrankembeddedfactory(K, K, r); %% Define the problem cost function f(X) = 1/2 * || P.*(X-A) ||^2 problem.cost = @cost; % The input X is a structure with fields U, S, V representing a rank k matrix as U*S*V'. function f = cost(X) Xmat = X.U*X.S*X.V';
f = .5*norm( P.*Xmat - PA , 'fro')^2;
end %% Define the Euclidean gradient of the cost function nabla f(X) = P.*(X-A) problem.egrad = @egrad; function G = egrad(X) % Same comment here about Xmat. Xmat = X.U*X.S*X.V';
G = P.*Xmat - PA; end checkgradient(problem); pause;
[U, S, V] = svds(eye(K), r); X0.U = U; X0.S = S; X0.V = V; %% Notice that for this solver, the Hessian is not needed. [Xcg, xcost] = conjugategradient(problem, X0);
[Xcg, xcost] = trustregions(problem, X0);end