-
Notifications
You must be signed in to change notification settings - Fork 1
/
spatial_depen_sigma.py
116 lines (64 loc) · 2.93 KB
/
spatial_depen_sigma.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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
####
# -------------------------------------
# |we can either warp the trajectories in advance and then construct the adj,
# |or, we can use a spatially changing sigma
# |for now, we use block-different sigmas.
# -------------------------------------
def getMuSigma(x,y,xspd,yspd):
sxdiffAll = []
sydiffAll = []
mdisAll = []
num = np.arange(fnum)
# build adjacent mtx
for i in range(NumGoodsample):
# print "i", i
# plt.cla()
for j in range(i, min(NumGoodsample,i+1000)):
tmp1 = x[i,:]!=0
tmp2 = x[j,:]!=0
idx = num[tmp1&tmp2]
if len(idx)>5: # has overlapping
# if len(idx)>=30: # at least overlap for 100 frames
sidx = idx[0:-1] # for speed
sxdiff = np.mean(np.abs(xspd[i,sidx]-xspd[j,sidx]))
sydiff = np.mean(np.abs(yspd[i,sidx]-yspd[j,sidx]))
mdis = np.mean(np.abs(x[i,idx]-x[j,idx])+np.abs(y[i,idx]-y[j,idx])) #mahhattan distance
sxdiffAll.append(sxdiff)
sydiffAll.append(sydiff)
mdisAll.append(mdis)
mu_xspd_diff,sigma_xspd_diff = fitGaussian(sxdiffAll)
mu_yspd_diff,sigma_yspd_diff = fitGaussian(sydiffAll)
mu_spatial_distance,sigma_spatial_distance = fitGaussian(mdisAll)
return mu_xspd_diff,sigma_xspd_diff,mu_yspd_diff,sigma_yspd_diff,mu_spatial_distance,sigma_spatial_distance
def getMuSigma_spatial(x,y,xspd,yspd):
sxdiffAll = []
sydiffAll = []
mdisAll = []
num = np.arange(fnum)
# build adjacent mtx
for i in range(NumGoodsample):
# print "i", i
# plt.cla()
for j in range(i, min(NumGoodsample,i+1000)):
tmp1 = x[i,:]!=0
tmp2 = x[j,:]!=0
idx = num[tmp1&tmp2] ###????
# median location of the ith and jth trj
midy1 = np.median(y[i,tmp1])
midy2 = np.median(y[j,tmp2])
'used to hard-threshold Gaussian adj'
# midx1 = np.median(x[i,tmp1])
# midx2 = np.median(y[j,tmp2])
if len(idx)>5: # has overlapping
# if len(idx)>=30: # at least overlap for 100 frames
sidx = idx[0:-1] # for speed
sxdiff = np.mean(np.abs(xspd[i,sidx]-xspd[j,sidx]))
sydiff = np.mean(np.abs(yspd[i,sidx]-yspd[j,sidx]))
mdis = np.mean(np.abs(x[i,idx]-x[j,idx])+np.abs(y[i,idx]-y[j,idx])) #mahhattan distance
sxdiffAll.append(sxdiff)
sydiffAll.append(sydiff)
mdisAll.append(mdis)
mu_xspd_diff,sigma_xspd_diff = fitGaussian(sxdiffAll)
mu_yspd_diff,sigma_yspd_diff = fitGaussian(sydiffAll)
mu_spatial_distance,sigma_spatial_distance = fitGaussian(mdisAll)
return mu_xspd_diff,sigma_xspd_diff,mu_yspd_diff,sigma_yspd_diff,mu_spatial_distance,sigma_spatial_distance