| 1 | #!/usr/bin/env python |
|---|
| 2 | # -*- coding: utf8 -*- |
|---|
| 3 | """ |
|---|
| 4 | benchmark_linear.py |
|---|
| 5 | ========================= |
|---|
| 6 | |
|---|
| 7 | Having fixed the background noise we are just studying now how different |
|---|
| 8 | signal to noise ratios are integrated by the neurons. |
|---|
| 9 | |
|---|
| 10 | Laurent Perrinet, INCM, CNRS |
|---|
| 11 | |
|---|
| 12 | $ Id $ |
|---|
| 13 | |
|---|
| 14 | """ |
|---|
| 15 | |
|---|
| 16 | import os, sys, numpy, pylab, shelve |
|---|
| 17 | |
|---|
| 18 | N, N_exp = 1000, 6 |
|---|
| 19 | t_smooth = 100. # width (in ms) of the integration window |
|---|
| 20 | from NeuroTools.parameters import ParameterSpace, ParameterRange |
|---|
| 21 | snr = 2.0 * numpy.linspace(0.1,2.0,N_exp) |
|---|
| 22 | p = ParameterSpace({'snr' : ParameterRange(list(snr))}) |
|---|
| 23 | |
|---|
| 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 | |
|---|
| 29 | temporal_ON = results['temporal_ON'] |
|---|
| 30 | temporal_OFF = results['temporal_OFF'] |
|---|
| 31 | lower_edges = results['lower_edges'] |
|---|
| 32 | params = results['params'] |
|---|
| 33 | #if (params == retina.params): raise('Parameters have changed') |
|---|
| 34 | |
|---|
| 35 | except: |
|---|
| 36 | from retina import * |
|---|
| 37 | retina = Retina(N) |
|---|
| 38 | retina.params['amplitude'] = numpy.ones(retina.params['amplitude'].shape) |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | # calculates the dimension of the parameter space |
|---|
| 42 | results_dim, results_label = p.parameter_space_dimension_labels() |
|---|
| 43 | |
|---|
| 44 | # creates results array with size of parameter space dimension |
|---|
| 45 | data = retina.run(retina.params,verbose=False) |
|---|
| 46 | lower_edges = data['out_ON_DATA'].time_axis(t_smooth) |
|---|
| 47 | N_smooth = len(lower_edges) |
|---|
| 48 | |
|---|
| 49 | temporal_ON, temporal_OFF = [],[] |
|---|
| 50 | import progressbar # see http://projects.scipy.org/pipermail/scipy-dev/2008-January/008200.html |
|---|
| 51 | pbar=progressbar.ProgressBar(widgets=[name, " ", progressbar.Percentage(), ' ', |
|---|
| 52 | progressbar.Bar(), ' ', progressbar.ETA()], maxval=N_exp) |
|---|
| 53 | for i_exp,experiment in enumerate(p.iter_inner()): |
|---|
| 54 | params = retina.params |
|---|
| 55 | params.update(experiment) # updates what changed in the dictionary |
|---|
| 56 | # simulate the experiment and get its data |
|---|
| 57 | data = retina.run(params,verbose=False) |
|---|
| 58 | # calculating the index in the parameter space |
|---|
| 59 | index = p.parameter_space_index(experiment) |
|---|
| 60 | # put the data at the right position in the results array |
|---|
| 61 | temporal_ON.append(sum(data['out_ON_DATA'].firing_rate(t_smooth))/N)# |
|---|
| 62 | temporal_OFF.append(sum(data['out_OFF_DATA'].firing_rate(t_smooth))/N)# |
|---|
| 63 | pbar.update(i_exp) |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | results['lower_edges'] = lower_edges |
|---|
| 67 | results['temporal_ON'] = temporal_ON |
|---|
| 68 | results['temporal_OFF'] = temporal_OFF |
|---|
| 69 | results['params'] = retina.params |
|---|
| 70 | |
|---|
| 71 | pbar.finish() |
|---|
| 72 | |
|---|
| 73 | results.close() |
|---|
| 74 | |
|---|
| 75 | ############################################################################### |
|---|
| 76 | |
|---|
| 77 | from NeuroTools.plotting import pylab_params |
|---|
| 78 | |
|---|
| 79 | """ Figure 1 |
|---|
| 80 | |
|---|
| 81 | Prints to a figure the mean firing rate for the output (ON and OFF) as a function |
|---|
| 82 | of the different parameter values. It's similar to a CRF function. |
|---|
| 83 | |
|---|
| 84 | """ |
|---|
| 85 | #pylab.close('all') |
|---|
| 86 | #pylab.rcParams.update(pylab_params(fig_width_pt = 497.9/2., ratio = 1.)) |
|---|
| 87 | pylab.figure(1) |
|---|
| 88 | #fmax = numpy.max([numpy.max(temporal_OFF[:]),numpy.max(temporal_ON[:])]) |
|---|
| 89 | |
|---|
| 90 | pylab.subplot(211) |
|---|
| 91 | for i_exp in range(N_exp): |
|---|
| 92 | pylab.plot(lower_edges[:-1] + t_smooth/2, temporal_ON[i_exp], |
|---|
| 93 | label= '%5.2f' % p.snr._values[i_exp]) |
|---|
| 94 | pylab.xticks( numpy.round(numpy.linspace(0, params.simtime, 5),0) ) |
|---|
| 95 | pylab.ylabel('ON Firing frequency (Hz)') |
|---|
| 96 | pylab.axis([0, params.simtime, 0.0, numpy.max(temporal_ON[:])]) |
|---|
| 97 | pylab.legend(loc='upper right') |
|---|
| 98 | pylab.subplot(212) |
|---|
| 99 | for i_exp in range(N_exp): |
|---|
| 100 | pylab.plot(lower_edges[:-1] + t_smooth/2, temporal_OFF[i_exp]) |
|---|
| 101 | pylab.xticks( numpy.round(numpy.linspace(0, params.simtime, 5),0) ) |
|---|
| 102 | pylab.ylabel('OFF Firing frequency (Hz)') |
|---|
| 103 | pylab.xlabel('time (ms)') |
|---|
| 104 | pylab.axis([0, params.simtime, 0.0, numpy.max(temporal_OFF[:]) ]) |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | if 0: |
|---|
| 108 | pylab.ion() |
|---|
| 109 | #pylab.show() |
|---|
| 110 | else: |
|---|
| 111 | pylab.savefig('results/fig-' + name + '.pdf') |
|---|
| 112 | pylab.savefig('results/fig-' + name + '.png', dpi = 300) |
|---|
| 113 | |
|---|