-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfunctions.py
More file actions
98 lines (77 loc) · 2.17 KB
/
Copy pathfunctions.py
File metadata and controls
98 lines (77 loc) · 2.17 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
import numpy as np
from scipy.optimize import leastsq
import scipy
def leastsq_helper(p, y, lsfunc, x, *args):
return y - lsfunc(p, x, *args)
def fboltz_up(p, x):
"""
Boltzmann function (upwards from 0 to 1)
Parameters
----------
p : numpy.ndarray
:math:`p_0`, location of half maximum; :math:`p_1`, slope
x : numpy.ndarray
Dependent variable
Returns
-------
boltzmann : numpy.ndarray
:math:`y = 1 - \\frac{1}{1 + e^\\left(\\left(x-p_0\\right)/p_1\\right)}`
"""
return 1.0 - 1.0/(1.0+np.exp((x-p[0])/p[1]))
def fexp(p, x):
"""
Exponential function
Parameters
----------
p : numpy.ndarray
:math:`p_0`, amplitude; :math:`p_1`, :math:`\tau`; :math:`p_2`, offset
x : numpy.ndarray
Dependent variable
Returns
-------
boltzmann : numpy.ndarray
:math:`y = p_0 \left( e^{\frac{-x}{\tau}} \right) + p_2`
"""
amp = p[0]
tau = p[1]
offset = p[2]
return amp*(-np.exp(-x/tau)) + offset
def gv(i, v, erev):
"""
Fit Boltzmann function to normalized conductance values
Parameters
----------
i : numpy.ndarray
Peak current values
v : numpy.ndarray
Command voltages
erev : float
Reversal potential
Returns
-------
g : numpy.ndarray
Normalized conductances
gfit : numpy.ndarray
Half-maximal voltage and slope of best-fit Boltzmann function
"""
g = i / (v-erev)
g /= g.max()
v50_init = 0.0
slope_init = 1.0
gfit = leastsq(
leastsq_helper, (v50_init, slope_init), args=(g, fboltz_up, v))[0]
return g, gfit
def tri_norm(x, *args):
m1, m2, m3, s1, s2, s3, k1, k2, k3 = args
ret = k1*scipy.stats.norm.pdf(x, loc=m1 ,scale=s1)
ret += k2*scipy.stats.norm.pdf(x, loc=m2 ,scale=s2)
ret += k3*scipy.stats.norm.pdf(x, loc=m3 ,scale=s3)
return ret
def bi_norm(x, *args):
m1, m2, s1, s2, k1, k2 = args
ret = k1*scipy.stats.norm.pdf(x, loc=m1 ,scale=s1)
ret += k2*scipy.stats.norm.pdf(x, loc=m2 ,scale=s2)
return ret
def single_norm(x, *args):
m1, s1, k1 = args
return k1*scipy.stats.norm.pdf(x, loc=m1 ,scale=s1)