-
Notifications
You must be signed in to change notification settings - Fork 1
/
updatePTs.m
62 lines (45 loc) · 1.65 KB
/
updatePTs.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
% Florian Meyer, 2017, 2020
function [legacyPTs,legacyExistences,legacyLabels] = updatePTs(kappas,iotas,legacyPTs,newPTs,legacyExistences,newExistences,legacyLabels,newLabels,vFactors1)
numTargets = size(vFactors1,2);
numMeasurements = size(vFactors1,1)-1;
numParticles = size(vFactors1,3);
for target = 1:numTargets
weights = permute(vFactors1(1,target,:),[3,1,2]);
for measurement = 1:numMeasurements
weights = weights + kappas(measurement,target)*permute(vFactors1(measurement+1,target,:),[3,1,2]);
end
sumWeights = sum(weights);
isAlive = legacyExistences(target)*sumWeights/numParticles;
isDead = (1-legacyExistences(target));
legacyExistences(target) = isAlive/(isAlive+isDead);
if(sumWeights)
legacyPTs(:,:,target) = legacyPTs(:,resampleSystematic(1/sumWeights*weights,numParticles),target);
end
end
% merge new and legacy PTs
legacyPTs = cat(3,legacyPTs,newPTs);
newExistences = iotas.*newExistences./(iotas.*newExistences + 1);
if(isempty(legacyExistences))
legacyExistences = newExistences;
else
legacyExistences = cat(1,legacyExistences,newExistences);
end
legacyLabels = cat(2,legacyLabels,newLabels);
end
function indexes = resampleSystematic(weights,numParticles)
indexes = zeros(numParticles,1);
cumWeights = cumsum(weights);
grid = zeros(1,numParticles+1);
grid(1:numParticles) = linspace(0,1-1/numParticles,numParticles) + rand/numParticles;
grid(numParticles+1) = 1;
i = 1;
j = 1;
while( i <= numParticles )
if( grid(i) < cumWeights(j) )
indexes(i) = j;
i = i + 1;
else
j = j + 1;
end
end
end