-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathSDP_updateXwithOutlier.m
28 lines (22 loc) · 1.06 KB
/
SDP_updateXwithOutlier.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
function [nextX,nextVelocityDegree]=SDP_updateXwithOutlier(curX,curVelocityDegree,Xlabel,para)
correlationMatrix=repmat(curVelocityDegree,[1, size(curX,1)])';
distanceMatrix=slmetric_pw(curX',curX','eucdist');
neighborMatrix=distanceMatrix<=para.R;
nNeighbor=sum(neighborMatrix,2);
nextVelocityDegreeSet=correlationMatrix.*neighborMatrix;
nextVelocityDegree=curVelocityDegree;
for i=1:size(distanceMatrix,1)
curNeighborIndex=find(nextVelocityDegreeSet(i,:)~=0);
curCosAverage=sum(cos(nextVelocityDegreeSet(i,curNeighborIndex)))/nNeighbor(i);
curSinAverage=sum(sin(nextVelocityDegreeSet(i,curNeighborIndex)))/nNeighbor(i);
nextVelocityDegree(i)=atan2(curSinAverage,curCosAverage);
end
%%
velocityDegree_noise=pi*para.noise*(-1+2*rand([para.nPoint,1])); %% adding noise
outlierIndex=find(Xlabel==-1);
nextVelocityDegree(outlierIndex)=curVelocityDegree(outlierIndex);
nextVelocityDegree=nextVelocityDegree+velocityDegree_noise;
incrementX=[para.velocity*cos(nextVelocityDegree) para.velocity*sin(nextVelocityDegree)];
nextX=curX+incrementX;
nextX=mod(nextX,para.L);
end