-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPointProcessGenerator.py
More file actions
100 lines (67 loc) · 2.7 KB
/
PointProcessGenerator.py
File metadata and controls
100 lines (67 loc) · 2.7 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
'''
Neuromuscular simulator in Python.
Copyright (C) 2018 Renato Naville Watanabe
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Contact: renato.watanabe@ufabc.edu.br
'''
import numpy as np
import numpy.random
import math
#from numba import jit
#@jit
def gammaPoint(GammaOrder):
'''
Generates a number according to a Gamma Distribution with an integer order **GammaOrder**.
- Inputs:
+ **GammaOrder**: integer order of the Gamma distribution.
- Outputs:
+ The number generated from the Gamma distribution.
The number is generated according to:
\f{equation}{
\Gamma = -\frac{1}{\lambda}\ln(\limits\prod_{i=1}^{\lambda} U(0,1))
\f}
where \f$\lambda\f$ is the order of the Gamma distribution and U(a,b) is
a uniform distribution from a to b.
'''
return - 1.0/GammaOrder * np.log(np.prod(numpy.random.uniform(0.0, 1.0, size=GammaOrder)))
class PointProcessGenerator(object):
'''
Generator of point processes.
'''
def __init__(self, index):
'''
Constructor
- Inputs:
+ **GammaOrder**: integer order of the Gamma distribution.
+ **index**: integer corresponding to the unit order in the pool.
'''
## Integer corresponding to the unit order in the pool to which this
## generator is associated.
self.index = index
## Auxiliary variable cummulating a value that indicates
## whether there will be a new spike or not.
self.threshold = gammaPoint(1)
## List of spike instants of the generator.
self.points = []
def atualizeGenerator(self, t, firingRate, GammaOrder):
'''
- Inputs:
+ **t**: current instant, in ms.
+ **firingRate**: instant firing rate, in spikes/s.
'''
if self.threshold <= 0 and t != 0:
self.points.append([t, self.index])
self.threshold = gammaPoint(GammaOrder)
self.threshold -= firingRate
def reset(self):
self.points = []
self.threshold = gammaPoint(1)