Changeset 728
- Timestamp:
- 03/11/10 17:41:37 (2 years ago)
- Location:
- trunk
- Files:
-
- 2 modified
-
src/connectors2.py (modified) (11 diffs)
-
test/unittests/generictests.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/connectors2.py
r727 r728 3 3 from pyNN.space import Space 4 4 from pyNN.random import RandomDistribution 5 from numpy import exp 5 from numpy import arccos, arcsin, arctan, arctan2, ceil, cos, cosh, e, exp, \ 6 fabs, floor, fmod, hypot, ldexp, log, log10, modf, pi, power, \ 7 sin, sinh, sqrt, tan, tanh, maximum, minimum 6 8 7 9 class ConnectionAttributeGenerator(object): … … 27 29 return values 28 30 elif isinstance(self.source, RandomDistribution): 29 values = self.source.next(N, mask_local=self.local_mask) 30 if sub_mask is not None: 31 values = values[sub_mask] 31 if sub_mask is None: 32 values = self.source.next(N, mask_local=self.local_mask) 33 else: 34 values = self.source.next(len(sub_mask), mask_local=self.local_mask) 32 35 return values 33 36 elif isinstance(self.source, numpy.ndarray): … … 44 47 ConnectionAttributeGenerator.__init__(self, source, local_mask, safe) 45 48 self.projection = projection 46 self.is_conductance = common.is_conductance(projection.post. local_cells[0])47 49 self.is_conductance = common.is_conductance(projection.post.all_cells[0]) 50 48 51 def check(self, weight): 49 52 if weight is None: … … 167 170 self.projection = projection 168 171 self.allow_self_connections = allow_self_connections 169 172 170 173 def _probabilistic_connect(self, src, p): 171 174 """ … … 178 181 create = numpy.arange(self.local.sum()) 179 182 else: 180 rarr = self.probas_generator.get(self.N, self.distance_matrix) 181 create = numpy.where(rarr < p)[0] 182 183 if isinstance(self.weights, basestring) or isinstance(self.delays, basestring): 184 self.distance_matrix.set_source(src.position) 185 183 rarr = self.probas_generator.get(self.N) 184 if not core.is_listlike(rarr) and numpy.isscalar(rarr): # if N=1, rarr will be a single number 185 rarr = numpy.array([rarr]) 186 create = numpy.where(rarr < p)[0] 187 self.distance_matrix.set_source(src.position) 186 188 targets = self.projection.post.local_cells[create] 187 189 weights = self.weights_generator.get(self.N, self.distance_matrix, create) … … 226 228 227 229 def connect(self, projection): 228 connector = ProbabilisticConnector(projection, self.weights, self.delays, self.allow_self_connections, self.space, safe=self.safe) 229 for src in projection.pre.all():230 connector = ProbabilisticConnector(projection, self.weights, self.delays, self.allow_self_connections, self.space, safe=self.safe) 231 for count, src in enumerate(projection.pre.all()): 230 232 connector._probabilistic_connect(src, 1) 233 231 234 232 235 … … 430 433 weights_generator = WeightGenerator(self.weights, local, projection, self.safe) 431 434 delays_generator = DelayGenerator(self.delays, local, self.safe) 432 distance_matrix = DistanceMatrix(projection.post.positions, self.space, local)435 distance_matrix = DistanceMatrix(projection.post.positions, self.space, numpy.arange(len(projection.post))) 433 436 candidates = projection.post.all_cells.flatten() 434 437 … … 443 446 n = self.n 444 447 445 targets = numpy.zeros(0, int) 446 loc_targets = [] 447 create = [] 448 448 targets = numpy.zeros(0, int) 449 449 while len(targets) < n: # if the number of requested cells is larger than the size of the 450 450 # postsynaptic population, we allow multiple connections for a given cell … … 455 455 targets = numpy.delete(targets, idx) 456 456 457 targets = targets[:n] 458 if isinstance(self.weights, basestring) or isinstance(self.delays, basestring): 459 distance_matrix.set_source(src.position) 460 461 # We need to keep only the local cells, because then distances will be computed only 462 # by the nodes that will established the connections. create is just a mask with all 463 # the id of the cells that are local and that need to be used. Same id could be repeted 464 # but this is not a problem. 465 for id in targets: 466 pos = numpy.where(id == projection.post.local_cells)[0] 467 N = len(pos) 468 if N > 0: 469 loc_targets += N*[id] 470 create += [pos[0]] 471 457 distance_matrix.set_source(src.position) 458 targets = targets[:n].astype(int) 459 create = targets - projection.post.first_id 472 460 weights = weights_generator.get(n, distance_matrix, create) 473 461 delays = delays_generator.get(n, distance_matrix, create) 474 462 475 if len( loc_targets) > 0:476 projection.connection_manager.connect(src, loc_targets, weights, delays)463 if len(targets) > 0: 464 projection.connection_manager.connect(src, targets.tolist(), weights, delays) 477 465 478 466 … … 538 526 n = self.n 539 527 540 sources = []528 sources = numpy.zeros(0, int) 541 529 while len(sources) < n: # if the number of requested cells is larger than the size of the 542 530 # presynaptic population, we allow multiple connections for a given cell … … 547 535 sources = numpy.delete(sources, i) 548 536 537 distance_matrix.set_source(tgt.position) 549 538 sources = sources[:n].astype(int) 550 551 if isinstance(self.weights, basestring) or isinstance(self.delays, basestring):552 distance_matrix.set_source(tgt.position)553 554 539 create = sources - projection.pre.first_id 555 540 weights = weights_generator.get(n, distance_matrix, create) -
trunk/test/unittests/generictests.py
r725 r728 886 886 for tgtP in [self.target6, self.target33]: 887 887 for conn in connectors: 888 print conn.w_expr888 #print conn.w_expr 889 889 prj = sim.Projection(srcP, tgtP, conn) 890 890 first_connection = prj.connections[0] … … 892 892 for c in first_connection, last_connection: 893 893 d = space.distance(c.source, c.target) 894 self.assertAlmostEqual(c.weight, eval(conn.w _expr), 10)894 self.assertAlmostEqual(c.weight, eval(conn.weights), 10) 895 895 896 896 class ProjectionSetTest(unittest.TestCase):
