def test_poisson(self): # Check the output types for input rate + n number of neurons pp = stgen._n_poisson(rate=self.rate, t_stop=self.t_stop, n=self.n) self.assertIsInstance(pp, list) self.assertIsInstance(pp[0], neo.core.spiketrain.SpikeTrain) self.assertEqual(pp[0].simplified.units, 1000*ms) self.assertEqual(len(pp), self.n) # Check the output types for input list of rates pp = stgen._n_poisson(rate=self.rates, t_stop=self.t_stop) self.assertIsInstance(pp, list) self.assertIsInstance(pp[0], neo.core.spiketrain.SpikeTrain) self.assertEqual(pp[0].simplified.units, 1000*ms) self.assertEqual(len(pp), self.n)
def test_poisson(self): # Check the output types for input rate + n number of neurons pp = stgen._n_poisson(rate=self.rate, t_stop=self.t_stop, n=self.n) self.assertIsInstance(pp, list) self.assertIsInstance(pp[0], neo.core.spiketrain.SpikeTrain) self.assertEqual(pp[0].simplified.units, 1000 * ms) self.assertEqual(len(pp), self.n) # Check the output types for input list of rates pp = stgen._n_poisson(rate=self.rates, t_stop=self.t_stop) self.assertIsInstance(pp, list) self.assertIsInstance(pp[0], neo.core.spiketrain.SpikeTrain) self.assertEqual(pp[0].simplified.units, 1000 * ms) self.assertEqual(len(pp), self.n)
def generate_sts(data_type, N=100): ''' Generate a list of parallel spike trains with different statistics. The data are composed of background spiking activity plus possibly a repeated sequence of synchronous events (SSE). The background activity depends on the value of data_type. The size and occurrence count of the SSE is specified by sse_params. Parameters ---------- data_type : int An integer specifying the type of background activity. At the moment the following types of background activity are supported (note: homog = across neurons; stat = over time): 0 : 100 indep Poisson with rate 25 Hz 1: 100 indep Poisson nonstat-step (10/60/10 Hz) 2: 100 indep Poisson heterog (5->25 Hz), stat 3 : 100 indep Poisson, rate increase with latency variability N: int total number of neurons in the model. The default is N=100. Output ------ sts : list of SpikeTrains a list of spike trains params : dict a dictionary of simulation parameters ''' T = 1 * pq.s # simulation time sampl_period = 10 * pq.ms # sampling period of the rate profile params = {'nr_neurons': N, 'simul_time': T} # Indep Poisson homog, stat rate 25 Hz if data_type == 0: # Define a rate profile rate = 25 * pq.Hz # Generate data sts = stg._n_poisson(rate=rate, t_stop=T, n=N) # Storing rate parameter params['rate'] = rate # Indep Poisson, homog, nonstat-step (10/60/10 Hz) elif data_type == 1: a0, a1 = 10 * pq.Hz, 60 * pq.Hz # baseline and transient rates t1, t2 = 600 * pq.ms, 700 * pq.ms # time segment of transient rate # Define a rate profile times = sampl_period.units * np.arange( 0, T.rescale(sampl_period.units).magnitude, sampl_period.magnitude) rate_profile = np.zeros(times.shape) rate_profile[np.any([times < t1, times > t2], axis=0)] = a0.magnitude rate_profile[np.all([times >= t1, times <= t2], axis=0)] = a1.magnitude rate_profile = rate_profile * a0.units rate_profile = neo.AnalogSignal(rate_profile, sampling_period=sampl_period) # Generate data sts = [ stg.inhomogeneous_poisson_process(rate_profile) for i in range(N) ] # Storing rate parameter params['rate'] = rate_profile # Indep Poisson, heterog (5->15 Hz), stat elif data_type == 2: rate_min = 5 * pq.Hz # min rate. Ensures that there is >=1 spike rate_max = 25 * pq.Hz # max rate rates = np.linspace(rate_min.magnitude, rate_max.magnitude, N) * pq.Hz # Define a rate profile # Generate data sts = [ stg.homogeneous_poisson_process(rate=rate, t_stop=T) for rate in rates ] random.shuffle(sts) # Storing rate parameter params['rate'] = rates # Indep Poisson, rate increase sequence elif data_type == 3: l = 20 # 20 groups of neurons w = 5 # of 5 neurons each t0 = 50 * pq.ms # the first of which increases the rate at time t0 t00 = 500 * pq.ms # and again at time t00 ratechange_dur = 5 * pq.ms # old: 10ms # for a short period a0, a1 = 14 * pq.Hz, 100 * pq.Hz # from rate a0 to a1 ratechange_delay = 5 * pq.ms # old: 10ms; followed with delay by next group # Define a rate profile times = sampl_period.units * np.arange( 0, T.rescale(sampl_period.units).magnitude, sampl_period.magnitude) sts = [] rate_profiles = [] for i in range(l * w): t1 = t0 + (i // w) * ratechange_delay t2 = t1 + ratechange_dur t11 = t00 + (i // w) * ratechange_delay t22 = t11 + ratechange_dur rate_profile = np.zeros(times.shape) rate_profile[np.any([times < t1, times > t2], axis=0)] = \ a0.magnitude rate_profile[np.all([times >= t1, times <= t2], axis=0)] = \ a1.magnitude rate_profile[np.all([times >= t11, times <= t22], axis=0)] = \ a1.magnitude rate_profile = rate_profile * a0.units rate_profile = neo.AnalogSignal(rate_profile, sampling_period=sampl_period) rate_profiles.append(rate_profile) # Generate data sts.append(stg.inhomogeneous_poisson_process(rate_profile)) # Storing rate parameter params['rate'] = rate_profiles else: raise ValueError( 'data_type %d not supported. Provide int from 0 to 10' % data_type) return sts, params
# Computation analytical p-values theo_pvalues = [] for l in lengths: num_combination_patt = (math.factorial(n) / math.factorial(n - xi)) * (l) theo_pvalues.append( binom.sf(occ - 1, (t_stop.simplified.magnitude - l.simplified.magnitude) / binsize.simplified.magnitude, p) * num_combination_patt) # Generating the data # Fixing the seed np.random.seed(0) # Generating Independent Background background_sts = stg._n_poisson(rate=rate, t_stop=t_stop, n=n) # Total number of patterns num_neu_patt = len(lengths) * xi sts = [] stps = [] # Raising errors if the number of neurons is smaller than number # of patterns if num_neu_patt > n: raise ValueError('Number of neurons involved in the patterns is ' 'larger than total number of patterns') for l_idx, l in enumerate(lengths): lag_bins = int(l / (xi - 1)) delays = [i * lag_bins * binsize.magnitude for i in range(1, xi)] * binsize.units print(delays) # Generating patterns