Changeset 462
- Timestamp:
- 09/02/10 15:42:45 (17 months ago)
- Location:
- trunk/src
- Files:
-
- 2 modified
-
signals/spikes.py (modified) (7 diffs)
-
stgen.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/signals/spikes.py
r453 r462 915 915 #def __setslice__(self, i, j): 916 916 917 918 919 917 def __setitem__(self, id, spktrain): 920 918 assert isinstance(spktrain, SpikeTrain), "A SpikeList object can only contain SpikeTrain objects" … … 1072 1070 1073 1071 Examples: 1074 >> spklist.id_list ()1072 >> spklist.id_list 1075 1073 [0,2,5] 1076 1074 >> spklist.complete(arange(5)) 1077 >> spklist.id_list ()1075 >> spklist.id_list 1078 1076 [0,1,2,3,4] 1079 1077 """ … … 1712 1710 return id-offset 1713 1711 if len(self.dimensions) == 2: 1714 x = (id-offset) % self.dimensions[ 1]1715 y = self.dimensions[0] - 1 - numpy.floor((id-offset)/self.dimensions[1]).astype(int)1712 x = (id-offset) % self.dimensions[0] 1713 y = ((id-offset)/self.dimensions[0]).astype(int) 1716 1714 return (x,y) 1717 1715 … … 1735 1733 assert len(position) == len(tuple(self.dimensions)), "position does not have the correct shape !" 1736 1734 if len(self.dimensions) == 1: 1737 return position +offset1735 return position + offset 1738 1736 if len(self.dimensions) == 2: 1739 return (self.dimensions[0] - 1 - position[1])*self.dimensions[1] + position[0] + offset1737 return position[1]*self.dimensions[1] + position[0] + offset 1740 1738 1741 1739 … … 1786 1784 activity_map = numpy.zeros(self.dimensions, float) 1787 1785 rates = spklist.mean_rates() 1788 id_offset = min(self.id_list()) 1786 #id_offset = min(self.id_list()) 1787 #x,y = spklist.id2position(spklist.id_list(), id_offset) 1788 x,y = spklist.id2position(spklist.id_list()) 1789 #j,i = x, self.dimensions[0] - 1 - y 1789 1790 for count, id in enumerate(spklist.id_list()): 1790 x,y = spklist.id2position(id, id_offset) 1791 j,i = x, self.dimensions[0] - 1 -y 1792 activity_map[i,j] = rates[count] 1791 #activity_map[i[count],j[count]] = rates[count] 1792 activity_map[x[count],y[count]] = rates[count] 1793 1793 if not subplot or not HAVE_PYLAB or not HAVE_MATPLOTLIB: 1794 1794 return activity_map … … 2247 2247 time = time[sort_idx] 2248 2248 pos = pos[sort_idx] 2249 x,y = spk.id2position(pos) 2249 2250 max_idx = len(time)-1 2250 2251 logging.info('Making movie %s - this make take a while' % output) … … 2254 2255 while (t_start < t_stop): 2255 2256 activity_map = numpy.zeros(spk.dimensions) 2256 while ((time[idx] < t_start + time_bin) and (idx < max_idx)): 2257 x,y = spk.id2position(pos[idx]) 2258 j,i = x, self.dimensions[0] - 1 -y 2259 activity_map[i,j] += 1 2257 while ((time[idx] < t_start + time_bin) and (idx < max_idx)): 2258 #j,i = x, self.dimensions[0] - 1 -y 2259 activity_map[x[idx],y[idx]] += 1 2260 2260 idx += 1 2261 2261 im.set_array(activity_map) -
trunk/src/stgen.py
r448 r462 255 255 return spikes 256 256 257 257 def gamma_generator(self, a, b, t_start=0.0, t_stop=1000.0, array=False,debug=False): 258 """ 259 Returns a SpikeTrain whose spikes are a realization of a Poisson process 260 with the given rate (Hz) and stopping time t_stop (milliseconds). 261 262 Note: t_start is always 0.0, thus all realizations are as if 263 they spiked at t=0.0, though this spike is not included in the SpikeList. 264 265 Inputs: 266 a,b - the parameters of the gamma process 267 t_start - the beginning of the SpikeTrain (in ms) 268 t_stop - the end of the SpikeTrain (in ms) 269 array - if True, a numpy array of sorted spikes is returned, 270 rather than a SpikeTrain object. 271 272 Examples: 273 >> gen.poisson_generator(50, 0, 1000) 274 >> gen.poisson_generator(20, 5000, 10000, array=True) 275 276 See also: 277 inh_poisson_generator, inh_gamma_generator, inh_adaptingmarkov_generator 278 """ 279 280 #number = int((t_stop-t_start)/1000.0*2.0*rate) 281 282 # less wasteful than double length method above 283 n = (t_stop-t_start)/1000.0*(a*b) 284 number = numpy.ceil(n+3*numpy.sqrt(n)) 285 if number<100: 286 number = min(5+numpy.ceil(2*n),100) 287 288 if number > 0: 289 isi = self.rng.gamma(a, b, number)*1000.0 290 if number > 1: 291 spikes = numpy.add.accumulate(isi) 292 else: 293 spikes = isi 294 else: 295 spikes = numpy.array([]) 296 297 spikes+=t_start 298 i = numpy.searchsorted(spikes, t_stop) 299 300 extra_spikes = [] 301 if i==len(spikes): 302 # ISI buf overrun 303 304 t_last = spikes[-1] + self.rng.gamma(a, b, 1)[0]*1000.0 305 306 while (t_last<t_stop): 307 extra_spikes.append(t_last) 308 t_last += self.rng.gamma(a, b, 1)[0]*1000.0 309 310 spikes = numpy.concatenate((spikes,extra_spikes)) 311 312 if debug: 313 print "ISI buf overrun handled. len(spikes)=%d, len(extra_spikes)=%d" % (len(spikes),len(extra_spikes)) 314 315 316 else: 317 spikes = numpy.resize(spikes,(i,)) 318 319 if not array: 320 spikes = SpikeTrain(spikes, t_start=t_start,t_stop=t_stop) 321 322 323 if debug: 324 return spikes, extra_spikes 325 else: 326 return spikes 327 258 328 def inh_poisson_generator(self, rate, t, t_stop, array=False): 259 329 """ … … 395 465 # find index in "t" time 396 466 t_i = numpy.searchsorted(t[t_i:],ps[i],'right')-1+t_i 397 if rn[i]<gamma_hazard ((ps[i]-t_last)/1000.0,a[t_i],b[t_i])/rmax:467 if rn[i]<gamma_hazard_scipy((ps[i]-t_last)/1000.0,a[t_i],b[t_i])/rmax: 398 468 # keep spike 399 469 t_last = ps[i]
