-
Notifications
You must be signed in to change notification settings - Fork 0
/
clrepeaters.py
104 lines (97 loc) · 3.41 KB
/
clrepeaters.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
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
##################################
#
# clneurons.py
# Copyright (C) Louisiana State University, Health Sciences Center
# Written by 2011-2014 Ruben Tikidji-Hamburyan <[email protected]>
#
#
# 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 2 of the License, or (at
# your option) 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, GOOD TITLE or
# NON INFRINGEMENT. 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, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
###################################
import random as rnd
import string
import sys,math
class clrepeaters:
def __init__(self, object="repeaters", attr={}):
#### Default paramters
self.number = 1
self.slope = 0 #a
self.offset = 1 #b
self.name="*****"
self.object=object
#### Test for implicit attributes:
for atr in attr.keys():
if atr == "offset": continue
if atr == "name": continue
if atr == "slope": continue
if atr == "min": continue
sys.stderr.write("Unexpected attribute \'%s\'for tag <repeaters>\nABORT\n\n"%atr)
sys.exit(1)
#### Reset from attrebuts
if attr.get("slope"): self.slope = float( attr["slope"] )
if attr.get("name"): self.name = attr["name"]
if attr.get("offset"): self.offset = float(attr["offset"])
if attr.get("min"): self.min = float( attr["min"] )
else: self.min = 0.
#Array of neurons the numbers are
# phase, second order correction and last period
self.neurons = [ [0, 0, 0] ]
self.timetospike = [ 1e19 ]
#### Dic of named connections
self.connections = {}
#### Output buffers
self.op = [ 0 ]
self.period = 1e19
self.__lastspike = 0.
def startpoint(self,object,attr):
sys.stderr.write("Unexpected tag <%s> in <repeaters> expression\nABBORT\n\n"%object);
sys.exit(1)
def stoppoint(self, object):
if object == "repeaters": #or object == "init" or object == "saturation":
return
else:
sys.stderr.write("Unexpected close tag <%s> in <repeaters> expression\nABBORT\n\n"%object);
sys.exit(1)
def write(self):
result=["<repeaters name=\"%s\" offset=\"%g\" slope=\"%g\"/>"%(self.name, self.offset, self.slope)]
return result
def getnames(self):
result = []
for cnt in xrange(self.number):
result.append("%s:%g"%(self.name,cnt+1))
return result
def calculate(self,model):
prespike = 0
for cont in self.connections.items():
for con in cont[1]:
prespike += reduce(lambda x,y:x+y, con.op, 0)
if prespike > 0:
#DB>>
#print prespike,"slope:",self.slope,"offset:",self.offset,"x:",model.elapsed_time - self.__lastspike,"({},{})".format(model.elapsed_time,self.__lastspike),"==>",
#<<DB
tmp = (model.elapsed_time - self.__lastspike)
self.timetospike = [ tmp * self.slope + self.offset if tmp > self.min else self.min ]
#DB>>
#print self.timetospike
#<<DB
def update(self,model):
if self.timetospike[0] <= model.timetospike:
self.op[0] = 1
self.neurons[0][2] = model.elapsed_time - self.__lastspike
self.__lastspike = model.elapsed_time
self.timetospike = [ 1e19 ]
else:
self.op[0] = 0