-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathksupLeastSquares.m
58 lines (50 loc) · 1.56 KB
/
ksupLeastSquares.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function [w,costs] = ksupLeastSquares(X,Y,lambda,k,w0, ...
iters_acc,eps_acc);
% Author: Matthew Blaschko - [email protected]
% Copyright (c) 2012-2013
%
% Run Ksupport norm using squared loss function
% first 3 arguments are required!
%
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 3 of the License, or
% (at your option) any later version.
%
% If you use this software in your research, please cite:
%
% M. B. Blaschko, A Note on k-support Norm Regularized Risk Minimization.
% arXiv:1303.6390, 2013.
%
% Argyriou, A., Foygel, R., Srebro, N.: Sparse prediction with the k-support
% norm. NIPS. pp. 1466-1474 (2012)
if(~exist('eps_acc','var'))
eps_acc = 1e-4;
end
if(~exist('iters_acc','var'))
iters_acc = 2000;
end
if(~exist('w0','var'))
w0 = zeros(size(X,2),1);
end
if(~exist('k','var'))
k = min(size(X,2),1500);
end
if(size(X,1)>size(X,2)) % lipschitz constant for gradient of squared loss
L = 2*eigs(X'*X,1);
else
L = 2*eigs(X*X',1);
end
[w,costs] = overlap_nest(@(w)(squaredLoss(w,X,Y)),...
@(w)(gradSquaredLoss(w,X,Y)), lambda, ...
L, w0, k, iters_acc,eps_acc);
end
function l = squaredLoss(w,X,Y)
Xw = X*w;
l = Xw'*Xw - 2*Xw'*Y + Y'*Y;
end
function g = gradSquaredLoss(w,X,Y)
g = 2*X'*(X*w) - 2*X'*Y;
end
% end of file