root/trunk/examples/single_neuron/CRF_neuron_vs_signal.py

Revision 362, 2.9 KB (checked in by LaurentPerrinet, 3 years ago)

Small fixes on example/single _neuron and sfn2008 / corrected ylabel in isi plot

  • Property svn:keywords set to Id
Line 
1#!/usr/bin/env python
2# -*- coding: utf8 -*-
3"""
4CRF_neuron_vs_signal.py
5
6Testing the mean firing rate of a fiber for different signal strengths.
7Prints to a figure the mean firing rate for the output (ON and OFF) as a function
8of the different parameter values. It's similar to a CRF function.
9
10Results 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
15TODO: do a better plot as in benchmark_neuron_vs_noise.py
16
17$Id$
18"""
19
20import os, sys, numpy, pylab, shelve
21
22from 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...
26import progressbar # see http://projects.scipy.org/pipermail/scipy-dev/2008-January/008200.html
27
28
29N_exp_snr = 20
30N_exp_noise = 9
31
32ps =  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
37name = sys.argv[0].split('.')[0] # name of the current script withpout the '.py' part
38results = shelve.open('results/mat-' + name)
39try:
40    CRF = results['CRF']
41except:
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
67results.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))
71for 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:])
74pylab.ylabel('Firing Rate (Hz/neuron)')
75#pylab.xticks(p.snr._values[:2:])
76pylab.xlabel('Signal')
77pylab.legend(loc = 'lower right')
78pylab.axis([numpy.min(ps.snr._values), numpy.max(ps.snr._values), 0.0, numpy.max(CRF[:])])
79if 0:
80    pylab.show()
81else:
82    pylab.savefig('results/fig-' + name + '.pdf')
83    pylab.savefig('results/fig-' + name + '.png')
Note: See TracBrowser for help on using the browser.