| 1 | #!/usr/bin/env python |
|---|
| 2 | # -*- coding: utf8 -*- |
|---|
| 3 | """ |
|---|
| 4 | CRF_neuron_vs_signal.py |
|---|
| 5 | |
|---|
| 6 | Testing the mean firing rate of a fiber for different signal strengths. |
|---|
| 7 | Prints to a figure the mean firing rate for the output (ON and OFF) as a function |
|---|
| 8 | of the different parameter values. It's similar to a CRF function. |
|---|
| 9 | |
|---|
| 10 | Results illustrate that |
|---|
| 11 | - the higher the value the more the neuron spikes (wouah!), |
|---|
| 12 | - that this follows a ramp-type of function |
|---|
| 13 | - and that noise "smoothes" the transition in theinput/output function. |
|---|
| 14 | |
|---|
| 15 | TODO: do a better plot as in benchmark_neuron_vs_noise.py |
|---|
| 16 | |
|---|
| 17 | $Id$ |
|---|
| 18 | """ |
|---|
| 19 | |
|---|
| 20 | import os, sys, numpy, pylab, shelve |
|---|
| 21 | |
|---|
| 22 | from NeuroTools.parameters import * |
|---|
| 23 | |
|---|
| 24 | # this is not mandatory but just a "easy_install progressbar" away |
|---|
| 25 | # else remove all corresponding 3 lines in this code... |
|---|
| 26 | import progressbar # see http://projects.scipy.org/pipermail/scipy-dev/2008-January/008200.html |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | N_exp_snr = 20 |
|---|
| 30 | N_exp_noise = 9 |
|---|
| 31 | |
|---|
| 32 | ps = ParameterSpace({ |
|---|
| 33 | 'snr' : ParameterRange(list(numpy.linspace(-1.,4.,N_exp_snr))), |
|---|
| 34 | 'noise_std' : ParameterRange(list(10.**(numpy.linspace(-.50,1.,N_exp_noise))))}) |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | name = sys.argv[0].split('.')[0] # name of the current script withpout the '.py' part |
|---|
| 38 | results = shelve.open('results/mat-' + name) |
|---|
| 39 | try: |
|---|
| 40 | CRF = results['CRF'] |
|---|
| 41 | except: |
|---|
| 42 | |
|---|
| 43 | # calculates the dimension of the parameter space |
|---|
| 44 | results_dim, results_label = ps.parameter_space_dimension_labels() |
|---|
| 45 | |
|---|
| 46 | # creates results array with size of parameter space dimension |
|---|
| 47 | import simple_single_neuron as model |
|---|
| 48 | myFibers = model.FiberChannel() |
|---|
| 49 | CRF = numpy.empty(results_dim) |
|---|
| 50 | |
|---|
| 51 | pbar=progressbar.ProgressBar(widgets=[name, " ", progressbar.Percentage(), ' ', |
|---|
| 52 | progressbar.Bar(), ' ', progressbar.ETA()], maxval=numpy.prod(results_dim)) |
|---|
| 53 | for i_exp,experiment in enumerate(ps.iter_inner()): |
|---|
| 54 | params = myFibers.params |
|---|
| 55 | params.update(experiment) # updates what changed in the dictionary |
|---|
| 56 | # simulate the experiment and get its data |
|---|
| 57 | data = myFibers.run(params,verbose=False) |
|---|
| 58 | # calculating the index in the parameter space |
|---|
| 59 | index = ps.parameter_space_index(experiment) |
|---|
| 60 | # put the data at the right position in the results array |
|---|
| 61 | CRF[index] = data.mean_rate()# |
|---|
| 62 | pbar.update(i_exp) |
|---|
| 63 | |
|---|
| 64 | results['CRF'] = CRF |
|---|
| 65 | pbar.finish() |
|---|
| 66 | |
|---|
| 67 | results.close() |
|---|
| 68 | |
|---|
| 69 | #numpy.array(p.noise_std._values),numpy.array(p.snr._values), |
|---|
| 70 | #pylab.plot(ps.snr._values,CRF.transpose()) #color = (sin(2*pi*noise_list)**2,cos(2*pi*noise_list)**2,1)) |
|---|
| 71 | for i_noise, noise in enumerate(ps.noise_std._values): |
|---|
| 72 | pylab.plot(ps.snr._values,CRF[i_noise,:], label='noise = %5.3f' % noise) |
|---|
| 73 | #pylab.yticks(p.noise_std._values[:2:]) |
|---|
| 74 | pylab.ylabel('Firing Rate (Hz/neuron)') |
|---|
| 75 | #pylab.xticks(p.snr._values[:2:]) |
|---|
| 76 | pylab.xlabel('Signal') |
|---|
| 77 | pylab.legend(loc = 'lower right') |
|---|
| 78 | pylab.axis([numpy.min(ps.snr._values), numpy.max(ps.snr._values), 0.0, numpy.max(CRF[:])]) |
|---|
| 79 | if 0: |
|---|
| 80 | pylab.show() |
|---|
| 81 | else: |
|---|
| 82 | pylab.savefig('results/fig-' + name + '.pdf') |
|---|
| 83 | pylab.savefig('results/fig-' + name + '.png') |
|---|