User Tools

Inhomogeneous Poisson spike train generation

def gen_spikes(r,dt,rng):
    '''Generate spike train from Poisson rate
 
    Parameters
    ----------
    r:   Array of spike rates
    dt:  Time step
    rng: Random number generator
    '''
    i = 0
    s = 0
    spks = []
    while True:
        s += rng.exponential()
        while s>r[i]*dt:
            s -= r[i]*dt
            i += 1
            if i>=len(r): break
        else:
            spks.append(i*dt+s/r[i])
            continue
        break
    return np.array(spks)

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also, you acknowledge that you have read and understand our Privacy Policy. If you do not agree, please leave the website.

More information