-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathksupLogisticRegression.m
59 lines (49 loc) · 1.57 KB
/
ksupLogisticRegression.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
59
function [w,costs] = ksupLogisticRegression(X,Y,lambda,k,w0, ...
iters_acc,eps_acc);
% Author: Matthew Blaschko - [email protected]
% Copyright (c) 2012-2013
%
% Run Ksupport norm using logistic 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 = round(size(X,2)/4);
end
if(size(X,1)>size(X,2)) % lipschitz constant for gradient
L = eigs(X'*X,1)/4;
else
L = eigs(X*X',1)/4;
end
[w,costs] = overlap_nest(@(w)(LogisticLoss(w,X,Y)),...
@(w)(gradLogisticLoss(w,X,Y)), lambda, ...
L, w0, k, iters_acc,eps_acc);
end
function l = LogisticLoss(w,X,Y)
l = sum(log(1+exp(-Y.*(X*w))));
end
function g = gradLogisticLoss(w,X,Y)
g = -X'*(Y./(1.0+exp(Y.*(X*w))));
end
% end of file