forked from mhd-medfa/Crowd-Copter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoherentFilter_NeighborToPair.py
45 lines (32 loc) · 1.45 KB
/
CoherentFilter_NeighborToPair.py
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
import numpy as np
from operator import add
def CoherentFilter_NeighborToPair(neighborSet, correlationSet, d):
zeroNeighborSet = neighborSet[0]
numberOfPoints = len(zeroNeighborSet)
pairwiseConnectionSet = []
correSet = []
for i in range(numberOfPoints):
currentIntersect = zeroNeighborSet[i][:]
currentCorre=[0]*len(zeroNeighborSet[1])
for j in range(d):
nextNeighborSet = neighborSet[j]
nextCorreSet = correlationSet[j]
'''the intersection of neighborhood'''
tmp = list((set(currentIntersect)).intersection(set(nextNeighborSet[i][:])))
indexA = [currentIntersect.index(c) for c in tmp]
indexB = [nextNeighborSet[i][:].index(c) for c in tmp]
currentIntersect = tmp
currentCorre = list(map(add,[currentCorre[l] for l in indexA], [nextCorreSet[i][l] for l in indexB]))
if len(currentIntersect) != 0:
tmp2 = [x / d for x in currentCorre]
if i==0:
correSet=tmp2
else:
correSet=correSet+tmp2
tmp3=[[i]*len(currentIntersect),currentIntersect ]
if i==0:
pairwiseConnectionSet=tmp3
else:
pairwiseConnectionSet=[x+y for x,y in zip(pairwiseConnectionSet,tmp3)]
# correSet : averaged velocity set
return pairwiseConnectionSet, correSet