Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionLast revisionBoth sides next revision | ||
technical:poisson_spike_train [2020/10/13 19:35] – created chunchung | technical:poisson_spike_train [2022/10/10 05:54] – chunchung | ||
---|---|---|---|
Line 1: | Line 1: | ||
======Inhomogeneous Poisson spike train generation====== | ======Inhomogeneous Poisson spike train generation====== | ||
+ | <code python> | ||
+ | def gen_spikes(r, | ||
+ | ''' | ||
+ | |||
+ | Parameters | ||
+ | ---------- | ||
+ | r: Array of spike rates | ||
+ | dt: Time step | ||
+ | ''' | ||
+ | i = 0 | ||
+ | s = 0 | ||
+ | spks = [] | ||
+ | while True: | ||
+ | s += np.random.exponential() | ||
+ | while s> | ||
+ | s -= r[i]*dt | ||
+ | i += 1 | ||
+ | if i> | ||
+ | else: | ||
+ | spks.append(i*dt+s/ | ||
+ | continue | ||
+ | break | ||
+ | return np.array(spks) | ||
+ | </ |