Changeset 326

Show
Ignore:
Timestamp:
11/12/08 19:49:46 (2 months ago)
Author:
LaurentPerrinet
Message:

wiki:examples : reflect changes in the wiki:parameters API / polishing figures to give usable examples

Files:

Legend:

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

    r301 r326  
    4949    """  
    5050    #set up the network 
    51     import pyNN.neuron as sim 
     51    import pyNN.nest2 as sim 
    5252    sim.setup(dt = 0.01,  min_delay = 1.,  max_delay = 1.,  debug = False,   
    5353              quit_on_end = False) 
  • trunk/examples/retina/benchmark_linear.py

    • Property svn:keywords set to Id
    r220 r326  
    1919 
    2020N, N_exp = 1000, 6 
    21 p = ParameterSet({}) 
    2221t_smooth = 100. # width (in ms) of the integration window 
    2322from retina import * 
    2423retina = Retina(N) 
     24retina.params['amplitude'] = 1 
     25snr  = retina.params['snr']* numpy.linspace(0.1,2.0,N_exp) 
     26p =  ParameterSpace({'snr' : ParameterRange(list(snr))}) 
     27 
    2528 
    2629name = sys.argv[0].split('.')[0] # name of the current script withpout the '.py' part 
     
    3336 
    3437except: 
    35     snr  = retina.params['snr']* numpy.linspace(0.1,2.0,N_exp) 
    36     p.snr = ParameterRange(list(snr)) 
     38 
    3739    # calculates the dimension of the parameter space 
    3840    results_dim, results_label = p.parameter_space_dimension_labels() 
     
    7880 
    7981""" 
    80 pylab.close('all') 
    81 pylab.rcParams.update(pylab_params(fig_width_pt = 497.9/2., ratio = 1.)) 
    82 pylab.figure(num = 1, dpi=150, facecolor='w', edgecolor='k') 
    83 Lmargin, Rmargin, dmargin, umargin = 0.2, 0.05, 0.15,  0.05 
    84 pylab.axes([Lmargin, dmargin , 1.0 - Rmargin- Lmargin,1.0-umargin-dmargin]) # [left, bottom, width, height] 
     82#pylab.close('all') 
     83#pylab.rcParams.update(pylab_params(fig_width_pt = 497.9/2., ratio = 1.)) 
     84pylab.figure(1) 
     85fmax = numpy.max([numpy.max(temporal_OFF[:]),numpy.max(temporal_ON[:])]) 
    8586 
     87pylab.subplot(211) 
    8688for i_exp in range(N_exp): 
    87     pylab.plot(lower_edges,  # TODO add a half bin 
    88                     temporal_ON[i_exp])#, 
    89                        # label= 'snr=' + str(benchmark.get('experiments')[experiment]['snr'])) 
    90 #pylab.subplot(121) 
    91 #pylab.title('time course')# ON 
     89    pylab.plot(lower_edges[:-1] + t_smooth/2,  # TODO add a half bin 
     90                    temporal_ON[i_exp])# 
    9291pylab.xticks( numpy.round(numpy.linspace(0, retina.params.simtime, 5),0) ) 
    93 pylab.ylabel('Firing frequency (Hz)') 
     92pylab.ylabel('ON Firing frequency (Hz/neuron)') 
     93pylab.axis([0, retina.params.simtime, 0.0, fmax]) 
     94pylab.subplot(212) 
     95for i_exp in range(N_exp): 
     96    pylab.plot(lower_edges[:-1] + t_smooth/2,  # TODO add a half bin 
     97                    temporal_OFF[i_exp], 
     98                        label= 'snr= %5.3f' % p.snr._values[i_exp] ) 
     99pylab.xticks( numpy.round(numpy.linspace(0, retina.params.simtime, 5),0) ) 
     100pylab.ylabel('OFF Firing frequency (Hz/neuron)') 
    94101pylab.xlabel('time (ms)') 
    95 pylab.axis('tight'
     102pylab.axis([0, retina.params.simtime, 0.0, fmax ]
    96103 
    97 #pylab.legend(
     104pylab.legend(loc='upper right'
    98105 
    99 #pylab.subplot(122) 
    100 #pylab.title('time course OFF') 
    101 #pylab.xticks( numpy.linspace(0, simtime, 5) ) 
    102 #pylab.ylabel('firing frequency (Hz)') 
    103 #pylab.axis('tight') 
    104 #pylab.xlabel('time (ms)') 
    105 #pylab.legend() 
    106106 
    107 pylab.savefig('results/fig-' + name + '.pdf') 
    108 pylab.savefig('results/fig-' + name + '.png', dpi = 300) 
     107if 0: 
     108    pylab.ion() 
     109    #pylab.show() 
     110else: 
     111    pylab.savefig('results/fig-' + name + '.pdf') 
     112    pylab.savefig('results/fig-' + name + '.png', dpi = 300) 
    109113 
    110 #TODO: make a plot showing it's the right point process with a histogram 
  • trunk/examples/retina/benchmark_noise.py

    • Property svn:keywords set to Id
    r172 r326  
    2525import progressbar # see http://projects.scipy.org/pipermail/scipy-dev/2008-January/008200.html 
    2626 
    27 N, N_exp_noise = 100, 22 
    28 p = ParameterSet({}) 
    29 p.noise_std = ParameterRange(list(10.**(numpy.linspace(-.50,1.,N_exp_noise)))
     27N, N_exp_noise = 1000, 22 
     28 
     29p =  ParameterSpace({'noise_std' : ParameterRange(list(10.**(numpy.linspace(-.50,1.,N_exp_noise))))}
    3030 
    3131import retina as model 
    32  
    33  
    3432retina = model.Retina(N)  
    3533retina.params['snr'] = 0 # no input 
     
    8785pylab.xlabel('Noise amplitude') 
    8886 
    89 pylab.savefig('results/fig-' + name + '.pdf') 
    90 pylab.savefig('results/fig-' + name + '.png', dpi = 300) 
    9187 
     88if 0: 
     89    pylab.show() 
     90else: 
     91    pylab.savefig('results/fig-' + name + '.pdf') 
     92    pylab.savefig('results/fig-' + name + '.png', dpi = 300) 
     93 
     94 
     95#TODO: make a plot showing that spontaneous activity is a point process with a known histogram 
  • trunk/examples/retina/benchmark_retina.py

    • Property svn:keywords set to Id
    r172 r326  
    2828 
    2929N, N_snr, N_seeds = 1000, 5, 10 
    30 p = ParameterSet({}) 
     30from retina import * 
     31retina = Retina(N) 
     32 
    3133t_smooth = 100. # ms.  integration time to show fiber activity 
    3234 
    33 from retina import * 
    34 retina = Retina(N) 
    35 p.snr = ParameterRange(list(retina.params['snr']* numpy.linspace(0.1,2.0,N_snr)))     
    36 p.kernelseed = ParameterRange(list([retina.params['kernelseed'] + k for k in range(N_seeds)])) 
     35p =  ParameterSpace({ 
     36                'snr' : ParameterRange(list(numpy.linspace(0.1,2.0,N_snr))), 
     37                'kernelseed' : ParameterRange(list([retina.params['kernelseed'] + k for k in range(N_seeds)]))}) 
     38 
    3739 
    3840name = sys.argv[0].split('.')[0] # name of the current script withpout the '.py' part 
    39  
    4041#### MAKING THE SIMULATIONS ########## 
    4142results = shelve.open('results/mat-' + name) 
     
    4344    DATA = results['DATA'] 
    4445except: 
    45      
     46 
    4647    # calculates the dimension of the parameter space 
    4748    results_dim, results_label = p.parameter_space_dimension_labels() 
     
    5556        params.update(experiment) # updates what changed in the dictionary 
    5657        # simulate the experiment and get its data 
    57         data = retina.run(params,verbose=False) 
     58        data = retina.run(params)#,verbose=False) 
    5859        # store it 
    5960        DATA.append(data)# 
     
    6162 
    6263    results['DATA'] = DATA 
    63      
     64 
    6465    pbar.finish() 
    6566 
    66 results.close() 
    67  
    6867############## PRE-PROCESSING ########################### 
    69 results = shelve.open('results/mat-' + name) 
    7068try: 
    71     #boing # to force recomputing 
     69    #boing # uncomment to force recomputing 
    7270    lower_edges = results['lower_edges'] 
    7371    temporal_ON = results['temporal_ON'] 
     
    7775 
    7876except: 
    79      
     77 
    8078    lower_edges = DATA[0]['out_ON_DATA'].time_axis(t_smooth) 
    8179    N_smooth = len(lower_edges) 
    8280    params = retina.params 
    83      
     81 
    8482    #N_snr = len(p.snr) 
    8583    temporal_ON, temporal_OFF = numpy.zeros((N_smooth,N_snr)), numpy.zeros((N_smooth,N_snr)) 
    8684    map_spatial_ON, map_spatial_OFF  = numpy.zeros((N,N_snr)), numpy.zeros((N,N_snr)) 
    87      
     85 
    8886    # 
    8987    N_ret, simtime = params['N_ret'], params['simtime'] 
     
    9593    id_center = [int(k) for k in numpy.where( r2 < N_ret**2)] 
    9694 
    97     # mean activity accross kernelseeds as a function of SNR     
     95    # mean activity accross kernelseeds as a function of SNR 
    9896    for i_exp, experiment in enumerate(p.iter_inner()): 
    9997        # calculating the index in the parameter space 
     
    104102        map_spatial_ON[:,index[1]] += DATA[i_exp]['out_ON_DATA'].mean_rates(t_start=simtime/4.,t_stop=3*simtime/4.)/N_seeds 
    105103        map_spatial_OFF[:,index[1]] += DATA[i_exp]['out_OFF_DATA'].mean_rates(t_start=simtime/4.,t_stop=3*simtime/4.)/N_seeds 
    106          
     104 
    107105    results['temporal_ON'] = temporal_ON 
    108106    results['map_spatial_OFF'] = map_spatial_OFF 
     
    110108    results['map_spatial_ON'] = map_spatial_ON 
    111109 
     110results.close() 
    112111 
    113112############# MAKING FIGURE ############################ 
     
    118117pylab.ioff() #pylab.ion() # 
    119118 
    120 """ Figure  
     119""" Figure 
    121120 
    122121Prints to a figure the mean firing rate 
     
    164163pylab.savefig('results/fig-' + name + '.pdf') 
    165164pylab.savefig('results/fig-' + name + '.png', dpi = 300) 
    166  
  • trunk/examples/retina/make_all.py

    • Property svn:keywords set to Id
  • trunk/examples/retina/retina.py

    • Property svn:keywords set to Id
    r220 r326  
    179179        phr_ON = sim.Population((N,),'dc_generator') 
    180180        phr_OFF  = sim.Population((N,),'dc_generator') 
     181 
     182 
    181183        for factor, phr in [(-params['snr'],phr_OFF),(params['snr'],phr_ON)]: 
    182184            phr.tset('amplitude', params['amplitude'] * factor ) 
     
    251253            print(params['description']) 
    252254            print "Number of Neurons  : ", N 
    253             #print "Output rate  (ON) : ", out_ON_DATA.meanRate(), "spikes/neuron in ", params['simtime'], "ms" 
    254             #print "Output rate (OFF)   : ", out_OFF_DATA.meanSpikeCount(), "spikes/neuron in ",params['simtime'], "ms" 
     255            print "Output rate  (ON) : ", out_ON_DATA.mean_rate(), "Hz/neuron in ", params['simtime'], "ms" 
     256            print "Output rate (OFF)   : ", out_OFF_DATA.mean_rate(), "Hz/neuron in ",params['simtime'], "ms" 
    255257            print("Build time             : %g s" % buildCPUTime)  
    256258            print("Simulation time        : %g s" % simCPUTime) 
     
    262264if __name__ == '__main__': 
    263265 
    264     ret = Retina(1000
     266    ret = Retina(100
    265267    out = ret.run(ret.params) 
    266268    # plotting 
     
    268270    fig = pylab.figure(1) 
    269271    z = pylab.subplot(121) 
    270     out['out_ON_DATA'].raster_plot(id_list=range(20), kwargs={'color':'b'}) 
     272    out['out_ON_DATA'].raster_plot(display=z, id_list=range(20), kwargs={'color':'r'}) 
    271273    z = pylab.subplot(122) 
    272     out['out_OFF_DATA'].raster_plot(id_list=range(20),display=z, kwargs={'color':'r'}) 
    273  
    274  
     274    out['out_OFF_DATA'].raster_plot(display=z, id_list=range(20), kwargs={'color':'b'}) 
     275    fig = pylab.figure(2) 
     276    z = pylab.subplot(111) 
     277    out['out_ON_DATA'].firing_rate(ret.params.simtime/100, display=z, kwargs={'label':'ON','color':'r'}) 
     278    out['out_OFF_DATA'].firing_rate(ret.params.simtime/100, display=z, kwargs={'label':'OFF','color':'b'}) 
     279    pylab.legend() 
     280 
  • trunk/examples/retina/test_parallel.py

    • Property svn:keywords set to Id
  • trunk/examples/single_neuron/CRF_neuron_vs_signal.py

    • Property svn:keywords set to Id
    r315 r326  
    2727 
    2828 
    29 p = ParameterSet({}) 
    30 N_exp_noise = 10 
    3129N_exp_snr = 25 
     30N_exp_noise = 9 
    3231 
    3332ps =  ParameterSpace({ 
     
    6968 
    7069#numpy.array(p.noise_std._values),numpy.array(p.snr._values), 
    71 pylab.plot(CRF.transpose()) #color = (sin(2*pi*noise_list)**2,cos(2*pi*noise_list)**2,1)) 
     70#pylab.plot(ps.snr._values,CRF.transpose()) #color = (sin(2*pi*noise_list)**2,cos(2*pi*noise_list)**2,1)) 
     71for i_noise, noise in enumerate(ps.noise_std._values): 
     72    pylab.plot(ps.snr._values,CRF[i_noise,:], label='noise = %5.3f' % noise) 
    7273#pylab.yticks(p.noise_std._values[:2:]) 
    7374pylab.ylabel('Firing Rate (Hz/neuron)') 
    7475#pylab.xticks(p.snr._values[:2:]) 
    7576pylab.xlabel('Signal') 
    76 #pylab.colorbar() 
    77 pylab.axis('tight') 
    78 pylab.savefig('results/fig-' + name + '.pdf') 
    79 pylab.savefig('results/fig-' + name + '.png') 
     77pylab.legend(loc = 'lower right') 
     78pylab.axis([numpy.min(ps.snr._values), numpy.max(ps.snr._values), 0.0, numpy.max(CRF[:])]) 
     79if 0: 
     80    pylab.show() 
     81else: 
     82    pylab.savefig('results/fig-' + name + '.pdf') 
     83    pylab.savefig('results/fig-' + name + '.png') 
  • trunk/examples/single_neuron/playing_with_simple_single_neuron.py

    • Property svn:keywords set to Id
  • trunk/examples/single_neuron/simple_single_neuron.py

    • Property svn:keywords set to Id