| 17 | | import NeuroTools.benchmark as benchmark |
| | 17 | |
| | 18 | from 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... |
| | 22 | import progressbar # see http://projects.scipy.org/pipermail/scipy-dev/2008-January/008200.html |
| | 23 | |
| | 24 | p = ParameterSet({}) |
| | 25 | N, N_exp_noise = 10, 22 |
| | 26 | p.noise_std = ParameterRange(list(10.**(numpy.linspace(-.50,1.,N_exp_noise)))) |
| | 27 | retina = model.Retina(N) |
| | 28 | retina.params['snr'] = 0 |
| | 29 | |
| | 30 | results = shelve.open('results/benchmark_noise') |
| | 31 | try: |
| | 32 | CRF = results['CRF'] |
| | 33 | except: |
| | 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 | |
| | 58 | results.close() |
| | 59 | |
| | 60 | from NeuroTools.plotting import pylab_params |
| | 61 | |
| | 62 | """ Figure 1 |
| | 63 | |
| | 64 | 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. |
| | 65 | |
| | 66 | TODO put standard deviation of activity, print CV |
| | 67 | |
| | 68 | """ |
| 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 |