| 1 | #!/usr/bin/env python |
|---|
| 2 | #-*- coding: utf8 -*- |
|---|
| 3 | """ |
|---|
| 4 | benchmark_noise.py |
|---|
| 5 | ================== |
|---|
| 6 | |
|---|
| 7 | Just studying how different background noise current are integrated by the |
|---|
| 8 | neurons on the retinal fibers. |
|---|
| 9 | |
|---|
| 10 | Illustrates how one many use parameters to explore one set of parameters and |
|---|
| 11 | compute a CRF function. See benchmark_linear to store time varrying values. |
|---|
| 12 | |
|---|
| 13 | Laurent Perrinet, INCM, CNRS |
|---|
| 14 | |
|---|
| 15 | $ Id $ |
|---|
| 16 | |
|---|
| 17 | """ |
|---|
| 18 | |
|---|
| 19 | import os, sys, numpy, shelve |
|---|
| 20 | |
|---|
| 21 | N, N_exp_noise = 1000, 22 |
|---|
| 22 | from NeuroTools.parameters import * |
|---|
| 23 | p = ParameterSpace({'noise_std' : ParameterRange(list(10.**(numpy.linspace(-.50,1.,N_exp_noise))))}) |
|---|
| 24 | |
|---|
| 25 | name = sys.argv[0].split('.')[0] # name of the current script withpout the '.py' part |
|---|
| 26 | results = shelve.open('results/mat-' + name) |
|---|
| 27 | try: |
|---|
| 28 | CRF = results['CRF'] |
|---|
| 29 | except: |
|---|
| 30 | # this is not mandatory but just a "easy_install progressbar" away |
|---|
| 31 | # else remove all corresponding lines in this code... |
|---|
| 32 | import progressbar # see http://projects.scipy.org/pipermail/scipy-dev/2008-January/008200.html |
|---|
| 33 | import retina as model |
|---|
| 34 | retina = model.Retina(N) |
|---|
| 35 | retina.params['snr'] = 0 # no input |
|---|
| 36 | |
|---|
| 37 | # calculates the dimension of the parameter space |
|---|
| 38 | results_dim, results_label = p.parameter_space_dimension_labels() |
|---|
| 39 | |
|---|
| 40 | # creates results array with size of parameter space dimension |
|---|
| 41 | CRF = numpy.empty(results_dim) |
|---|
| 42 | |
|---|
| 43 | pbar=progressbar.ProgressBar(widgets=[name, " ", progressbar.Percentage(), ' ', |
|---|
| 44 | progressbar.Bar(), ' ', progressbar.ETA()], maxval=numpy.prod(results_dim)) |
|---|
| 45 | for i_exp,experiment in enumerate(p.iter_inner()): |
|---|
| 46 | params = retina.params |
|---|
| 47 | params.update(experiment) # updates what changed in the dictionary |
|---|
| 48 | # simulate the experiment and get its data |
|---|
| 49 | data = retina.run(params,verbose=False) |
|---|
| 50 | # calculating the index in the parameter space |
|---|
| 51 | index = p.parameter_space_index(experiment) |
|---|
| 52 | # put the data at the right position in the results array |
|---|
| 53 | CRF[index] = data['out_ON_DATA'].mean_rate()# |
|---|
| 54 | pbar.update(i_exp) |
|---|
| 55 | |
|---|
| 56 | results['CRF'] = CRF |
|---|
| 57 | |
|---|
| 58 | pbar.finish() |
|---|
| 59 | |
|---|
| 60 | results.close() |
|---|
| 61 | |
|---|
| 62 | from NeuroTools.plotting import pylab_params |
|---|
| 63 | |
|---|
| 64 | """ Figure 1 |
|---|
| 65 | |
|---|
| 66 | 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. |
|---|
| 67 | |
|---|
| 68 | TODO put standard deviation of activity, print CV |
|---|
| 69 | |
|---|
| 70 | """ |
|---|
| 71 | |
|---|
| 72 | import pylab |
|---|
| 73 | |
|---|
| 74 | pylab.figure(num = 1) |
|---|
| 75 | |
|---|
| 76 | pylab.plot(p.noise_std._values,CRF,'go-', label='line 1', linewidth=2) |
|---|
| 77 | pylab.ylabel('Firing Frequency (Hz)') |
|---|
| 78 | pylab.xlabel('Noise amplitude') |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | if 0: |
|---|
| 82 | pylab.show() |
|---|
| 83 | else: |
|---|
| 84 | pylab.savefig('results/fig-' + name + '.pdf') |
|---|
| 85 | pylab.savefig('results/fig-' + name + '.png', dpi = 300) |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | #TODO: make a plot showing that spontaneous activity is a point process with a known histogram |
|---|