-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathbasis_functions.py
More file actions
211 lines (195 loc) · 5.06 KB
/
basis_functions.py
File metadata and controls
211 lines (195 loc) · 5.06 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/usr/bin/env python
"""
This script is used to generate basis sources for the
kCSD method Jan et.al (2012) for 1D,2D and 3D cases.
Two 'types' are described here, gaussian and step source,
These can be easily extended.
These scripts are based on Grzegorz Parka's,
Google Summer of Code 2014, INFC/pykCSD
This was written by :
Michal Czerwinski, Chaitanya Chintaluri
Laboratory of Neuroinformatics,
Nencki Institute of Experimental Biology, Warsaw.
"""
from __future__ import division, print_function, absolute_import
import numpy as np
from numba import jit
@jit(nopython=True)
def gauss(d, stdev, dim):
"""Gaussian function
Parameters
----------
d : floats or np.arrays
Distance array to the point of evaluation
stdev : float
cutoff range
dim : int
dimension of the gaussian function
Returns
-------
Z : floats or np.arrays
function evaluated
"""
Z = np.exp(-(d**2) / (2*stdev**2)) / (np.sqrt(2*np.pi)*stdev)**dim
return Z
@jit(nopython=True)
def step_1D(d, R):
"""Returns normalized 1D step function.
Parameters
----------
d : floats or np.arrays
Distance array to the point of evaluation
R : float
cutoff range
Returns
-------
s : Value of the function (d <= R) / R
"""
s = (d <= R)
s = s / R #normalize with width
return s
@jit(nopython=True)
def gauss_1D(d, three_stdev):
"""Returns normalized gaussian 2D scale function
Parameters
----------
d : floats or np.arrays
Distance array to the point of evaluation
three_stdev : float
3 * standard deviation of the distribution
Returns
-------
Z : (three_std/3)*(1/2*pi)*(exp(-0.5)*stddev**(-2) *(d**2))
"""
stdev = three_stdev/3
Z = gauss(d, stdev, 1)
return Z
@jit(nopython=True)
def gauss_lim_1D(d, three_stdev):
"""Returns gausian 2D function cut off after 3 standard deviations.
Parameters
----------
d : floats or np.arrays
Distance array to the point of evaluation
three_stdev : float
3 * standard deviation of the distribution
Returns
-------
Z : (three_std/3)*(1/2*pi)*(exp(-0.5)*stddev**(-2) *((x-mu)**2)),
cut off = three_stdev
"""
Z = gauss_1D(d, three_stdev)
Z *= (d < three_stdev)
return Z
@jit(nopython=True)
def step_2D(d, R):
"""Returns normalized 2D step function.
Parameters
----------
d : float or np.arrays
Distance array to the point of evaluation
R : float
cutoff range
Returns
-------
s : step function
"""
s = (d <= R) / (np.pi*(R**2))
return s
@jit(nopython=True)
def gauss_2D(d, three_stdev):
"""Returns normalized gaussian 2D scale function
Parameters
----------
d : floats or np.arrays
distance at which we need the function evaluated
three_stdev : float
3 * standard deviation of the distribution
Returns
-------
Z : function
Normalized gaussian 2D function
"""
stdev = three_stdev/3
Z = gauss(d, stdev, 2)
return Z
@jit(nopython=True)
def gauss_lim_2D(d, three_stdev):
"""Returns gausian 2D function cut off after 3 standard deviations.
Parameters
----------
d : floats or np.arrays
distance at which we need the function evaluated
three_stdev : float
3 * standard deviation of the distribution
Returns
-------
Z : function
Normalized gaussian 2D function cut off after three_stdev
"""
Z = (d <= three_stdev)*gauss_2D(d, three_stdev)
return Z
@jit(nopython=True)
def gauss_3D(d, three_stdev):
"""Returns normalized gaussian 3D scale function
Parameters
----------
d : floats or np.arrays
distance at which we need the function evaluated
three_stdev : float
3 * standard deviation of the distribution
Returns
-------
Z : funtion
Normalized gaussian 3D function
"""
stdev = three_stdev/3
Z = gauss(d, stdev, 3)
return Z
@jit(nopython=True)
def gauss_lim_3D(d, three_stdev):
"""Returns normalized gaussian 3D scale function cut off after 3stdev
Parameters
----------
d : floats or np.arrays
distance at which we need the function evaluated
three_stdev : float
3 * standard deviation of the distribution
Returns
-------
Z : funtion
Normalized gaussian 3D function cutoff three_Stdev
"""
Z = gauss_3D(d, three_stdev)
Z = Z * (d < (three_stdev))
return Z
@jit(nopython=True)
def step_3D(d, R):
"""Returns normalized 3D step function.
Parameters
----------
d : floats or np.arrays
distance at which we need the function evaluated
R : float
cutoff range
Returns
-------
s : step function in 3D
"""
s = 3/(4*np.pi*R**3)*(d <= R)
return s
basis_1D = {
"step": step_1D,
"gauss": gauss_1D,
"gauss_lim": gauss_lim_1D,
}
basis_2D = {
"step": step_2D,
"gauss": gauss_2D,
"gauss_lim": gauss_lim_2D,
}
basis_3D = {
"step": step_3D,
"gauss": gauss_3D,
"gauss_lim": gauss_lim_3D,
}