forked from NeuralEnsemble/PyNN
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathprojections.py
More file actions
98 lines (79 loc) · 3.45 KB
/
Copy pathprojections.py
File metadata and controls
98 lines (79 loc) · 3.45 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
"""
"""
from collections import defaultdict
from itertools import repeat
import arbor
from arbor import units as U
from .. import common
from ..core import ezip
from ..space import Space
from . import simulator
class ConnectionGroup:
"""
"""
def __init__(self, pre, post, receptor_type, location_selector, **attributes):
self.presynaptic_index = pre
self.postsynaptic_index = post
self.receptor_type = receptor_type
self.location_selector = location_selector
for name, value in attributes.items():
setattr(self, name, value)
def as_tuple(self, *attribute_names):
# should return indices, not IDs for source and target
return tuple([getattr(self, name) for name in attribute_names])
class Projection(common.Projection):
__doc__ = common.Projection.__doc__
_simulator = simulator
def __init__(self, presynaptic_population, postsynaptic_population,
connector, synapse_type, source=None, receptor_type=None,
space=Space(), label=None):
common.Projection.__init__(self, presynaptic_population, postsynaptic_population,
connector, synapse_type, source, receptor_type,
space, label)
# Create connections
self.connections = defaultdict(list)
connector.connect(self)
self._simulator.state.network.add_projection(self)
def __len__(self):
return len(self.connections)
def set(self, **attributes):
raise NotImplementedError
def _convergent_connect(self, presynaptic_indices, postsynaptic_index,
location_selector=None,
**connection_parameters):
for name, value in connection_parameters.items():
if isinstance(value, float):
connection_parameters[name] = repeat(value)
for pre_idx, other in ezip(presynaptic_indices, *connection_parameters.values()):
other_attributes = dict(zip(connection_parameters.keys(), other))
self.connections[postsynaptic_index].append(
ConnectionGroup(pre_idx, postsynaptic_index, self.receptor_type, location_selector, **other_attributes)
)
def arbor_connections(self, gid):
"""Return a list of incoming connections to the cell with the given gid"""
try:
postsynaptic_index = self.post.id_to_index(gid)
except IndexError:
return []
else:
if self.pre.celltype.injectable:
source = "detector"
else:
source = "spike-source"
connections = []
all_labels = list(self.post._arbor_cell_description[postsynaptic_index]["labels"])
for cg in self.connections[postsynaptic_index]:
if cg.location_selector in (None, "all"):
target_labels = [lbl for lbl in all_labels if lbl.startswith(cg.receptor_type)]
for target in target_labels:
connections.append(
arbor.connection(
(self.pre[cg.presynaptic_index], source),
target,
cg.weight,
cg.delay * U.ms
)
)
else:
raise NotImplementedError()
return connections