Changeset 441
- Timestamp:
- 08/12/08 14:37:01 (3 months ago)
- Files:
-
- trunk/src/brian/connectors.py (modified) (5 diffs)
- trunk/src/nest1/connectors.py (modified) (3 diffs)
- trunk/src/nest2/connectors.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/brian/connectors.py
r436 r441 5 5 6 6 from pyNN import common 7 from pyNN.brian.__init__ import numpy , PoissonGroupWithDelays7 from pyNN.brian.__init__ import numpy 8 8 import brian_no_units_no_warnings 9 9 import brian, types … … 24 24 src = projection.pre.brian_cells 25 25 tgt = projection.post.brian_cells 26 delay = Connector.delays*0.00126 delay = max(projection.pre.brian_cells.clock.dt,Connector.delays*0.001) 27 27 connection = brian.Connection(src, tgt, target, delay=delay) 28 28 return connection … … 93 93 # The -2 comes from the fact that brian will make 2 tests calls before 94 94 # using the function. 95 nb_conn = -295 #nb_conn = -2 96 96 post = projection.post 97 97 N = len(post) 98 get_proba = eval("lambda d: %s" %self.d_expression) 99 get_weights = eval("lambda d: %s" %self.weights) 98 100 99 101 def topoconnect(i,j): … … 102 104 distances = common.distances(pre, post, self.mask, 103 105 self.scale_factor, self.offset, 104 periodic_boundaries) 105 func = eval("lambda d: %s" %self.d_expression) 106 p = func(distances[0]) 106 periodic_boundaries)[0] 107 p = get_proba(distances) 107 108 # We get the list of cells that will established a connection 108 109 rarr = rng.uniform(0, 1, N) 109 110 conn = ((p >= 1) | ((0 < p) & (p < 1) & (rarr <= p))) 110 111 if isinstance(self.weights,str): 111 func = eval("lambda d: %s" %self.weights) 112 weights = func(distances[0]) 112 weights = get_weights(distances) 113 113 else: 114 114 weights = self.weights*numpy.ones(N) … … 126 126 projection._connections = _targetConnection(self, projection) 127 127 projection._connections.connect_full(projection.pre.brian_cells,projection.post.brian_cells,weight=topoconnect) 128 #print nb_conn 128 129 return projection._connections.W.getnnz() 129 130 trunk/src/nest1/connectors.py
r433 r441 116 116 else: 117 117 rng = numpy.random 118 119 get_proba = eval("lambda d: %s" %self.d_expression) 120 get_weights = eval("lambda d: %s" %self.weights) 121 get_delays = eval("lambda d: %s" %self.delays) 122 118 123 for post in postsynaptic_neurons: 119 distances = common.distances(projection.pre, post, self.mask, self.scale_factor, self.offset, periodic_boundaries) 124 distances = common.distances(projection.pre, post, self.mask, self.scale_factor, self.offset, periodic_boundaries)[:,0] 120 125 # We evaluate the probabilities of connections for those distances 121 func = eval("lambda d: %s" %self.d_expression) 122 probabilities = func(distances[:,0]) 126 proba = get_proba(distances) 123 127 rarr = rng.uniform(0, 1, (npre,)) 124 128 # We get the list of cells that will established a connecti 125 idx = numpy.where((proba bilities >= 1) | ((0 < probabilities) & (probabilities < 1) & (rarr <= probabilities)))[0]129 idx = numpy.where((proba >= 1) | ((0 < proba) & (proba < 1) & (rarr <= proba)))[0] 126 130 source_list = presynaptic_neurons[idx].tolist() 127 131 # We remove the post cell if we don't allow self connections … … 131 135 N = len(source_list) 132 136 if isinstance(self.weights,str): 133 func = eval("lambda d: %s" %self.weights) 134 weights = func(distances[:,0])[idx] 137 weights = get_weights(distances[idx]) 135 138 else: 136 139 weights = self.getWeights(N) … … 138 141 # We deal with the fact that the user could have given a delays distance dependent 139 142 if isinstance(self.delays,str): 140 func = eval("lambda d: %s" %self.delays) 141 delays = func(distances[:,0])[idx].tolist() 143 delays = get_delays(distances[idx]).tolist() 142 144 else: 143 145 delays = self.getDelays(N).tolist() trunk/src/nest2/connectors.py
r433 r441 132 132 else: 133 133 rng = numpy.random 134 135 get_proba = eval("lambda d: %s" %self.d_expression) 136 get_weights = eval("lambda d: %s" %self.weights) 137 get_delays = eval("lambda d: %s" %self.delays) 138 134 139 for pre in projection.pre.cell.flat: 135 140 # We compute the distances from the post cell to all the others 136 141 distances = common.distances(pre, projection.post, self.mask, 137 142 self.scale_factor, self.offset, 138 periodic_boundaries) 143 periodic_boundaries)[0] 139 144 # We evaluate the probabilities of connections for those distances 140 func = eval("lambda d: %s" %self.d_expression) 141 probabilities = func(distances[0]) 145 proba = get_proba(distances) 142 146 # We get the list of cells that will established a connection 143 147 rarr = rng.uniform(0, 1, (npost,)) 144 idx = numpy.where((proba bilities >= 1) | ((0 < probabilities) & (probabilities < 1) & (rarr <= probabilities)))[0]148 idx = numpy.where((proba >= 1) | ((0 < proba) & (proba < 1) & (rarr <= proba)))[0] 145 149 target_list = postsynaptic_neurons[idx].tolist() 146 150 # We remove the pre cell if we don't allow self connections … … 151 155 # We deal with the fact that the user could have given a weights distance dependent 152 156 if isinstance(self.weights,str): 153 func = eval("lambda d: %s" %self.weights) 154 weights = func(distances[0])[idx] 157 weights = get_weights(distances[idx]) 155 158 else: 156 159 weights = self.getWeights(N) … … 158 161 # We deal with the fact that the user could have given a delays distance dependent 159 162 if isinstance(self.delays,str): 160 func = eval("lambda d: %s" %self.delays) 161 delays = func(distances[0])[idx].tolist() 163 delays = get_delays(distances[idx]).tolist() 162 164 else: 163 165 delays = self.getDelays(N).tolist() … … 167 169 nest.DivergentConnectWD([pre], target_list, weights, delays) 168 170 return len(projection._sources) 169 170 171 171 172 class FixedNumberPostConnector(common.FixedNumberPostConnector):

