-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.m
35 lines (30 loc) · 2.74 KB
/
test.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
trainFeatures =[0.0305285150387533,0.00247733393639111,0.000490841060011102,0.00141984128615777,0.000434304393412964,0.000666875681009848,0.00112559363499928,0.000574361135667441,0.000734976665775786,0.000630897802265579,0.000950843938241401,0.00272146954215579,0.00179889393721346;0.0362644168499825,0.00212269484591189,0.000573076211426574,0.00142369605888037,0.000549947575090973,0.000857044468658128,0.00135045537715096,0.00101894492300734,0.00114872227133488,0.000905871589811065,0.00136715939228223,0.00521936226640077,0.00248118870911371;0.0322593079912008,0.00205202401266421,0.000508829999383236,0.00118470015007915,0.000452293332785099,0.000593634999280443,0.00111145946834975,0.000778664089965256,0.000896877120124997,0.000673300302214182,0.000968832877613536,0.00415416007072223,0.00209699636109455;0.0293386751917107,0.00229487469418803,0.000385477272260028,0.00137229908924570,0.000451008408544232,0.000562796817499640,0.00134017598322403,0.000603914393207377,0.000760675150593121,0.000557657120536173,0.00125151621060422,0.00386248226804548,0.00212397977015275];
trainLabels = [0.156521466919188,0.165224060479895,0.191300536868632,0.156521466919188,0.173911001893910,0.156521466919188;0.148758609404519,0.206610832601937,0.190083751097095,0.157029588087411,0.148758609404519,0.148758609404519;0.179999100004500,0.160004199979000,0.199994000030000,0.160004199979000,0.149999250003750,0.149999250003750;0.115384171599340,0.153841715993400,0.288460428998350,0.205129980269307,0.121799531540263,0.115384171599340];
weights = eye(size(trainFeatures,2),size(trainLabels,2));
modProb = exp(trainFeatures * weights);
modProb = modProb ./ sum(modProb, 2);
lambda1 = 1;
% Target function.
kurtosisDif = kurtosis(trainLabels,1,2)-kurtosis(modProb,1,2);
target = -sum(sum(repmat(kurtosis(trainLabels,1,2),1,L).*trainLabels.*log(modProb+eps)))+ lambda1*sum(max(-kurtosisDif,0));
% The gradient.
[~,L] = size(trainLabels);
m1 = modProb-1/L;
m2 = (modProb-1/L).^2;
m3 = (modProb-1/L).^3;
m4 = (modProb-1/L).^4;
M1= moment(modProb,1,2);
M2= moment(modProb,2,2);
M3= moment(modProb,3,2);
M4= moment(modProb,4,2);
M1 = repmat(M1,1,L);
M2 = repmat(M2,1,L);
M3 = repmat(M3,1,L);
M4 = repmat(M4,1,L);
KurtosisDif = repmat(kurtosisDif,1,L);
gradient1 = trainFeatures'*(modProb - trainLabels);
KurtosisDif = max(KurtosisDif,0);
% gradient2 = -2 * trainFeatures'*(modProb.*(1-modProb).*(4/L*(m3-M3).*(M2.^-2)-4/L*(m1-M1).*M4.*(M2.^-3)).*kurtosisDif);
gradient2 = -2 * trainFeatures'*(modProb.*(1-modProb).*(4/L*(m3.*(M2.^-2)-M3.*(M2.^-2))-4/L*(m1./M2).*(M4./(M2.^2))).*KurtosisDif);
% gradient2 = gradient2./sum(gradient1)/sum(gradient2)
gradient = gradient1 + lambda1 * gradient2;