Changeset 728

Show
Ignore:
Timestamp:
03/11/10 17:41:37 (2 years ago)
Author:
pierre
Message:

Minor modification in the test to be able to pass the tests for connectors2.py. Still in testing phase, but you can try it if you want, and report bugs if any. Seems to work. I'll add also a progressbar I think to all those Connector, to be able to visualize the status of the connections. Can be useful maybe, to have an idea of the building time

Location:
trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/connectors2.py

    r727 r728  
    33from pyNN.space import Space 
    44from pyNN.random import RandomDistribution 
    5 from numpy import exp 
     5from 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 
    68 
    79class ConnectionAttributeGenerator(object): 
     
    2729            return values 
    2830        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) 
    3235            return values 
    3336        elif isinstance(self.source, numpy.ndarray): 
     
    4447      ConnectionAttributeGenerator.__init__(self, source, local_mask, safe) 
    4548      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       
    4851    def check(self, weight): 
    4952        if weight is None: 
     
    167170        self.projection        = projection 
    168171        self.allow_self_connections = allow_self_connections 
    169  
     172         
    170173    def _probabilistic_connect(self, src, p): 
    171174        """ 
     
    178181            create = numpy.arange(self.local.sum()) 
    179182        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)         
    186188        targets = self.projection.post.local_cells[create] 
    187189        weights = self.weights_generator.get(self.N, self.distance_matrix, create) 
     
    226228         
    227229    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()): 
    230232            connector._probabilistic_connect(src, 1) 
     233 
    231234 
    232235     
     
    430433        weights_generator = WeightGenerator(self.weights, local, projection, self.safe) 
    431434        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))) 
    433436        candidates        = projection.post.all_cells.flatten()             
    434437         
     
    443446                n = self.n 
    444447             
    445             targets     = numpy.zeros(0, int) 
    446             loc_targets = [] 
    447             create      = [] 
    448              
     448            targets     = numpy.zeros(0, int)             
    449449            while len(targets) < n: # if the number of requested cells is larger than the size of the 
    450450                                    # postsynaptic population, we allow multiple connections for a given cell                 
     
    455455                    targets = numpy.delete(targets, idx) 
    456456             
    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             
    472460            weights = weights_generator.get(n, distance_matrix, create) 
    473461            delays  = delays_generator.get(n, distance_matrix, create)             
    474462                         
    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) 
    477465                     
    478466 
     
    538526                n = self.n 
    539527             
    540             sources = [] 
     528            sources = numpy.zeros(0, int) 
    541529            while len(sources) < n: # if the number of requested cells is larger than the size of the 
    542530                                    # presynaptic population, we allow multiple connections for a given cell 
     
    547535                    sources = numpy.delete(sources, i) 
    548536             
     537            distance_matrix.set_source(tgt.position)         
    549538            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              
    554539            create  = sources - projection.pre.first_id 
    555540            weights = weights_generator.get(n, distance_matrix, create) 
  • trunk/test/unittests/generictests.py

    r725 r728  
    886886            for tgtP in [self.target6, self.target33]: 
    887887                for conn in connectors: 
    888                     print conn.w_expr 
     888                    #print conn.w_expr 
    889889                    prj = sim.Projection(srcP, tgtP, conn) 
    890890                    first_connection = prj.connections[0] 
     
    892892                    for c in first_connection, last_connection: 
    893893                       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) 
    895895 
    896896class ProjectionSetTest(unittest.TestCase):