Show
Ignore:
Timestamp:
05/07/08 17:56:33 (4 years ago)
Author:
LaurentPerrinet
Message:

CodeJam? #2: clean-up of the NeuroTools package / removing benchmark.py and everything that depends on it (if you need it, find it in branches/working_concept2) / examples on single neuron are fine, still some work to do on retina

Files:
1 modified

Legend:

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

    r152 r165  
    1515import os, datetime, numpy 
    1616import retina as model 
    17 import NeuroTools.benchmark as benchmark 
     17 
     18from NeuroTools.parameters import * 
     19 
     20# this is not mandatory but just a "easy_install progressbar" away 
     21# else remove all corresponding lines in this code... 
     22import progressbar # see http://projects.scipy.org/pipermail/scipy-dev/2008-January/008200.html 
     23 
     24p = ParameterSet({}) 
     25N, N_exp_noise = 10, 22 
     26p.noise_std = ParameterRange(list(10.**(numpy.linspace(-.50,1.,N_exp_noise)))) 
     27retina = model.Retina(N) 
     28retina.params['snr'] = 0 
     29 
     30results = shelve.open('results/benchmark_noise') 
     31try: 
     32    CRF = results['CRF'] 
     33except: 
     34 
     35    # calculates the dimension of the parameter space 
     36    results_dim, results_label = p.parameter_space_dimension_labels() 
     37 
     38    # creates results array with size of parameter space dimension 
     39 
     40    CRF = numpy.empty(results_dim) 
     41 
     42    pbar=progressbar.ProgressBar(widgets=["calculating", " ", progressbar.Percentage(), ' ', 
     43            progressbar.Bar(), ' ', progressbar.ETA()], maxval=numpy.prod(results_dim)) 
     44    for i_exp,experiment in enumerate(p.iter_inner()): 
     45        params = retina.params 
     46        params.update(experiment) # updates what changed in the dictionary 
     47        # simulate the experiment and get its data 
     48        data = retina.run(params,verbose=False) 
     49        # calculating the index in the parameter space 
     50        index = p.parameter_space_index(experiment) 
     51        # put the data at the right position in the results array 
     52        CRF[index] = data.mean_rate()# 
     53        pbar.update(i_exp) 
     54 
     55    results['CRF'] = CRF 
     56    pbar.finish() 
     57 
     58results.close() 
     59 
     60from NeuroTools.plotting import pylab_params 
     61 
     62""" Figure 1 
     63 
     64Prints to a figure the mean firing rate for the output (ON and OFF) as a function of the different parameter values. It's similar to a CRF function. 
     65 
     66TODO put standard deviation of activity, print CV 
     67 
     68""" 
    1869 
    1970 
    20 def show(benchmark): 
    21     from NeuroTools.plotting import pylab_params 
     71params = retina.params 
     72N, simtime = params['N'], params['simtime'] 
    2273 
    23     """ Figure 1 
     74import pylab 
    2475 
    25     Prints to a figure the mean firing rate for the output (ON and OFF) as a function of the different parameter values. It's similar to a CRF function. 
     76#pylab.rcParams.update(pylab_params(fig_width_pt =497.9/5, ratio = 1/1.2)) 
     77pylab.figure(num = 1)#, dpi=200, facecolor='w', edgecolor='k') 
    2678 
    27     TODO put standard deviation of activity, print CV 
     79#Lmargin, Rmargin, dmargin, umargin = 0.15, 0.05, 0.15,  0.05 
     80#pylab.axes([Lmargin, dmargin , 1.0 - Rmargin- Lmargin,1.0-umargin-dmargin]) # [left, bottom, width, height] 
    2881 
    29     """ 
     82idx_ = numpy.argsort(noise_std) # extract lines 
     83pylab.plot(noise_std[idx_],CRF[idx_],'go-', label='line 1', linewidth=2) 
     84pylab.ylabel('Firing Frequency (Hz)') 
     85pylab.xlabel('Noise amplitude') 
     86#pylab.axis('tight') 
     87pylab.savefig('results/benchmark_noise.pdf')#, dpi=300) # 
     88#command = 'epstopdf  "%s" "%s"'% (pdffile, psfile) 
     89#os.system(command) 
    3090 
    31  
    32     params = benchmark.get('params') 
    33  
    34     N, simtime = params['N'], params['simtime'] 
    35     experiments = benchmark.list_experiments() 
    36     noise_std, CRF = numpy.zeros(len(experiments)), numpy.zeros(len(experiments)) 
    37     for count, experiment in enumerate(experiments): 
    38         out_ON_DATA = benchmark.get('out',experiment)['out_ON_DATA'] 
    39         noise_std[count] = benchmark.get('experiments')[experiment]['noise_std'] 
    40         CRF[count] = out_ON_DATA.mean_rate() 
    41  
    42  
    43     import pylab 
    44  
    45     #pylab.rcParams.update(pylab_params(fig_width_pt =497.9/5, ratio = 1/1.2)) 
    46     pylab.figure(num = 1)#, dpi=200, facecolor='w', edgecolor='k') 
    47  
    48     #Lmargin, Rmargin, dmargin, umargin = 0.15, 0.05, 0.15,  0.05 
    49     #pylab.axes([Lmargin, dmargin , 1.0 - Rmargin- Lmargin,1.0-umargin-dmargin]) # [left, bottom, width, height] 
    50  
    51     idx_ = numpy.argsort(noise_std) # extract lines 
    52     pylab.plot(noise_std[idx_],CRF[idx_],'go-', label='line 1', linewidth=2) 
    53     pylab.ylabel('Firing Frequency (Hz)') 
    54     pylab.xlabel('Noise amplitude') 
    55     #pylab.axis('tight') 
    56     pylab.savefig(benchmark.directory + '/benchmark_noise.pdf')#, dpi=300) # 
    57     #command = 'epstopdf  "%s" "%s"'% (pdffile, psfile) 
    58     #os.system(command) 
    59  
    60     #TODO: make a plot showing it's the right point process with a histogram 
    61  
    62  
    63 if __name__ == '__main__': 
    64  
    65     # create a Retina Model object that contains a method to init, to run, ... 
    66     ret = model.Retina(10) 
    67  
    68     tag = 'test' 
    69  
    70     name = 'results/' + tag + '_benchmark_noise' 
    71  
    72     # create the list of experiments as all possibilities accross parameter vectors 
    73     span, N_exp = 5, 2*7+1 
    74     #range = 10.**(numpy.linspace(-span,span,N_exp)) 
    75     range = numpy.linspace(1/span,span,N_exp) 
    76     run = benchmark.get_experiment_dict({'noise_std': ret.params['noise_std']* range, 'snr' : [ 0.0 ]}) 
    77  
    78     # create benchmark (or open it if it exists) 
    79     B = benchmark.Benchmark(name,ret,run) 
    80 # there are many ways to get data from the benchmark. see benchmark.py 
    81     B.run_simulations() 
    82  
    83     show(B) 
    84     #B.reset_all() # erase experimental data 
     91#TODO: make a plot showing it's the right point process with a histogram