Changeset 441

Show
Ignore:
Timestamp:
08/12/08 14:37:01 (3 months ago)
Author:
pierre
Message:

Minors optimization and cleanup in the DistanceDependentProbabilityConnectors? for nest1, nest2 and brian.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/brian/connectors.py

    r436 r441  
    55 
    66from pyNN import common 
    7 from pyNN.brian.__init__ import numpy, PoissonGroupWithDelays 
     7from pyNN.brian.__init__ import numpy 
    88import brian_no_units_no_warnings 
    99import brian, types 
     
    2424    src   = projection.pre.brian_cells 
    2525    tgt   = projection.post.brian_cells 
    26     delay = Connector.delays*0.001 
     26    delay = max(projection.pre.brian_cells.clock.dt,Connector.delays*0.001) 
    2727    connection = brian.Connection(src, tgt, target, delay=delay) 
    2828    return connection 
     
    9393        # The -2 comes from the fact that brian will make 2 tests calls before 
    9494        # using the function. 
    95         nb_conn = -2 
     95        #nb_conn = -2 
    9696        post    = projection.post 
    9797        N       = len(post) 
     98        get_proba   = eval("lambda d: %s" %self.d_expression) 
     99        get_weights = eval("lambda d: %s" %self.weights) 
    98100         
    99101        def topoconnect(i,j): 
     
    102104            distances = common.distances(pre, post, self.mask, 
    103105                                         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) 
    107108            # We get the list of cells that will established a connection 
    108109            rarr  = rng.uniform(0, 1, N) 
    109110            conn  = ((p >= 1) | ((0 < p) & (p < 1) & (rarr <= p))) 
    110111            if isinstance(self.weights,str): 
    111                 func = eval("lambda d: %s" %self.weights) 
    112                 weights = func(distances[0]) 
     112                weights = get_weights(distances) 
    113113            else: 
    114114                weights = self.weights*numpy.ones(N) 
     
    126126        projection._connections = _targetConnection(self, projection) 
    127127        projection._connections.connect_full(projection.pre.brian_cells,projection.post.brian_cells,weight=topoconnect) 
     128        #print nb_conn 
    128129        return projection._connections.W.getnnz() 
    129130     
  • trunk/src/nest1/connectors.py

    r433 r441  
    116116        else: 
    117117            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             
    118123        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] 
    120125            # 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) 
    123127            rarr = rng.uniform(0, 1, (npre,)) 
    124128            # We get the list of cells that will established a connecti 
    125             idx = numpy.where((probabilities >= 1) | ((0 < probabilities) & (probabilities < 1) & (rarr <= probabilities)))[0] 
     129            idx = numpy.where((proba >= 1) | ((0 < proba) & (proba < 1) & (rarr <= proba)))[0] 
    126130            source_list = presynaptic_neurons[idx].tolist() 
    127131            # We remove the post cell if we don't allow self connections 
     
    131135            N = len(source_list) 
    132136            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]) 
    135138            else: 
    136139                weights = self.getWeights(N) 
     
    138141            # We deal with the fact that the user could have given a delays distance dependent 
    139142            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() 
    142144            else: 
    143145                delays = self.getDelays(N).tolist() 
  • trunk/src/nest2/connectors.py

    r433 r441  
    132132        else: 
    133133            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             
    134139        for pre in projection.pre.cell.flat: 
    135140            # We compute the distances from the post cell to all the others 
    136141            distances = common.distances(pre, projection.post, self.mask, 
    137142                                         self.scale_factor, self.offset, 
    138                                          periodic_boundaries) 
     143                                         periodic_boundaries)[0] 
    139144            # 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) 
    142146            # We get the list of cells that will established a connection 
    143147            rarr = rng.uniform(0, 1, (npost,)) 
    144             idx = numpy.where((probabilities >= 1) | ((0 < probabilities) & (probabilities < 1) & (rarr <= probabilities)))[0] 
     148            idx = numpy.where((proba >= 1) | ((0 < proba) & (proba < 1) & (rarr <= proba)))[0] 
    145149            target_list = postsynaptic_neurons[idx].tolist() 
    146150            # We remove the pre cell if we don't allow self connections 
     
    151155            # We deal with the fact that the user could have given a weights distance dependent 
    152156            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]) 
    155158            else: 
    156159                weights = self.getWeights(N) 
     
    158161            # We deal with the fact that the user could have given a delays distance dependent 
    159162            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() 
    162164            else: 
    163165                delays = self.getDelays(N).tolist() 
     
    167169            nest.DivergentConnectWD([pre], target_list, weights, delays) 
    168170        return len(projection._sources) 
    169  
    170171 
    171172class FixedNumberPostConnector(common.FixedNumberPostConnector):