Changeset 340
- Timestamp:
- 11/14/08 19:17:05 (2 months ago)
- Files:
-
- trunk/examples/retina/benchmark_linear.py (modified) (4 diffs)
- trunk/examples/retina/benchmark_noise.py (modified) (3 diffs)
- trunk/examples/retina/benchmark_retina.py (modified) (7 diffs)
- trunk/examples/retina/results/fig-benchmark_linear.png (modified) (previous)
- trunk/examples/retina/results/fig-benchmark_retina.png (modified) (previous)
- trunk/examples/retina/retina.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/examples/retina/benchmark_linear.py
r333 r340 16 16 import os, sys, numpy, pylab, shelve 17 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 18 24 19 25 name = sys.argv[0].split('.')[0] # name of the current script withpout the '.py' part … … 28 34 29 35 except: 30 N, N_exp = 1000, 631 t_smooth = 100. # width (in ms) of the integration window32 36 from retina import * 33 37 retina = Retina(N) 34 38 retina.params['amplitude'] = numpy.ones(retina.params['amplitude'].shape) 35 snr = retina.params['snr']* numpy.linspace(0.1,2.0,N_exp) 36 from NeuroTools.parameters import ParameterSpace 37 p = ParameterSpace({'snr' : ParameterRange(list(snr))}) 39 38 40 39 41 # calculates the dimension of the parameter space … … 65 67 results['temporal_ON'] = temporal_ON 66 68 results['temporal_OFF'] = temporal_OFF 67 results['params'] = params69 results['params'] = retina.params 68 70 69 71 pbar.finish() … … 84 86 #pylab.rcParams.update(pylab_params(fig_width_pt = 497.9/2., ratio = 1.)) 85 87 pylab.figure(1) 86 fmax = numpy.max([numpy.max(temporal_OFF[:]),numpy.max(temporal_ON[:])])88 #fmax = numpy.max([numpy.max(temporal_OFF[:]),numpy.max(temporal_ON[:])]) 87 89 88 90 pylab.subplot(211) 89 91 for i_exp in range(N_exp): 90 pylab.plot(lower_edges[:-1] + t_smooth/2, # TODO add a half bin 91 temporal_ON[i_exp])# 92 pylab.xticks( numpy.round(numpy.linspace(0, retina.params.simtime, 5),0) ) 93 pylab.ylabel('ON Firing frequency (Hz/neuron)') 94 pylab.axis([0, retina.params.simtime, 0.0, fmax]) 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') 95 98 pylab.subplot(212) 96 99 for i_exp in range(N_exp): 97 pylab.plot(lower_edges[:-1] + t_smooth/2, # TODO add a half bin 98 temporal_OFF[i_exp], 99 label= 'snr= %5.3f' % p.snr._values[i_exp] ) 100 pylab.xticks( numpy.round(numpy.linspace(0, retina.params.simtime, 5),0) ) 101 pylab.ylabel('OFF Firing frequency (Hz/neuron)') 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)') 102 103 pylab.xlabel('time (ms)') 103 pylab.axis([0, retina.params.simtime, 0.0, fmax ]) 104 105 pylab.legend(loc='upper right') 104 pylab.axis([0, params.simtime, 0.0, numpy.max(temporal_OFF[:]) ]) 106 105 107 106 trunk/examples/retina/benchmark_noise.py
r333 r340 19 19 import os, sys, numpy, shelve 20 20 21 retina.params['snr'] = 0 # no input 22 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))))}) 23 24 24 25 name = sys.argv[0].split('.')[0] # name of the current script withpout the '.py' part … … 27 28 CRF = results['CRF'] 28 29 except: 29 30 from NeuroTools.parameters import *31 32 30 # this is not mandatory but just a "easy_install progressbar" away 33 31 # else remove all corresponding lines in this code... 34 32 import progressbar # see http://projects.scipy.org/pipermail/scipy-dev/2008-January/008200.html 35 36 N, N_exp_noise = 1000, 2237 38 p = ParameterSpace({'noise_std' : ParameterRange(list(10.**(numpy.linspace(-.50,1.,N_exp_noise))))})39 40 33 import retina as model 41 34 retina = model.Retina(N) 35 retina.params['snr'] = 0 # no input 36 42 37 # calculates the dimension of the parameter space 43 38 results_dim, results_label = p.parameter_space_dimension_labels() … … 75 70 """ 76 71 77 N, simtime = retina.params['N'], retina.params['simtime']78 79 72 import pylab 80 73 trunk/examples/retina/benchmark_retina.py
r333 r340 25 25 import os, sys, numpy, pylab, shelve, progressbar 26 26 27 N, N_snr, N_seeds = 1000, 5, 10 28 from NeuroTools.parameters import * 29 p = ParameterSpace({ 30 'snr' : ParameterRange(list(numpy.linspace(0.1,2.0,N_snr))), 31 'kernelseed' : ParameterRange(list([12345 + k for k in range(N_seeds)]))}) 27 32 28 33 name = sys.argv[0].split('.')[0] # name of the current script withpout the '.py' part 29 ############## MAKING THE SIMULATIONS ############### 30 results = shelve.open('results/mat-' + name) 34 31 35 try: 32 DATA = results['DATA'] 33 except: 36 ############## MAKING THE SIMULATIONS ############### 37 results = shelve.open('results/mat-' + name) 38 try: 39 DATA = results['DATA'] 40 params = results['params'] 41 except: 42 from retina import * 43 retina = Retina(N) 44 # calculates the dimension of the parameter space 45 results_dim, results_label = p.parameter_space_dimension_labels() 34 46 35 from NeuroTools.parameters import * 47 DATA = [] 48 pbar=progressbar.ProgressBar(widgets=[name, " ", progressbar.Percentage(), ' ', 49 progressbar.Bar(), ' ', progressbar.ETA()], maxval=N_snr*N_seeds) 50 for i_exp, experiment in enumerate(p.iter_inner()): 51 params = retina.params 52 params.update(experiment) # updates what changed in the dictionary 53 # simulate the experiment and get its data 54 data = retina.run(params)#,verbose=False) 55 # store it 56 DATA.append(data)# 57 pbar.update(i_exp) 36 58 37 N, N_snr, N_seeds = 1000, 5, 10 38 from retina import * 39 retina = Retina(N) 59 results['DATA'] = DATA 60 results['params'] = retina.params 40 61 41 t_smooth = 100. # ms. integration time to show fiber activity 42 43 p = ParameterSpace({ 44 'snr' : ParameterRange(list(numpy.linspace(0.1,2.0,N_snr))), 45 'kernelseed' : ParameterRange(list([retina.params['kernelseed'] + k for k in range(N_seeds)]))}) 46 47 # calculates the dimension of the parameter space 48 results_dim, results_label = p.parameter_space_dimension_labels() 49 50 DATA = [] 51 52 pbar=progressbar.ProgressBar(widgets=[name, " ", progressbar.Percentage(), ' ', 53 progressbar.Bar(), ' ', progressbar.ETA()], maxval=N_snr*N_seeds) 54 for i_exp, experiment in enumerate(p.iter_inner()): 55 params = retina.params 56 params.update(experiment) # updates what changed in the dictionary 57 # simulate the experiment and get its data 58 data = retina.run(params)#,verbose=False) 59 # store it 60 DATA.append(data)# 61 pbar.update(i_exp) 62 63 results['DATA'] = DATA 64 65 pbar.finish() 66 67 ############## PRE-PROCESSING ########################### 68 try: 62 pbar.finish() 63 results.close() 64 results = shelve.open('results/mat-pre-' + name) 65 ############## PRE-PROCESSING ########################### 69 66 #boing # uncomment to force recomputing the pre-processing stage 70 67 lower_edges = results['lower_edges'] … … 73 70 temporal_OFF = results['temporal_OFF'] 74 71 map_spatial_ON = results['map_spatial_ON'] 72 lower_edges = results['lower_edges'] 73 results.close() 75 74 76 75 except: 77 76 def temporal_mean(spike_list): 77 return numpy.sum(spike_list.firing_rate(t_smooth),axis=0) 78 79 t_smooth = 100. # ms. integration time to show fiber activity 78 80 lower_edges = DATA[0]['out_ON_DATA'].time_axis(t_smooth) 79 N_smooth = len(lower_edges) 80 params = retina.params 81 N_smooth = len(lower_edges)-1 81 82 82 83 #N_snr = len(p.snr) … … 86 87 # 87 88 N_ret, simtime = params['N_ret'], params['simtime'] 88 #89 89 x = params['position'][0] 90 90 y = params['position'][1] … … 92 92 r = numpy.sqrt(r2) 93 93 id_center = [int(k) for k in numpy.where( r2 < N_ret**2)[0]] 94 95 94 # mean activity accross kernelseeds as a function of SNR 96 95 for i_exp, experiment in enumerate(p.iter_inner()): … … 98 97 index = p.parameter_space_index(experiment) 99 98 # getting SpikeLists corresponding to the interesting parts (within the center) 100 temporal_ON[:,index[1]] += sum(DATA[i_exp]['out_ON_DATA'][id_center].firing_rate(t_smooth))/N_seeds101 temporal_OFF[:,index[1]] += sum(DATA[i_exp]['out_OFF_DATA'][id_center].firing_rate(t_smooth))/N_seeds102 map_spatial_ON[:,index[1]] += DATA[i_exp]['out_ON_DATA'].mean_rates(t_start=simtime/4.,t_stop=3*simtime/4.) /N_seeds103 map_spatial_OFF[:,index[1]] += DATA[i_exp]['out_OFF_DATA'].mean_rates(t_start=simtime/4.,t_stop=3*simtime/4.) /N_seeds99 temporal_ON[:,index[1]] += temporal_mean(DATA[i_exp]['out_ON_DATA'].id_slice(id_center))/N_seeds 100 temporal_OFF[:,index[1]] += temporal_mean(DATA[i_exp]['out_ON_DATA'].id_slice(id_center))/N_seeds 101 map_spatial_ON[:,index[1]] += DATA[i_exp]['out_ON_DATA'].mean_rates(t_start=simtime/4.,t_stop=3*simtime/4.)#/N_seeds 102 map_spatial_OFF[:,index[1]] += DATA[i_exp]['out_OFF_DATA'].mean_rates(t_start=simtime/4.,t_stop=3*simtime/4.)#/N_seeds 104 103 104 results = shelve.open('results/mat-pre-' + name) 105 105 results['temporal_ON'] = temporal_ON 106 106 results['map_spatial_OFF'] = map_spatial_OFF 107 107 results['temporal_OFF'] = temporal_OFF 108 108 results['map_spatial_ON'] = map_spatial_ON 109 results['lower_edges'] = lower_edges 110 results.close() 109 111 110 112 results.close() … … 133 135 #pylab.axes([Lmargin, dmargin , 1.0 - Rmargin- Lmargin,1.0-umargin-dmargin]) # [left, bottom, width, height] 134 136 pylab.subplot(131) 135 pylab.scatter(x,y,c=params['amplitude'], faceted=False)137 pylab.scatter(x,y,c=params['amplitude'], edgecolors='none') 136 138 137 139 pylab.subplot(232) 138 pylab.plot(lower_edges ,temporal_ON)140 pylab.plot(lower_edges[:-1],temporal_ON) 139 141 pylab.title('time course (ROI) ',fontsize = 'small') 140 142 #pylab.title('time course ON',fontsize = 'small') 141 pylab.xticks( numpy.linspace(0, simtime, 5) )143 pylab.xticks( numpy.linspace(0, params.simtime, 5) ) 142 144 pylab.ylabel('ON activity (spike / s / neuron)') 143 145 #pylab.axis('tight') 144 146 pylab.subplot(235) 145 pylab.plot(lower_edges ,temporal_OFF)147 pylab.plot(lower_edges[:-1],temporal_OFF) 146 148 #pylab.title('time course OFF',fontsize = 'small') 147 pylab.xticks( numpy.linspace(0, simtime, 5) )149 pylab.xticks( numpy.linspace(0, params.simtime, 5) ) 148 150 pylab.ylabel('OFF activity (spike / s / neuron)') 149 151 #pylab.axis('tight') 150 152 pylab.xlabel('time (ms)') 151 153 pylab.subplot(233) 152 pylab.scatter(x, y, c= map_spatial_ON[:,-1], faceted=False)154 pylab.scatter(x, y, c= map_spatial_ON[:,-1], edgecolors='none') 153 155 #pylab.title('spatial distribution ON',fontsize ='small') 154 156 #pylab.title('spatial distribution',fontsize ='small') 155 157 pylab.subplot(236) 156 pylab.scatter(x, y, c= map_spatial_OFF[:,-1], faceted=False)158 pylab.scatter(x, y, c= map_spatial_OFF[:,-1], edgecolors='none') 157 159 #pylab.title('spatial distribution OFF',fontsize ='small') 158 160 #pylab.xlabel('distance from center') … … 161 163 162 164 163 pylab.savefig('results/fig-' + name + '.pdf') 164 pylab.savefig('results/fig-' + name + '.png', dpi = 300) 165 if 1: 166 pylab.ion() 167 pylab.show() 168 else: 169 pylab.savefig('results/fig-' + name + '.pdf') 170 pylab.savefig('results/fig-' + name + '.png', dpi = 300) 171 172 trunk/examples/retina/retina.py
r326 r340 117 117 params = {'description' : 'default retina', 118 118 'N': N, # integer; square of total number of Ganglion Cells LUP: how do we include types and units in parameters? (or by default it is a float in ISO standards) TODO: go rectangular 119 'N_ret': .2, # float; diameter of Ganglion Cell's RF 119 'N_ret': .2, # float; diameter of Ganglion Cell's RF (max: 1) 120 120 'K_ret': 4.0, # float; ratio of center vs. surround in DOG 121 121 'dt' : 0.1,# discretization step in simulations (ms)

