Skip to content

Commit

Permalink
apg lasso handles matrix variables
Browse files Browse the repository at this point in the history
  • Loading branch information
bodonoghue committed Aug 5, 2016
1 parent 448fb2e commit 41a3a29
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
7 changes: 5 additions & 2 deletions examples/apg_lasso.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
opts.A = A;
opts.b = b;
opts.rho = rho;
x = apg(@quad_grad, @soft_thresh, size(A,2), opts);
opts.dims = [size(A,2), size(b,2)];
x = apg(@quad_grad, @soft_thresh, prod(opts.dims), opts);
end

function g = quad_grad(x, opts)
g = opts.A'*(opts.A*x - opts.b);
x_t = reshape(x, opts.dims);
g = opts.A'*(opts.A*x_t - opts.b);
g = g(:);
end

function v = soft_thresh(x, t, opts)
Expand Down
3 changes: 1 addition & 2 deletions examples/apg_log_reg.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
end

function g = lr_grad(w, opts)
v = exp(w'*[opts.X_p, -opts.X_n])';
g = [opts.X_p, -opts.X_n]*(v./(1+v))/opts.N;
g = [opts.X_p, -opts.X_n]*(1./(1+exp(-w'*[opts.X_p, -opts.X_n])'))/opts.N;
end

function v = soft_thresh(w, t, opts)
Expand Down
1 change: 0 additions & 1 deletion examples/run_examples.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
x_lr = apg_log_reg(X_p,X_n,rho,opts);
title('L1 regularized logistic regression')


%% noisy low-rank matrix completion
fprintf('running noisy low-rank matrix completion ex:\n');
n = 100; m = 50; r = 10; density = 0.2; rho = 5;
Expand Down

0 comments on commit 41a3a29

Please sign in to comment.