Show
Ignore:
Timestamp:
11/14/08 19:17:05 (4 years ago)
Author:
LaurentPerrinet
Message:

some polishing of the wiki:examples, the retina needs a bit more work...

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/examples/retina/benchmark_retina.py

    r333 r340  
    2525import os, sys, numpy, pylab, shelve, progressbar 
    2626 
     27N, N_snr, N_seeds = 1000, 5, 10 
     28from NeuroTools.parameters import * 
     29p =  ParameterSpace({ 
     30                'snr' : ParameterRange(list(numpy.linspace(0.1,2.0,N_snr))), 
     31                'kernelseed' : ParameterRange(list([12345 + k for k in range(N_seeds)]))}) 
    2732 
    2833name = sys.argv[0].split('.')[0] # name of the current script withpout the '.py' part 
    29 ############## MAKING THE SIMULATIONS ############### 
    30 results = shelve.open('results/mat-' + name) 
     34 
    3135try: 
    32     DATA = results['DATA'] 
    33 except: 
     36    ############## MAKING THE SIMULATIONS ############### 
     37    results = shelve.open('results/mat-' + name) 
     38    try: 
     39        DATA = results['DATA'] 
     40        params = results['params'] 
     41    except: 
     42        from retina import * 
     43        retina = Retina(N) 
     44        # calculates the dimension of the parameter space 
     45        results_dim, results_label = p.parameter_space_dimension_labels() 
    3446 
    35     from NeuroTools.parameters import * 
     47        DATA = [] 
     48        pbar=progressbar.ProgressBar(widgets=[name, " ", progressbar.Percentage(), ' ', 
     49                progressbar.Bar(), ' ', progressbar.ETA()], maxval=N_snr*N_seeds) 
     50        for i_exp, experiment in enumerate(p.iter_inner()): 
     51            params = retina.params 
     52            params.update(experiment) # updates what changed in the dictionary 
     53            # simulate the experiment and get its data 
     54            data = retina.run(params)#,verbose=False) 
     55            # store it 
     56            DATA.append(data)# 
     57            pbar.update(i_exp) 
    3658 
    37     N, N_snr, N_seeds = 1000, 5, 10 
    38     from retina import * 
    39     retina = Retina(N) 
     59        results['DATA'] = DATA 
     60        results['params'] = retina.params 
    4061 
    41     t_smooth = 100. # ms.  integration time to show fiber activity 
    42  
    43     p =  ParameterSpace({ 
    44                     'snr' : ParameterRange(list(numpy.linspace(0.1,2.0,N_snr))), 
    45                     'kernelseed' : ParameterRange(list([retina.params['kernelseed'] + k for k in range(N_seeds)]))}) 
    46  
    47     # calculates the dimension of the parameter space 
    48     results_dim, results_label = p.parameter_space_dimension_labels() 
    49  
    50     DATA = [] 
    51  
    52     pbar=progressbar.ProgressBar(widgets=[name, " ", progressbar.Percentage(), ' ', 
    53             progressbar.Bar(), ' ', progressbar.ETA()], maxval=N_snr*N_seeds) 
    54     for i_exp, experiment in enumerate(p.iter_inner()): 
    55         params = retina.params 
    56         params.update(experiment) # updates what changed in the dictionary 
    57         # simulate the experiment and get its data 
    58         data = retina.run(params)#,verbose=False) 
    59         # store it 
    60         DATA.append(data)# 
    61         pbar.update(i_exp) 
    62  
    63     results['DATA'] = DATA 
    64  
    65     pbar.finish() 
    66  
    67 ############## PRE-PROCESSING ########################### 
    68 try: 
     62        pbar.finish() 
     63    results.close() 
     64    results = shelve.open('results/mat-pre-' + name) 
     65    ############## PRE-PROCESSING ########################### 
    6966    #boing # uncomment to force recomputing the pre-processing stage 
    7067    lower_edges = results['lower_edges'] 
     
    7370    temporal_OFF = results['temporal_OFF'] 
    7471    map_spatial_ON = results['map_spatial_ON'] 
     72    lower_edges = results['lower_edges'] 
     73    results.close() 
    7574 
    7675except: 
    77  
     76    def temporal_mean(spike_list): 
     77        return numpy.sum(spike_list.firing_rate(t_smooth),axis=0) 
     78         
     79    t_smooth = 100. # ms.  integration time to show fiber activity 
    7880    lower_edges = DATA[0]['out_ON_DATA'].time_axis(t_smooth) 
    79     N_smooth = len(lower_edges) 
    80     params = retina.params 
     81    N_smooth = len(lower_edges)-1 
    8182 
    8283    #N_snr = len(p.snr) 
     
    8687    # 
    8788    N_ret, simtime = params['N_ret'], params['simtime'] 
    88     # 
    8989    x = params['position'][0] 
    9090    y = params['position'][1] 
     
    9292    r = numpy.sqrt(r2) 
    9393    id_center = [int(k) for k in numpy.where( r2 < N_ret**2)[0]] 
    94  
    9594    # mean activity accross kernelseeds as a function of SNR 
    9695    for i_exp, experiment in enumerate(p.iter_inner()): 
     
    9897        index = p.parameter_space_index(experiment) 
    9998        # getting SpikeLists corresponding to the interesting parts (within the center) 
    100         temporal_ON[:,index[1]] += sum(DATA[i_exp]['out_ON_DATA'][id_center].firing_rate(t_smooth))/N_seeds 
    101         temporal_OFF[:,index[1]] += sum(DATA[i_exp]['out_OFF_DATA'][id_center].firing_rate(t_smooth))/N_seeds 
    102         map_spatial_ON[:,index[1]] += DATA[i_exp]['out_ON_DATA'].mean_rates(t_start=simtime/4.,t_stop=3*simtime/4.)/N_seeds 
    103         map_spatial_OFF[:,index[1]] += DATA[i_exp]['out_OFF_DATA'].mean_rates(t_start=simtime/4.,t_stop=3*simtime/4.)/N_seeds 
     99        temporal_ON[:,index[1]] += temporal_mean(DATA[i_exp]['out_ON_DATA'].id_slice(id_center))/N_seeds 
     100        temporal_OFF[:,index[1]] += temporal_mean(DATA[i_exp]['out_ON_DATA'].id_slice(id_center))/N_seeds 
     101        map_spatial_ON[:,index[1]] += DATA[i_exp]['out_ON_DATA'].mean_rates(t_start=simtime/4.,t_stop=3*simtime/4.)#/N_seeds 
     102        map_spatial_OFF[:,index[1]] += DATA[i_exp]['out_OFF_DATA'].mean_rates(t_start=simtime/4.,t_stop=3*simtime/4.)#/N_seeds 
    104103 
     104    results = shelve.open('results/mat-pre-' + name) 
    105105    results['temporal_ON'] = temporal_ON 
    106106    results['map_spatial_OFF'] = map_spatial_OFF 
    107107    results['temporal_OFF'] = temporal_OFF 
    108108    results['map_spatial_ON'] = map_spatial_ON 
     109    results['lower_edges'] = lower_edges 
     110    results.close() 
    109111 
    110112results.close() 
     
    133135#pylab.axes([Lmargin, dmargin , 1.0 - Rmargin- Lmargin,1.0-umargin-dmargin]) # [left, bottom, width, height] 
    134136pylab.subplot(131) 
    135 pylab.scatter(x,y,c=params['amplitude'],faceted=False) 
     137pylab.scatter(x,y,c=params['amplitude'], edgecolors='none') 
    136138 
    137139pylab.subplot(232) 
    138 pylab.plot(lower_edges,temporal_ON) 
     140pylab.plot(lower_edges[:-1],temporal_ON) 
    139141pylab.title('time course (ROI) ',fontsize = 'small') 
    140142#pylab.title('time course ON',fontsize = 'small') 
    141 pylab.xticks( numpy.linspace(0, simtime, 5) ) 
     143pylab.xticks( numpy.linspace(0, params.simtime, 5) ) 
    142144pylab.ylabel('ON activity (spike / s / neuron)') 
    143145#pylab.axis('tight') 
    144146pylab.subplot(235) 
    145 pylab.plot(lower_edges,temporal_OFF) 
     147pylab.plot(lower_edges[:-1],temporal_OFF) 
    146148#pylab.title('time course OFF',fontsize = 'small') 
    147 pylab.xticks( numpy.linspace(0, simtime, 5) ) 
     149pylab.xticks( numpy.linspace(0, params.simtime, 5) ) 
    148150pylab.ylabel('OFF activity (spike / s / neuron)') 
    149151#pylab.axis('tight') 
    150152pylab.xlabel('time (ms)') 
    151153pylab.subplot(233) 
    152 pylab.scatter(x, y, c= map_spatial_ON[:,-1], faceted=False) 
     154pylab.scatter(x, y, c= map_spatial_ON[:,-1], edgecolors='none') 
    153155#pylab.title('spatial distribution ON',fontsize ='small') 
    154156#pylab.title('spatial distribution',fontsize ='small') 
    155157pylab.subplot(236) 
    156 pylab.scatter(x, y, c= map_spatial_OFF[:,-1], faceted=False) 
     158pylab.scatter(x, y, c= map_spatial_OFF[:,-1], edgecolors='none') 
    157159#pylab.title('spatial distribution OFF',fontsize ='small') 
    158160#pylab.xlabel('distance from center') 
     
    161163 
    162164 
    163 pylab.savefig('results/fig-' + name + '.pdf') 
    164 pylab.savefig('results/fig-' + name + '.png', dpi = 300) 
     165if 1: 
     166    pylab.ion() 
     167    pylab.show() 
     168else: 
     169    pylab.savefig('results/fig-' + name + '.pdf') 
     170    pylab.savefig('results/fig-' + name + '.png', dpi = 300) 
     171 
     172