Changeset 1015

Show
Ignore:
Timestamp:
11/25/11 14:53:10 (6 months ago)
Author:
apdavison
Message:

Implemented (together with Jochen and Mikael) NEST-specific version of the CSAConnector, which uses the NEST connection-generator interface currently available in the csanest branch of NEST.

Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/examples/VAbenchmarks2-csa.py

    r998 r1015  
    126126inh_cells = all_cells[n_exc:] 
    127127if benchmark == "COBA": 
    128     ext_stim = Population(20, SpikeSourcePoisson,{'rate' : rate, 'duration' : stim_dur},"expoisson") 
     128    ext_stim = Population(20, SpikeSourcePoisson, {'rate' : rate, 'duration' : stim_dur}, label="expoisson") 
    129129    rconn = 0.01 
    130130    ext_conn = FixedProbabilityConnector(rconn, weights=0.1) 
    131131 
    132132print "%s Initialising membrane potential to random values..." % node_id 
    133 rng = NumpyRNG(seed=rngseed, parallel_safe=parallel_safes) 
     133rng = NumpyRNG(seed=rngseed, parallel_safe=parallel_safe) 
    134134uniformDistr = RandomDistribution('uniform', [v_reset,v_thresh], rng=rng) 
    135135all_cells.initialize('v', uniformDistr) 
  • trunk/src/connectors.py

    r1003 r1015  
    898898            Connector.__init__(self, None, None, safe=safe, verbose=verbose) 
    899899            self.cset = cset 
    900             if cset.arity == 0: 
     900            if csa.arity(cset) == 0: 
    901901                #assert weights is not None and delays is not None, \ 
    902902                #       'must specify weights and delays in addition to a CSA mask' 
     
    906906                self.delays = delays 
    907907            else: 
    908                 assert cset.arity == 2, 'must specify mask or connection-set with arity 2' 
     908                assert csa.arity(cset) == 2, 'must specify mask or connection-set with arity 2' 
    909909                assert weights is None and delays is None, \ 
    910910                       "weights or delays specified both in connection-set and as CSAConnector argument" 
     
    926926        if self.delays is None: 
    927927            self.delays = projection._simulator.state.min_delay 
    928         i0 = projection.pre.first_id 
    929         size1 = projection.pre.last_id - i0 
    930         j0 = projection.post.first_id 
    931         targets = [j - j0 for j in projection.post] 
    932  
    933         # Cut out finite part and shift to global ids 
    934         c = csa.shift (i0, j0) * csa.cross ((0, size1), targets) * self.cset 
    935          
    936         if csa.arity (self.cset) == 2: 
     928        # Cut out finite part 
     929        c = csa.cross((0, projection.pre.size-1), (0, projection.post.size-1)) * self.cset 
     930         
     931        if csa.arity(self.cset) == 2: 
    937932            # Connection-set with arity 2 
    938933            for (i, j, weight, delay) in c: 
    939                 projection._divergent_connect (i, [j], weight, delay) 
     934                projection._divergent_connect(projection.pre[i], [projection.post[j]], weight, delay) 
    940935        elif CSAConnector.isConstant (self.weights) \ 
    941936             and CSAConnector.isConstant (self.delays): 
    942937            # Mask with constant weights and delays 
    943938            for (i, j) in c: 
    944                 projection._divergent_connect (i, [j], self.weights, self.delays) 
     939                projection._divergent_connect (projection.pre[i], [projection.post[j]], self.weights, self.delays) 
    945940        else: 
    946941            # Mask with weights and/or delays iterable 
     
    952947                delays = CSAConnector.constantIterator (delays) 
    953948            for (i, j), weight, delay in zip (c, weights, delays): 
    954                 projection._divergent_connect (i, [j], weight, delay) 
     949                projection._divergent_connect (projection.pre[i], [projection.post[j]], weight, delay) 
  • trunk/src/nest/connectors.py

    r1013 r1015  
    1616import numpy 
    1717from pyNN.space import Space 
    18  
    19  
    20  
     18from pyNN.common.populations import Population 
     19try: 
     20    import csa 
     21    have_csa = True 
     22except ImportError: 
     23    have_csa = False 
     24import nest 
    2125 
    2226class FastProbabilisticConnector(Connector): 
     
    209213            connector._probabilistic_connect(tgt, proba, self.n_connections, self.rewiring) 
    210214            self.progression(count, projection._simulator.state.mpi_rank) 
     215 
     216 
     217class CSAConnector(CSAConnector): 
     218     
     219    def connect(self, projection): 
     220        """Connect-up a Projection.""" 
     221        if self.delays is None: 
     222            self.delays = projection._simulator.state.min_delay 
     223 
     224        def connect_csa(cset, pre, post, syn_type): 
     225            print "connecting using cset" 
     226            if isinstance(pre, Population) and isinstance(post, Population): 
     227                # contiguous IDs, so just pass first_id and size 
     228                nest.sli_func("Connect_cg_i_i_i_i_D_l", 
     229                              self.cset, 
     230                              pre.first_id, pre.size, 
     231                              post.first_id, post.size, 
     232                              {'weight': 0, 'delay': 1}, # ignored if arity==0 
     233                              syn_type) 
     234            else: # PopulationViews or Assemblies 
     235                # IDs may be non-contiguous, so need to pass entire arrays 
     236                nest.sli_func("Connect_cg_a_a_D_l", 
     237                              self.cset, 
     238                              pre.all_cells, 
     239                              post.all_cells, 
     240                              {'weight': 0, 'delay': 1}, # ignored if arity==0 
     241                              syn_type) 
     242        # TODO: fix weights units 
     243        if csa.arity(self.cset) == 2: 
     244            # Connection-set with arity 2 
     245            connect_csa(self.cset, projection.pre, 
     246                        projection.post, projection.synapse_model) 
     247        elif CSAConnector.isConstant(self.weights) \ 
     248            and CSAConnector.isConstant(self.delays): 
     249            # Mask with constant weights and delays 
     250            assert csa.arity(self.cset) == 0 
     251            nest.SetDefaults(projection.synapse_model, {'weight': self.weights, 'delay': self.delays}) 
     252            connect_csa(self.cset, projection.pre, 
     253                        projection.post, projection.synapse_model) 
     254        projection._sources = projection.pre.all_cells