-
Notifications
You must be signed in to change notification settings - Fork 0
/
InstUpdate.m
72 lines (43 loc) · 1.59 KB
/
InstUpdate.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
60
61
62
63
64
65
66
67
68
69
70
71
72
function [nS,IPs]=InstUpdate(Data,S,IPs,W,lambda,Insts)
nS=S;
IPs=IPs;
TotalLoss=0;
for i=1:Data.NbBags
Data.Bags(i).S=S(i,:);
Data.Bags(i).ConfVal=sum(W.*Data.Bags(i).S');
TotalLoss=TotalLoss+SVMLoss(Data.Bags(i).Label,Data.Bags(i).ConfVal);
end
TotalLossCopy=TotalLoss;
for i=1:Data.NbBags
if SVMLoss(Data.Bags(i).Label,Data.Bags(i).ConfVal)==0
continue
end
TotalLoss=TotalLossCopy;
for j=1:Data.Bags(i).NbInst
if j==IPs(i)
continue;
end
[NewTotalLoss,nSi,nf]=FeatureUpdate(Data,Data.Bags(i).Insts(j,:),i,...
S(:,i),W,[Data.Bags(:).ConfVal],TotalLoss,lambda,Insts);
if NewTotalLoss < TotalLoss
TotalLoss = NewTotalLoss;
nS(:,i)=nSi;
IPs(i)=j;
for k=1:Data.NbBags
Data.Bags(k).ConfVal=nf(k);
end
end
end
end
end
function [nv,nSi,nf]=FeatureUpdate(Data,nIP,FeatInd,Si,W,f,v,lambda,Insts)
LandMineNbInstPerBag=5;
nSi=DataMinHaussDorff(Insts,nIP,LandMineNbInstPerBag);
nSi=exp(-lambda*(nSi.^2));
nf=f+W(FeatInd)*(nSi-Si)';
Labels=[Data.Bags(:).Label];
nv= sum(max(0,1-Labels.*nf).^2);
end
function l=SVMLoss(y,f)
l=max(0,1-y*f)^2;
end