-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctions.py
More file actions
122 lines (92 loc) · 3.14 KB
/
Functions.py
File metadata and controls
122 lines (92 loc) · 3.14 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import numpy as np
import numpy.random
import scipy.special
import random
import math
import matplotlib.pyplot as plt
def random_2d_points(x0, x1, y0, y1, N):
Points={'x':[], 'y':[]}
for i in range(0, N):
x=random.uniform(x0, x1)
y=random.uniform(y0, y1)
Points['x'].append(x)
Points['y'].append(y)
return Points
def random_2d_points_lam(x0, x1, y0, y1, Lam):
N=numpy.random.poisson(Lam*(x1-x0)*(y1-y0))
Points={'x':[], 'y':[]}
for i in range(0, N):
x=random.uniform(x0, x1)
y=random.uniform(y0, y1)
Points['x'].append(x)
Points['y'].append(y)
return Points
def region_count_square(x0, x1, y0, y1, Points):
Area={'xrange':[x0, x1], 'yrange':[y0,y1]}
AreaCount=0
for i in range(0, len(Points['x'])):
cond=((Points['x'][i]>=Area['xrange'][0]) and (Points['x'][i]<=Area['xrange'][1]) and
(Points['y'][i]>=Area['yrange'][0]) and (Points['y'][i]<=Area['yrange'][1]))
if(cond):
AreaCount+=1
return AreaCount
def region_count_circle(R, C, Points):
AreaCount=0
for i in range(0, len(Points['x'])):
shiftx=Points['x'][i]-C[0]
shifty=Points['y'][i]-C[1]
r=np.sqrt(shiftx**2+shifty**2)
#print(r)
if(r<=R):
AreaCount+=1
return AreaCount
def vacancy_ind_square(x0, x1, y0, y1, Points):
if(region_count_square(x0, x1, y0, y1, Points) < 1):
return 1
else:
return 0
def capacity_functional(beta, area):
return 1 - np.exp(-beta*area)
def contact_dist_2d(beta, r):
p=np.pi
return 1 - np.exp(-beta*p*r*r)
def dist_2d(u, X):
distance=[]
for i in range(0, len(X['x'])):
distx=X['x'][i]-u[0]
disty=X['y'][i]-u[1]
dist=np.sqrt(disty**2+distx**2)
distance=np.append(distance, dist)
return(distance.min())
def K_function(t, X, W):
#W=width of the feild in [x0,y0,x1,y1]
K=[]
for i in range(0, len(X['x'])):
Npoints=region_count_circle(t, [X['x'][i],X['y'][i]], X)-1
cond=((X['x'][i]>t+W[0]) and (X['x'][i]<W[2]-t) and (X['y'][i]>t+W[1]) and (X['y'][i]<W[3]-t))
if(cond):
K=np.append(K, Npoints)
return K.mean()
def PCP(t, X, W, dt=1):
#W=width of the feild in [x0,y0,x1,y1]
return K_function(t+dt, X, W)-K_function(t, X, W)
#adding comments here to track changes
def F_function(r, X, W):
#W=width of the feild in [x0,y0,x1,y1]
F=[]
for i in range(W[0], W[2]):
for j in range(W[1],W[3]):
if(region_count_circle(r, [i,j] , X)>0):
F=np.append(F, 1)
else:
F=np.append(F, 0)
return(F.mean())
def G_function(r, X):
#W=width of the feild in [x0,y0,x1,y1]
G=[]
for i in range(0, len(X['x'])):
if((region_count_circle(r, [X['x'][i],X['y'][i]] , X)-1)>0):
G=np.append(G, 1)
else:
G=np.append(G, 0)
return(G.mean())