Download this file

21 lines (16 with data), 417 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
function [m] = LogisticHv(v,w,X,y)
% v(feature,1) - vector that we will apply diagonal preconditioner to
% w(feature,1)
% X(instance,feature)
% y(instance,1)
sig = 1./(1+exp(-y.*(X*w)));
% Compute diagonals of Hessian
sig = sig.*(1-sig);
for i = 1:length(w)
h(i,1) = (sig.*X(:,i))'*X(:,i);
end
% Apply preconditioner
m = v./h;
% Exact preconditioner
%H = X'*diag(sig.*(1-sig))*X;
%m = H\v;