-
Notifications
You must be signed in to change notification settings - Fork 5
/
cells.py
159 lines (129 loc) · 5.47 KB
/
cells.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
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
#Glomeruli and Mitral Cell Objects
#Mitchell Gronowitz
#Spring 2015
class Glom(object):
"""Represents a glomerulus cell that communicates with a single receptor.
Instance attributes:
_id = [integer] identifies the glomerulus
_activ = [float: 0 - 1] activation level of glomerulus
_loc = [2D list] x,y coordinates of the glom on the surface of the Olfactory bulb
_dim = [2D list] row x columns
_conn = [integer] number of mitral cells connected to
_recConn = [dict] dict of connecting recs:weights
"""
def getId(self):
"""Returns ID of glom"""
return self._id
def setId(self, value):
"""Sets value to id.
Precondition: value is an integer"""
assert type(value) == int, "value is not an integer!!"
self._id = value
def getActiv(self):
"""Returns activation level of Glom."""
return self._activ
def setActiv(self, value):
"""Rounds value and sets it to activation level.
Precondition: Value is a float between 0 and 1."""
assert type(value) == float, "Not a float!"
assert value <= 1 and value >= 0, "Not between 0 and 1"
self._activ = round(value, 6)
def getLoc(self):
"""Returns location of glom"""
return self._loc
def setLoc(self, value):
"""Sets value to loc.
Precondition: value is a 2D list of numbers"""
assert type(value) == list, "value is not a list!!"
assert len(value) == 2 and type(value[0]) in [int, float], "Not a 2D list of numbers!"
self._loc = value
def getDim(self):
"""Returns dimensions of glom"""
return self._dim
def setDim(self, value):
"""Sets value to dim.
Precondition: value is a 2D list of numbers"""
assert type(value) == list, "value is not a list!!"
assert len(value) == 2 and type(value[0]) in [int], "Not a 2D list of numbers!"
self._dim = value
def getConn(self):
"""Returns connections of glom"""
return self._conn
def setConn(self, value):
"""Sets value to conn.
Precondition: value is an int"""
assert type(value) == int
self._conn = value
def setRecConn(self, value):
"""Sets value to recConn"""
assert type(value) == dict, "value isn't a dictionary"
self._recConn = value
def addRecConn(self, value, weight):
"""Sets value to recConn"""
self._recConn[value] = weight
def __init__(self, ID, activ=0.0, loc=[0,0], dim=[0,0], conn=0):
"""Initializes Glom object"""
self.setId(ID)
self.setActiv(activ)
self.setLoc(loc)
self.setDim(dim)
self.setConn(conn)
self.setRecConn({})
def __str__(self):
"""Returns a Glomural object description with activation energy"""
return "Id: " + str(self.getId()) + " activ: " + str(self.getActiv())
class Mitral(object):
"""Represents a mitral cell that samples from glomeruli.
Instance attributes:
_id = [int] identifies the mitral cell
_activ = [float: 0 - 1] activation level of mitral cell
-loc = [2D list] coordinates of the mitral cell on the surface of the bulb
_glom = dict where the keys are glom and the values are weights
"""
def getId(self):
"""Returns ID of mitral"""
return self._id
def setId(self, value):
"""Sets value to id.
Precondition: value is an integer"""
assert type(value) == int, "value is not an integer!!"
self._id = value
def getActiv(self):
"""Returns activation level of Mitral."""
return self._activ
def setActiv(self, value):
"""Rounds value and sets it to activation level.
Precondition: Value is a float between 0 and 1."""
assert type(value) == float, "Not a float!"
assert value <= 1 and value >= 0, "Not between 0 and 1"
self._activ = round(value, 5)
def getLoc(self):
"""Returns location of mitral cell"""
return self._loc
def setLoc(self, value):
"""Sets value to loc.
Precondition: value is a 2D list of numbers"""
assert type(value) == list, "value is not a list!!"
assert len(value) == 2 and type(value[0]) in [int, float], "Not a 2D list of numbers!"
self._loc = value
def getGlom(self):
"""Returns dictionary of connected glom"""
return self._glom
def setGlom(self, value):
"""Sets glomeruli to value.
Precondition: Value is a dict containing glomeruli id's and weights."""
assert type(value) == dict, "Not a dict!"
self._glom = value
def __init__(self, ID, activ=0.0, loc=[0,0], glom={}):
"""Initializes a Mitral cell"""
self.setId(ID)
self.setActiv(activ)
self.setLoc(loc)
self.setGlom(glom)
def __str__(self):
"""Returns a Mitral object description with activation energy and ID's
of connected glomeruli."""
# *********************** From Python 3.6 onwards, the standard dict type maintains insertion order by default *****************************
g = []
gstring = self.getGlom().keys()
return "Mitral ID: " + str (self.getId()) + " Mitral Activ: " + str(self.getActiv()) + " Glom:" + str(gstring)