Changeset 296

Show
Ignore:
Timestamp:
11/06/08 14:51:55 (2 months ago)
Author:
mschmucker
Message:

now using NeuroTools.stgen to generate a spike train.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/examples/parameter_search/parameter_search_example.py

    r197 r296  
    3131              quit_on_end = False) 
    3232     
    33     rate = param_dict['rate'] 
    3433    weight = param_dict['weight'] 
    3534     
    36     import numpy 
    37     spiketrain = numpy.linspace(start = 0., stop = 1000., num = rate,  
    38                                 endpoint = False) 
    39     source = sim.create(sim.SpikeSourceArray,  {'spike_times':spiketrain}) 
    40     neuron = sim.create(sim.IF_curr_alpha) 
    41     sim.connect(source, neuron, weight = weight,  delay = 1.) 
     35    import NeuroTools.stgen as stgen 
     36    stgen = stgen.StGen() 
     37    spiketrain = stgen.poisson_generator(param_dict['rate']/1000., tsim = 1000.) 
     38    source = sim.Population(1, sim.SpikeSourceArray,  {'spike_times':spiketrain}) 
     39    neuron = sim.Population(1, sim.IF_cond_alpha) 
     40    sim.Projection(source, neuron,  
     41                   method = sim.OneToOneConnector(weights = param_dict['weight'],  
     42                                                  delays = 1.)) 
    4243     
    4344    #set recorder 
    44     import tempfile 
    45     spikefile,  spikefilename = tempfile.mkstemp(prefix='test_parameter_search') 
    46     sim.record(neuron, spikefilename) 
     45    neuron.record() 
     46    neuron.record_v() 
    4747     
    4848    #run the simulation 
     
    5151     
    5252    # count the number of spikes 
    53     import pylab 
     53    spikes = neuron.getSpikes() 
     54    import tempfile 
     55    fd, potfile = tempfile.mkstemp(prefix = 'param_search_example_pot') 
     56    potential = neuron.print_v(potfile) 
     57    import pylab, numpy 
    5458    try: 
    55         spikes = pylab.load(spikefilename)[:,0] 
     59        pot = pylab.load(potfile)[:,0] 
    5660    except(ValueError): 
    57         spikes = numpy.array([]) 
     61        pot = numpy.array([]) 
     62    except Exception, e: 
     63        import pdb 
     64        pdb.set_trace() 
    5865    import os 
    59     os.remove(spikefilename) 
     66    os.remove(potfile) 
    6067    numspikes = len(spikes) 
    6168     
    6269    # return everything, including the input parameters 
    63     return {'source_rate':rate,  'weight':weight, 'neuron_rate':numspikes} 
     70    return {'source_rate':param_dict['rate'],  
     71            'weight':param_dict['weight'],  
     72            'neuron_rate':numspikes } 
    6473     
    6574def make_param_dict_list(): 
     
    7079    import numpy 
    7180    rates = numpy.linspace(start = 10., stop = 100.,  num = 5) 
    72     weights = numpy.linspace(start = 1.0,  stop = 25., num = 5) 
    73     dictlist = [] 
    74     for r in rates: 
    75         for w in weights: 
    76             dictlist.append({'rate':r,  'weight':w}) 
     81    weights = numpy.linspace(start = 0.1,  stop = 1.0, num = 5) 
     82    from NeuroTools.parameters import ParameterSet, ParameterSpace, ParameterRange 
     83    params = ParameterSpace(ParameterSet({'rate':ParameterRange(rates),  
     84                                          'weight': ParameterRange(weights)})) 
     85    dictlist = [p.as_dict() for p in params.iter_inner()] 
    7786    return dictlist 
    7887 
     
    113122    # search the parameter space 
    114123    param_dict_list = make_param_dict_list() 
    115     srchr = ps.RestartingIPythonParameterSearcher( 
    116                             dictlist = param_dict_list,  
    117                             func = model_network,  
    118                             task_furl = contr_dict['task_furl'], 
    119                             multiengine_furl = contr_dict['multiengine_furl'], 
    120                             engine_furl = contr_dict['engine_furl'], 
    121                             numengines = numengines)  
     124    srchr = ps.IPythonParameterSearcher( 
     125        dictlist = param_dict_list, 
     126        func = model_network) 
     127#     srchr = ps.RestartingIPythonParameterSearcher( 
     128#                             dictlist = param_dict_list,  
     129#                             func = model_network,  
     130#                             task_furl = contr_dict['task_furl'], 
     131#                             multiengine_furl = contr_dict['multiengine_furl'], 
     132#                             engine_furl = contr_dict['engine_furl'], 
     133#                             numengines = numengines)  
    122134    srchr.search() 
    123135    outlist = srchr.harvest()