-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDistFuncs.py
70 lines (62 loc) · 2.62 KB
/
DistFuncs.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
import numpy as np
import pylab as plt
AGENTRADIUS = 1.0
# Functions to estimate density used in Kernel class
def uniformFunc( dispX, dispY, radius ):
""" Density Estimation using uniform function -> square in 2D """
maskX = dispX <= radius
maskY = dispY <= radius
maskXY = maskX & maskY
return maskXY/ float(radius *radius)
def linearFunc( dispX, dispY, radius):
""" Density Esitmation using linear function -> cone in 2D """
distXY = np.sqrt( dispX * dispX + dispY * dispY )
maskXY = distXY <= radius
valueXY = (radius - distXY) * maskXY
## For testing by ploting gradient or value of the function
if ( False ):
gradX, gradY = np.gradient(valueXY)
gradMag = np.sqrt( gradX * gradX + gradY * gradY )
plt.contour( valueXY )
plt.axis('equal')
plt.show()
return valueXY
def biweightFunc( dispX, dispY, radius):
rSqd = radius * radius
dispYSqd = dispY * dispY
distXY = dispX * dispX + dispYSqd
maskXY = np.sqrt(distXY) <= radius
valueXY = -( distXY )/rSqd
valueXY += 1.0
# Normalize the biweight function
valueXY /= (4. * rSqd)/ 3.
valueXY *= maskXY
##For testing by ploting gradient or value of the function
if ( False ):
gradX, gradY = np.gradient( valueXY )
gradMag = np.sqrt( gradX * gradX + gradY * gradY )
plt.contour( valueXY )
plt.axis( 'equal' )
plt.show()
return valueXY
def gaussianFunc( dispX, dispY, radiusSqd ):
""" Density Estimation using gaussian function """
return np.exp( -(dispX * dispX + dispY * dispY) / (2.0 * radiusSqd ) ) / ( 2.0 * np.pi * radiusSqd )
def variableGaussianFunc( dispX, dispY, smooth_sqrd ):
""" Density Estimation using gaussian function with varied radius"""
# Have to be seperated from normal Gaussian for function pointer testing in Kernel and Grid file
return np.exp( -(dispX * dispX + dispY * dispY) / (2.0 * radiusSqd * smooth_sqrd ) ) / ( 2.0 * np.pi *
radiusSqd * smooth_sqrd )
UNIFORM = lambda X, Y, S: uniformFunc( X, Y, S )
GAUSS = lambda X, Y, S: gaussianFunc( X, Y, S * S )
LINEAR = lambda X, Y, S: linearFunc( X, Y, S * S )
BIWEIGHT = lambda X, Y, S: biweightFunc( X, Y, S )
VARGAUSS = lambda X, Y, S: variableGaussianFunc( X, Y, S * S)
VORONOI_UNI = lambda X, Y, S: uniformFunc( X, Y, S )
FUNCS_MAP = { "uniform": UNIFORM,
"gaussian": GAUSS,
"variable-gaussian":VARGAUSS,
"linear": LINEAR,
"biweight": BIWEIGHT,
"voronoi-uniform": VORONOI_UNI
}