Changeset 415

Show
Ignore:
Timestamp:
07/16/08 10:35:16 (1 month ago)
Author:
pierre
Message:

Add the possibility, in the common.py file, to select a particular model of plasticity when several are available for the same plastic rule. This is mainly used in NEST2, where I have also set the stdp_synapse_hom as the default type, because it's more efficient when (and it is often the case) all plasticity parameters are identitical. Add also the possibility, as discussed in a previous ticket, to give an expression for weights and delays in the DistanceDependentProbabilityConnector?, only implemented in nest1 and nest2 yet. Changes in the brunel.py file to do, like for the VA network, a comparison based on the number of nodes to be sure mpi simulations are doing what we want them to do...

Files:

Legend:

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

    r414 r415  
    10661066                    raise Exception("No available plasticity models") 
    10671067                elif len(possible_models) > 1 : 
    1068                     raise Exception("Multiple plasticity models available") 
     1068                    if self.synapse_dynamics.slow.model: 
     1069                        if self.synapse_dynamics.slow.model in list(possible_models): 
     1070                            self.long_term_plasticity_mechanism = self.synapse_dynamics.slow.model 
     1071                        else: 
     1072                            print "The particular model %s does not exists !" %self.synapse_dynamics.slow.model 
     1073                    else: 
     1074                        print "Several stdp models are available for those plastics connections" 
     1075                        for model in possible_models: 
     1076                            print "--> %s" %model 
     1077                        self.long_term_plasticity_mechanism = list(possible_models)[0] 
     1078                        print "By default, %s is used" %self.long_term_plasticity_mechanism 
     1079                    #raise Exception("Multiple plasticity models available") 
    10691080                 
    10701081                #print "Using %s" % self._plasticity_model 
     
    15421553     
    15431554    def __init__(self, timing_dependence=None, weight_dependence=None, 
    1544                  voltage_dependence=None, dendritic_delay_fraction=1.0): 
     1555                 voltage_dependence=None, dendritic_delay_fraction=1.0, model=None): 
    15451556        self.timing_dependence = timing_dependence 
    15461557        self.weight_dependence = weight_dependence 
    15471558        self.voltage_dependence = voltage_dependence 
    15481559        self.dendritic_delay_fraction = dendritic_delay_fraction 
     1560        self.model = model 
    15491561 
    15501562 
  • trunk/src/nest1/connectors.py

    r411 r415  
    116116            # We evaluate the probabilities of connections for those distances 
    117117            func = eval("lambda d: %s" %self.d_expression) 
    118             distances = func(distances[:,0]) 
     118            probabilities = func(distances[:,0]) 
    119119            rarr = rng.uniform(0, 1, (npre,)) 
    120             # We get the list of cells that will established a connection 
    121             source_list = numpy.compress((distances >= 1) | ((0 < distances) & (distances < 1) & (rarr <= distances)), presynaptic_neurons).tolist() 
     120            # We get the list of cells that will established a connecti 
     121            idx = numpy.where((probabilities >= 1) | ((0 < probabilities) & (probabilities < 1) & (rarr <= probabilities)))[0] 
     122            source_list = presynaptic_neurons[idx].tolist() 
    122123            # We remove the post cell if we don't allow self connections 
    123124            if not self.allow_self_connections and post in source_list: 
     125                idx.remove(source_list.index(post)) 
    124126                source_list.remove(post) 
    125127            N = len(source_list) 
    126             weights = self.getWeights(N) 
     128            if isinstance(self.weights,str): 
     129                func = eval("lambda d: %s" %self.weights) 
     130                weights = func(distances[:,0])[idx] 
     131            else: 
     132                weights = self.getWeights(N) 
    127133            weights = _convertWeight(weights, projection.synapse_type).tolist() 
    128             delays = self.getDelays(N).tolist() 
     134            # We deal with the fact that the user could have given a delays distance dependent 
     135            if isinstance(self.delays,str): 
     136                func = eval("lambda d: %s" %self.delays) 
     137                delays = func(distances[:,0])[idx].tolist() 
     138            else: 
     139                delays = self.getDelays(N).tolist() 
    129140            projection._targets += [post]*N 
    130141            projection._sources += source_list 
  • trunk/src/nest2/connectors.py

    r411 r415  
    114114            print "Periodic boundaries activated and set to size ", periodic_boundaries 
    115115        postsynaptic_neurons = projection.post.cell.flatten() # array 
    116        npost = len(postsynaptic_neurons) 
    117        #postsynaptic_neurons = projection.post.cell_local 
     116        npost = len(postsynaptic_neurons) 
     117        #postsynaptic_neurons = projection.post.cell_local 
    118118        # what about NativeRNG? 
    119119        if projection.rng: 
     
    132132            # We evaluate the probabilities of connections for those distances 
    133133            func = eval("lambda d: %s" %self.d_expression) 
    134             distances = func(distances[0]) 
     134            probabilities = func(distances[0]) 
    135135            # We get the list of cells that will established a connection 
    136136            rarr = rng.uniform(0, 1, (npost,)) 
    137             target_list = numpy.compress((distances >= 1) | ((0 < distances) & (distances < 1) & (rarr <= distances)), postsynaptic_neurons).tolist() 
    138             #target_list = postsynaptic_neurons[idx].tolist() 
     137            idx = numpy.where((probabilities >= 1) | ((0 < probabilities) & (probabilities < 1) & (rarr <= probabilities)))[0] 
     138            target_list = postsynaptic_neurons[idx].tolist() 
    139139            # We remove the pre cell if we don't allow self connections 
    140140            if not self.allow_self_connections and pre in target_list: 
     141                idx.remove(target_list.index(pre)) 
    141142                target_list.remove(pre) 
    142143            N = len(target_list) 
    143             weights = self.getWeights(N) 
    144             weights = _convertWeight(weights, projection.synapse_type).tolist() 
    145             delays = self.getDelays(N).tolist() 
     144            # We deal with the fact that the user could have given a weights distance dependent 
     145            if isinstance(self.weights,str): 
     146                func = eval("lambda d: %s" %self.weights) 
     147                weights = func(distances[0])[idx] 
     148            else: 
     149                weights = self.getWeights(N) 
     150            weights = _convertWeight(weights, projection.synapse_type).tolist() 
     151            # We deal with the fact that the user could have given a delays distance dependent 
     152            if isinstance(self.delays,str): 
     153                func = eval("lambda d: %s" %self.delays) 
     154                delays = func(distances[0])[idx].tolist() 
     155            else: 
     156                delays = self.getDelays(N).tolist() 
    146157            projection._targets += target_list 
    147158            projection._sources += [pre]*N  
  • trunk/src/nest2/synapses.py

    r407 r415  
    2222     
    2323    def __init__(self, timing_dependence=None, weight_dependence=None, 
    24                  voltage_dependence=None, dendritic_delay_fraction=1.0): 
     24                 voltage_dependence=None, dendritic_delay_fraction=1.0, model=None): 
    2525        assert dendritic_delay_fraction == 1, """NEST does not currently support axonal delays: 
    2626                                                 for the purpose of STDP calculations all delays 
    2727                                                 are assumed to be dendritic.""" 
    2828        common.STDPMechanism.__init__(self, timing_dependence, weight_dependence, 
    29                                       voltage_dependence, dendritic_delay_fraction
     29                                      voltage_dependence, dendritic_delay_fraction,model
    3030 
    3131 
     
    6262        ('A_minus',   'alpha', 'A_minus/A_plus', 'alpha*lambda'), 
    6363    ) 
    64     possible_models = set(['stdp_synapse',]) #'stdp_synapse_hom' 
     64    possible_models = set(['stdp_synapse_hom','stdp_synapse']) #'stdp_synapse_hom' 
    6565     
    6666    def __init__(self, w_min=0.0, w_max=1.0, A_plus=0.01, A_minus=0.01): # units? 
     
    8787        ('A_minus',   'alpha', 'A_minus/A_plus', 'alpha*lambda'), 
    8888    ) 
    89     possible_models = set(['stdp_synapse',]) #'stdp_synapse_hom' 
     89    possible_models = set(['stdp_synapse_hom','stdp_synapse']) #'stdp_synapse_hom' 
    9090         
    9191    def __init__(self, w_min=0.0, w_max=1.0, A_plus=0.01, A_minus=0.01): 
     
    111111        ('A_minus',   'alpha', 'A_minus/A_plus', 'alpha*lambda'), 
    112112    ) 
    113     possible_models = set(['stdp_synapse',]) #'stdp_synapse_hom' 
     113    possible_models = set(['stdp_synapse_hom','stdp_synapse']) #'stdp_synapse_hom' 
    114114         
    115115    def __init__(self, w_min=0.0, w_max=1.0, A_plus=0.01, A_minus=0.01): 
     
    138138        ('mu_minus',  'mu_minus'), 
    139139    ) 
    140     possible_models = set(['stdp_synapse',]) #'stdp_synapse_hom' 
     140    possible_models = set(['stdp_synapse_hom','stdp_synapse']) #'stdp_synapse_hom' 
    141141         
    142142    def __init__(self, w_min=0.0, w_max=1.0, A_plus=0.01, A_minus=0.01,mu_plus=0.5,mu_minus=0.5): 
     
    155155        ('tau_minus', 'tau_minus'), # defined in post-synaptic neuron 
    156156    ) 
    157     possible_models = set(['stdp_synapse',]) #'stdp_synapse_hom' 
     157    possible_models = set(['stdp_synapse_hom','stdp_synapse']) #'stdp_synapse_hom' 
    158158     
    159159    def __init__(self, tau_plus=20.0, tau_minus=20.0): 
  • trunk/src/neuron2/connectors.py

    r399 r415  
    134134                             periodic_boundaries) 
    135135        p_array = eval(self.d_expression) 
     136        if isinstance(self.weights,str): 
     137            raise Exception("The weights distance dependent are not implemented yet") 
     138        if isinstance(self.delays,str): 
     139            raise Exception("The delays distance dependent are not implemented yet") 
    136140        probabilistic_connect(self, projection, p_array.flatten()) 
    137141 
  • trunk/test/brunel.py

    r341 r415  
    2727                      # scale synaptic weights up by this factor to 
    2828                      # obtain similar dynamics independent of size 
    29 order       = 50000  # determines size of network: 
     29order       = 50000  # determines size of network: 
    3030                      # 4*order excitatory neurons 
    3131                      # 1*order inhibitory neurons 
     
    4848 
    4949# simulation-related parameters   
    50 simtime     = 100.0  # simulation time [ms]  
     50simtime     = 100.0  # simulation time [ms]  
    5151dt          = 0.1     # simulation step length [ms]    
    5252 
     
    5757# seed for random generator(s) used during simulation 
    5858kernelseed  = 43210987       
    59  
    60 exfilename  = "brunel_ex_%s.ras" % simulator # output file for excit. population   
    61 infilename  = "brunel_in_%s.ras" % simulator # output file for inhib. population   
    62 vexfilename = "brunel_ex_%s.v" % simulator # output file for membrane potential traces 
    63 vinfilename = "brunel_in_%s.v" % simulator # output file for membrane potential traces 
    6459   
    6560# === Calculate derived parameters ============================================= 
     
    113108# For NEST, limits must be set BEFORE connecting any elements 
    114109 
    115 extra = {'threads' : 2} 
     110#extra = {'threads' : 2} 
     111extra = {} 
    116112 
    117113myid = setup(timestep=dt, max_delay=delay, **extra) 
     114np = num_processes() 
     115import socket 
     116host_name = socket.gethostname() 
     117print "Host #%d is on %s" % (myid+1, host_name) 
    118118 
    119119if extra.has_key('threads'): 
    120120    print "%d Initialising the simulator with %d threads..." %(myid, extra['threads']) 
    121121else: 
    122     print "%d Initialising the simulator with single thread..." %(node_id) 
     122    print "%d Initialising the simulator with single thread..." %(myid) 
    123123 
    124124# Small function to display information only on node 1 
     
    130130 
    131131print "%d Setting up random number generator" %myid 
    132 rng = NumpyRNG(kernelseed+myid
     132rng = NumpyRNG(kernelseed, parallel_safe=True, rank=myid, num_processes=np
    133133 
    134134print "%d Creating excitatory population." %myid 
     
    139139 
    140140print "%d Initialising membrane potential to random values." %myid 
    141 rng2 = NumpyRNG(kernelseed+myid) 
    142 uniformDistr = RandomDistribution('uniform',[U0,theta],rng2) 
     141uniformDistr = RandomDistribution('uniform',[U0,theta],rng) 
    143142E_net.randomInit(uniformDistr) 
    144143I_net.randomInit(uniformDistr) 
     
    171170print "input --> E\t", len(input_to_E), "connections" 
    172171 
     172print E_to_E.describe() 
     173 
    173174print "%d Connecting inhibitory population." %myid 
    174175E_to_I = Projection(E_net, I_net, E_Connector, rng=rng, target="excitatory") 
     
    189190simCPUTime = Timer.elapsedTime() 
    190191 
     192exfilename  = "Results/Brunel_exc_%s_np%d.ras" % (simulator,np) # output file for excit. population   
     193infilename  = "Results/Brunel_inh_%s_np%d.ras" % (simulator,np) # output file for inhib. population   
     194vexfilename = "Results/Brunel_exc_%s_np%d.v"   % (simulator,np) # output file for membrane potential traces 
     195vinfilename = "Results/Brunel_inh_%s_np%d.v"   % (simulator,np) # output file for membrane potential traces 
     196 
    191197# write data to file 
    192198E_net.printSpikes(exfilename) 
     
    200206# write a short report 
    201207nprint("\n--- Brunel Network Simulation ---") 
     208nprint("Nodes              : %d" % np) 
    202209nprint("Number of Neurons  : %d" %N) 
    203210nprint("Number of Synapses : %d" %Nsyn) 
     
    209216nprint("Build time         : %g s" %buildCPUTime)    
    210217nprint("Simulation time    : %g s" %simCPUTime) 
    211  
    212218   
    213219# === Clean up and quit ======================================================== 
    214220 
    215221end() 
    216  
  • trunk/test/simple_STDP.py

    r384 r415  
    3636 
    3737if simulator == "nest2": 
    38     print nest.GetConnection([p1[0]], 'stdp_synapse', 0) 
     38    print nest.GetConnection([p1[0]], 'stdp_synapse_hom', 0) 
    3939    print nest.GetStatus([p2[0]]) 
    4040 
     
    4747    while t < 50: 
    4848        t = run(1.0) 
    49         syn_dict = nest.GetConnection([p1[0]], 'stdp_synapse', 0) 
     49        syn_dict = nest.GetConnection([p1[0]], 'stdp_synapse_hom', 0) 
    5050        print "%4.1f   %6.4f   %7.3f   %6.4f" % (t, prj.getWeights()[0], syn_dict['Kplus'], syn_dict['weight']) 
    5151#run(1000.0)