Changeset 101
- Timestamp:
- 01/15/08 17:44:22 (1 year ago)
- Files:
-
- trunk/benchmark.py (modified) (2 diffs)
- trunk/examples/retina/benchmark_linear.py (modified) (5 diffs)
- trunk/examples/retina/benchmark_noise.py (modified) (4 diffs)
- trunk/examples/retina/benchmark_retina.py (modified) (7 diffs)
- trunk/examples/retina/make_all.py (modified) (4 diffs)
- trunk/examples/retina/retina.py (modified) (6 diffs)
- trunk/spikes.py (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/benchmark.py
r94 r101 203 203 return unfinished_experiments 204 204 205 def reset_all(self ):205 def reset_all(self, type='full'): 206 206 """ Removes all experiments files 207 207 208 """ 209 210 for experiment in self.experiments: 211 os.remove(self.experiment_filename(experiment)) 208 type gives the type of cleaning to do 209 may be 'full', 'exp' or 'corrupted' (non finished) 210 """ 211 if type == 'exp': 212 os.remove(self.experiment_filename()) 213 for experiment in self.experiments: 214 os.remove(self.experiment_filename(experiment)) 215 elif type == 'full': 216 for experiment in self.experiments: 217 os.remove(self.experiment_filename(experiment)) 218 os.remove(self.experiment_filename()) 219 #os.remove(self.filename) 212 220 213 221 … … 230 238 params = self.get('params') 231 239 print "Running Experiment " + experiment + " ..." 240 print 'Changing :', self.get('experiments')[experiment] 232 241 # updates params with the changed parameers from experiment 233 242 params.update(self.get('experiments')[experiment]) # change some parameters trunk/examples/retina/benchmark_linear.py
r97 r101 17 17 import retina as model 18 18 import NeuroTools.benchmark as benchmark 19 20 21 19 22 20 … … 43 41 44 42 N, N_ret, simtime = params['N'], params['N_ret'], params['simtime'] 45 N_smooth = 100 # how many time bins43 t_smooth = 100. # smooting time (ms) 46 44 47 45 for experiment in experiment_list: … … 50 48 except: 51 49 print "Loading data for experiment " , experiment 52 out_ON_DATA = benchmark.get('out',experiment)['out_ON_DATA'] 53 # ON 54 temporal_ON , lower_edges = numpy.histogram(out_ON_DATA.as_list_id_list_time()[1], 55 bins=N_smooth, range=(out_ON_DATA.t_start,out_ON_DATA.t_stop)) 56 temporal_ON /= N**2 57 # OFF : noit very useful here 58 #out_OFF_DATA = benchmark.get('out',experiment)['out_OFF_DATA'] 59 ## temporal_OFF , lower_edges = numpy.histogram(out_OFF_DATA.as_list_id_list_time()[1], 60 ## bins=N_smooth, range=(out_ON_DATA.t_start,out_ON_DATA.t_stop)) 61 ## temporal_OFF /= N**2 50 out_ON = benchmark.get('out',experiment)['out_ON_DATA'] 51 62 52 # storing 63 53 benchmark.put('firing_rate',{ 64 'temporal_ON' : temporal_ON,65 ## 'temporal_OFF' : temporal_OFF,66 'lower_edges' : lower_edges,54 'temporal_ON' : sum(out_ON.firing_rate(t_smooth))/N, 55 #'temporal_OFF' : out_OFF.firing_rate(t_smooth), 56 'lower_edges' : out_ON.time_axis(t_smooth), 67 57 'firing_rate_ok' : True # a flag to do it once 68 58 }, experiment ) … … 89 79 #pylab.legend() 90 80 91 pylab.savefig(benchmark.filename + '/benchmark_linear.p ng') #, dpi=300) #81 pylab.savefig(benchmark.filename + '/benchmark_linear.pdf') #, dpi=300) # 92 82 93 83 94 84 if __name__ == '__main__': 95 85 96 # not working tag= '07-02-16'97 # tag= '07-02-14'98 # tag= '07-02-23'99 tag= '07-02-27'100 tag = '07-03-08'101 tag = '07-05-09'102 86 tag = 'test' 103 87 … … 106 90 107 91 ret = model.Retina(21) 108 ret.params['simtime'] = 4000*0.1 109 ret.params['amplitude'] = numpy.ones((ret.params['N'],ret.params['N'] )) 110 111 run = benchmark.get_experiment_dict({'snr' : 10.**(numpy.linspace(-.50,.75,5))}) 112 92 #ret.params['simtime'] = 4000*0.1 93 ret.params['amplitude'] = numpy.ones(ret.params['N']) 94 N_exp = 15 95 snr = ret.params['snr']* numpy.linspace(0.1,2.0,N_exp) 96 run = benchmark.get_experiment_dict({'snr':snr}) 97 print snr#,ret.params 113 98 B = benchmark.Benchmark(filename,ret,run) 114 99 115 100 B.run_simulations() 116 101 show(B) 117 102 #B.reset_all() trunk/examples/retina/benchmark_noise.py
r97 r101 35 35 noise_std, CRF = numpy.zeros(len(experiments)), numpy.zeros(len(experiments)) 36 36 for count, experiment in enumerate(experiments): 37 out_ON_DATA = benchmark.get('out',experiment)['out_ON_DATA'] #.as_list_id_list_time()37 out_ON_DATA = benchmark.get('out',experiment)['out_ON_DATA'] 38 38 noise_std[count] = benchmark.get('experiments')[experiment]['noise_std'] 39 CRF[count] = out_ON_DATA.mean_rate() #[0]) / N / N / simtime * 1000.039 CRF[count] = out_ON_DATA.mean_rate() 40 40 41 41 … … 48 48 #pylab.axes([Lmargin, dmargin , 1.0 - Rmargin- Lmargin,1.0-umargin-dmargin]) # [left, bottom, width, height] 49 49 50 #pylab.subplot(111)51 50 idx_ = numpy.argsort(noise_std) # extract lines 52 51 pylab.plot(noise_std[idx_],CRF[idx_],'go-', label='line 1', linewidth=2) … … 65 64 # create a Retina Model object that contains a method to init, to run, ... 66 65 ret = model.Retina(10) 67 ret.params['simtime'] = 4000*0.168 66 69 tag = '07-02-21' 70 tag = '07-03-08' # worked fine for D25 71 tag = '07-04-12' 72 tag = '07-04-08' # new with multiple seeds for CNS07 73 tag = '07-05-14' # no 74 tag = '07-05-16' # going OO 75 tag = 'test' # going OO 67 tag = 'test' 76 68 77 69 name = 'results/' + tag + '_benchmark_noise' 78 70 79 71 # create the list of experiments as all possibilities accross parameter vectors 80 run = benchmark.get_experiment_dict({'noise_std':numpy.linspace(.10,10.0,20), 'snr' : [ 0.0 ]}) 72 span, N_exp = 5, 2*7+1 73 #range = 10.**(numpy.linspace(-span,span,N_exp)) 74 range = numpy.linspace(1/span,span,N_exp) 75 run = benchmark.get_experiment_dict({'noise_std': ret.params['noise_std']* range, 'snr' : [ 0.0 ]}) 81 76 82 77 # create benchmark (or open it if it exists) … … 86 81 87 82 show(B) 88 83 #B.reset_all() # erase experimental data trunk/examples/retina/benchmark_retina.py
r97 r101 27 27 def show(benchmark): 28 28 from NeuroTools.plotting import pylab_params 29 from numpy import zeros, where, arange 29 30 30 31 … … 32 33 33 34 N, N_ret, simtime, dt = params['N'], params['N_ret'], params['simtime'], params['dt'] 34 N_smooth = 100 # how many time bins 35 # TODO : print N_smooth 36 space , t = numpy.linspace(-N/2, N/2, N), numpy.arange(0,simtime,dt * N_smooth) 37 amplitude = params['amplitude'] 38 39 x = params['position'][0][out_DATA[0]] 40 y = params['position'][1][out_DATA[0]] 35 t_smooth = 100. # smooting time (ms) 36 t = arange(0.0, simtime, t_smooth) 37 N_smooth = len(t) 38 39 x = params['position'][0] 40 y = params['position'][1] 41 41 r2 = x**2 + y**2 42 42 r = numpy.sqrt(r2) 43 id_center = where( r2 < N_ret**2) 44 #print r2,id_center 43 45 #kernel = amplitude * (amplitude > 0) 44 46 #kernel /= numpy.sum(numpy.sum(kernel)) … … 52 54 out_ON = benchmark.get('out',experiment)['out_ON_DATA'] 53 55 out_OFF = benchmark.get('out',experiment)['out_OFF_DATA'] 54 out_ON_DATA = out_ON.firing_rate(t_smooth)55 out_OFF_DATA = out_OFF.firing_rate(t_smooth)56 57 ##temporal_ON= numpy.sum(numpy.sum(out_ON_spikematrix, axis=0), axis=0)58 temporal_ON , lower_edges = numpy.histogram(out_ON_DATA[1],59 bins=N_smooth, range=(out_ON.t_start,out_ON.t_stop))60 ##temporal_OFF= numpy.sum(numpy.sum(out_OFF_spikematrix, axis=0), axis=0)61 temporal_OFF , lower_edges = numpy.histogram(out_OFF_DATA[1],62 bins=N_smooth, range=(out_ON.t_start,out_ON.t_stop))63 64 65 # TODO the range argument may serve to select a time window66 map_spatial_ON , dump = numpy.histogram(out_ON_DATA[0],bins=N**2, range=(0,N**2))67 map_spatial_OFF, dump = numpy.histogram(out_OFF_DATA[0],bins=N**2, range=(0,N**2))68 56 69 57 benchmark.put('firing_rate',{ 70 'temporal_ON' : temporal_ON,71 'temporal_OFF' : temporal_OFF,72 'lower_edges' : lower_edges,73 'map_spatial_ON' : numpy.reshape(map_spatial_ON,(N,N)),74 'map_spatial_OFF' : numpy.reshape(map_spatial_OFF,(N,N))75 }, experiment )58 'temporal_ON' : sum(out_ON.firing_rate(t_smooth))/N, 59 'temporal_OFF' : sum(out_OFF.firing_rate(t_smooth))/N, 60 'lower_edges' : out_OFF.time_axis(t_smooth), 61 'map_spatial_ON' : out_ON.mean_rates(t_start=simtime/4.,t_stop=3*simtime/4.), 62 'map_spatial_OFF' : out_OFF.mean_rates(t_start=simtime/4.,t_stop=3*simtime/4.) 63 }, experiment ) 76 64 77 65 pylab.close('all') … … 91 79 # mean activity accross kernelseeds as a function of SNR 92 80 snr_list = benchmark.list_param('snr') 93 94 81 for snr in snr_list: 95 temporal_ON, temporal_OFF, map_spatial_ON, map_spatial_OFF = 0, 0, 0, 082 temporal_ON, temporal_OFF, map_spatial_ON, map_spatial_OFF =zeros(N_smooth), zeros(N_smooth), zeros(N), zeros(N) 96 83 seeds_list = benchmark.list_where('snr',snr) 84 n_seeds = len(seeds_list) 97 85 for experiment in seeds_list: # TODO sum on dictionaries? 98 86 run = benchmark.get('firing_rate',experiment) 99 temporal_ON += run['temporal_ON'] / len(seeds_list) 100 temporal_OFF += run['temporal_OFF']/ len(seeds_list) 101 map_spatial_ON += run['map_spatial_ON']/ len(seeds_list) 102 map_spatial_OFF += run['map_spatial_OFF']/ len(seeds_list) 103 104 t = run['lower_edges'] 87 temporal_ON += run['temporal_ON'] 88 temporal_OFF += run['temporal_OFF'] 89 map_spatial_ON += run['map_spatial_ON'] 90 map_spatial_OFF += run['map_spatial_OFF'] 91 105 92 pylab.subplot(221) 106 pylab.plot(t,temporal_ON )93 pylab.plot(t,temporal_ON/ n_seeds) 107 94 pylab.subplot(223) 108 pylab.plot(t,temporal_OFF )95 pylab.plot(t,temporal_OFF/ n_seeds) 109 96 pylab.subplot(222) 110 pylab.plot( space , numpy.sum(map_spatial_ON[N/2-N_ret/2:N/2+N_ret/2,:], axis=0) * N / N_ret)97 pylab.plot(r , map_spatial_ON ,'bo' ) 111 98 pylab.subplot(224) 112 pylab.plot( space , numpy.sum(map_spatial_OFF[N/2-N_ret/2:N/2+N_ret/2,:], axis=0) * N / N_ret)99 pylab.plot(r , map_spatial_OFF , 'ro' ) 113 100 114 101 pylab.subplot(221) … … 131 118 pylab.subplot(224) 132 119 #pylab.title('spatial distribution OFF',fontsize ='small') 133 pylab.xlabel(' space')120 pylab.xlabel('distance from center') 134 121 135 122 pylab.savefig(name) # … … 176 163 pylab.figure(num = 3, dpi=dpi, facecolor='w', edgecolor='k') 177 164 178 Lmargin, Rmargin, dmargin, umargin = 0.05, 0.15, 0.05, 0.05179 pylab.axes([Lmargin, dmargin , 1.0 - Rmargin- Lmargin,1.0-umargin-dmargin]) # [left, bottom, width, height]180 181 pylab. matshow(benchmark.get('params')['amplitude'])182 183 pylab.axis('off')184 pylab.colorbar(shrink = 0.7)165 #Lmargin, Rmargin, dmargin, umargin = 0.05, 0.15, 0.05, 0.05 166 #pylab.axes([Lmargin, dmargin , 1.0 - Rmargin- Lmargin,1.0-umargin-dmargin]) # [left, bottom, width, height] 167 168 pylab.scatter(x,y,c=benchmark.get('params')['amplitude'],faceted=False) 169 170 #pylab.axis('off') 171 #pylab.colorbar(shrink = 0.7) 185 172 pylab.savefig(name) 186 173 … … 201 188 # create a Retina Model object that contains a method to init, to run, ... 202 189 ret = model.Retina(10) 203 ret.params['simtime'] = 4000*0.1 204 #retina_default(url) 205 #params=retina_debug() 190 #ret.params['simtime'] = 4000*0.1 206 191 ret.params['description']= 'Testing Benchmark Retina with ' + ret.params['description'], 207 192 208 193 # create the list of experiments as all possibilities accross parameter vectors 209 194 N_exp_snr, N_exp_seeds = 5 , 4 210 snr = ret.params['snr'] * 10.**(numpy.linspace(-.50,.75,N_exp_snr))195 snr = ret.params['snr'] * numpy.linspace(0.1,2.0,N_exp_snr) 211 196 seeds = [43210987 + k for k in range(N_exp_seeds)] 212 197 run = benchmark.get_experiment_dict({'snr':snr,'kernelseed':seeds}) trunk/examples/retina/make_all.py
r97 r101 5 5 =========== 6 6 7 Launches all benchmarks in B 0.7 Launches all benchmarks in B1. 8 8 9 9 Laurent Perrinet, INCM, CNRS … … 18 18 19 19 # tag list 20 tag = '07-02-21'21 tag = '07-03-08' # worked fine for D2522 tag = '07-04-12'23 tag = '07-04-08' # new with multiple seeds for CNS0724 tag = '07-05-14' # no25 tag= '07-04-08' # this worked nice and will be a reference for D2526 tag = '07-05-17' # going OO27 tag = '07-07-12' # testing the new shelve interface28 20 tag = '08-01-04' # demo for Debrecen 29 21 … … 31 23 from NeuroTools.benchmark import * 32 24 from numpy import linspace, ones 25 26 33 27 ### testing the noise response 34 28 import benchmark_noise … … 42 36 B.run_simulations() 43 37 benchmark_noise.show(B) 44 raise("to finish") 38 45 39 ### testing the linear response 46 40 import benchmark_linear trunk/examples/retina/retina.py
r84 r101 104 104 'simtime' : 40000*0.1, # float; (ms) 105 105 'syn_delay' : 1.0, # float; (ms) 106 'noise_std' : 4.0, # (nA) standard deviation of the internal noise107 'snr' : 3.0, # (nA) maximum signal106 'noise_std' : 5.0, # (nA) standard deviation of the internal noise 107 'snr' : 2.0, # (nA) maximum signal 108 108 'weight' : 1.0, # 109 109 #'threads' : 2, 'kernelseeds' : [43210987, 394780234], # array with one element per thread … … 116 116 117 117 # retinal neurons parameters 118 self.params['parameters_gc'] = {'Theta':-57.0, 'Vreset': -70.0,'Vinit': -63.0, 'TauR': 0.5, 'gL':28.95, 118 self.params['parameters_gc'] = {'Theta':-57.0, 'Vreset': -70.0,'Vinit': -70.0, 119 'TauR': 0.5, 'gL':28.95, 119 120 'C':289.5, 'V_reversal_E': 0.0, 'V_reversal_I': -75.0, 'TauSyn_E':1.5, 120 121 'TauSyn_I': 10.0, 'V_reversal_sfa': -70.0, 'q_sfa': 0., #14.48, … … 152 153 sim.Timer.start() # start timer on construction 153 154 sim.setup(timestep=params['dt'],max_delay=params['syn_delay']) 154 #sim.pynest.setDict([0],{'threads' : params['threads']})155 155 sim.setRNGseeds([params['kernelseed']]) 156 156 … … 159 159 phr_ON = sim.Population(N,'dc_generator') 160 160 phr_OFF = sim.Population(N,'dc_generator') 161 for phr in [phr_ON, phr_OFF]: 161 for factor, phr in [(-params['snr'],phr_OFF),(params['snr'],phr_ON)]: 162 phr.tset('amplitude', params['amplitude'] * factor ) 162 163 phr.set({ 'start' : params['simtime']/4, 'stop' : params['simtime']/4*3}) 163 164 … … 166 167 noise_OFF = sim.Population(N,'noise_generator',{'mean':0.,'std':params['noise_std']}) 167 168 168 # TODO LUP : here introduce a tranformation of the image (on a grid) by a DOG and then on the specific location of the neuron169 170 171 phr_ON.tset('amplitude', params['amplitude'] * params['snr'])172 phr_OFF.tset('amplitude', - params['amplitude'] * params['snr'])173 169 174 170 # target ON and OFF populations (what about a tridimensional Population?) … … 191 187 ## >>> p1.randomInit(vinit_distr) 192 188 193 194 # Connecting the network 189 # connection matrix= 190 ## connections = ([retina_proj_ON,phr_ON, out_ON]) 191 ## # Connecting the network 192 ## for name_proj,in_pop, out_pop in connections: 193 195 194 retina_proj_ON = sim.Projection(phr_ON, out_ON, 'oneToOne') 196 195 retina_proj_ON.setWeights(params['weight'])# trunk/spikes.py
r99 r101 24 24 >>> s1.isi() 25 25 array([ 0.1, 0.1, 0.3]) 26 >>> s1.mean_ firing_rate()26 >>> s1.mean_rate() 27 27 8.0 28 28 >>> s1.cv_isi() … … 145 145 146 146 # Returns the mean firing rate of the SpikeTrain 147 def mean_ firing_rate(self, t_start=None, t_stop=None):147 def mean_rate(self, t_start=None, t_stop=None): 148 148 """ Mean firing rate between t_start and t_stop in Hz 149 149 … … 151 151 """ 152 152 if (t_start==None) & (t_start==None): 153 t_start=self.t_start 154 t_stop=self.t_stop 153 155 idx = self.spike_times 154 156 else: 155 157 if t_start==None: t_start=self.t_start 156 if t_stop==None: t_st art=self.t_stop158 if t_stop==None: t_stop=self.t_stop 157 159 idx = numpy.where((self.spike_times >= t_start) & (self.spike_times <= t_stop))[0] 158 160 return 1000.*len(idx)/(t_stop-t_start) … … 219 221 are calculated from `self.t_start` and `self.t_stop`. 220 222 If `normalized` is True, the bin values are scaled so as to represent 221 firing rates in spikes/second, otherwise .223 firing rates in spikes/second, otherwise it's the number of spikes per bin. 222 224 """ 223 225 nbins = self.time_axis(time_bin) … … 481 483 482 484 483 see mean_firing_rate485 see SpikeTrain.mean_rate 484 486 """ 485 487 rates = [] 486 488 for id in self.id_list: 487 rates.append(self.spiketrains[id].mean_ firing_rate(t_start, t_stop))489 rates.append(self.spiketrains[id].mean_rate(t_start, t_stop)) 488 490 489 491 return rates … … 492 494 # If display is True, then it plots the distribution of the rates 493 495 def rate_distribution(self, nbins=25, normalize=True, display=False): 494 rates = numpy.zeros(self.N, float) 495 for idx,id in enumerate(self.id_list): 496 rates[idx] = self.spiketrains[id].mean_firing_rate() 496 #rates = numpy.zeros(self.N, float) 497 #for idx,id in enumerate(self.id_list): 498 # rates[idx] = self.spiketrains[id].mean_firing_rate() 499 rates = self.mean_rates() 497 500 if not display: 498 501 return rates … … 560 563 if isinstance(dims, tuple) or isinstance(dims, list): 561 564 activity_map = numpy.zeros(dims,float) 565 rates = self.mean_rates() 562 566 for id in self.id_list: 563 567 position = self.id2position(id, dims) 564 activity_map[position] = self.spiketrains[id].mean_firing_rate()568 activity_map[position] = rates[id] 565 569 if not display: 566 570 return activity_map … … 575 579 if not len(self.id_list) == len(dims[0]): 576 580 raise Exception("Error, the number of positions does not match the number of cells in the SpikeList") 577 rates = []578 for id in self.id_list:579 rates.append(self.spiketrains[id].mean_firing_rate())581 rates = self.mean_rates() 582 #for id in self.id_list: 583 # rates.append(self.spiketrains[id].mean_firing_rate()) 580 584 if not display: 581 585 return rates

