neuroprob/point_process.py
def gen_IRP(interval_dist, rate, tbin, samples=100):
    """
    Sample event times from an Inhomogenous Renewal Process with a given rate function
    samples is an algorithm parameter, should be around the expect number of spikes
    Assumes piecewise constant rate function
    
    Samples intervals from :math:`q(\Delta)`, parallelizes sampling
    
    :param np.array rate: (trials, neurons, timestep)
    :param ISI_dist interval_dist: renewal interval distribution :math:`q(\tau)`
    :returns: event times as integer indices of the rate array time dimension
    :rtype: list of spike time indices as indexed by rate time dimension
    """
    sim_samples = rate.shape[2]
    N = rate.shape[1] # neurons
    trials = rate.shape[0]
    T = np.transpose(np.cumsum(rate, axis=-1), (2, 0, 1))*tbin # actual time to rescaled, (time, trials, neuron)
    
    psT = 0
    sT_cont = []
    while True:

        sT = psT + np.cumsum(interval_dist.sample((samples, trials,)), axis=0)
        sT_cont.append(sT)
        
        if not (T[-1, ...] >= sT[-1, ...]).any(): # all False
            break
            
        psT = np.tile(sT[-1:, ...], (samples, 1, 1))
        
    sT_cont = np.stack(sT_cont, axis=0).reshape(-1, trials, N)
    samples_tot = sT_cont.shape[0]
    st = []
    
    iterator = tqdm(range(samples_tot), leave=False)
    for ss in iterator: # AR assignment
        comp = np.tile(sT_cont[ss:ss+1, ...], (sim_samples, 1, 1))
        st.append(np.argmax((comp < T), axis=0)) # convert to rescaled time indices

    st = np.array(st) # (samples_tot, trials, neurons)
    st_new = []
    for st_ in st.reshape(samples_tot, -1).T:
        if not st_.any(): # all zero
            st_new.append(np.array([]).astype(int))
        else: # first zeros in this case counts as a spike indices
            for k in range(samples_tot):
                if st_[-1-k] != 0:
                    break
            if k == 0:
                st_new.append(st_)
            else:
                st_new.append(st_[:-k])            
            
    return st_new

    Sample event times from an Inhomogenous Renewal Process with a given rate function
    samples is an algorithm parameter, should be around the expect number of spikes
    Assumes piecewise constant rate function
    
    Samples intervals from :math:`q(\Delta)`, parallelizes sampling
    
    :param np.array rate: (trials, neurons, timestep)
    :param ISI_dist interval_dist: renewal interval distribution :math:`q(\tau)`
    :returns: event times as integer indices of the rate array time dimension
    :rtype: list of spike time indices as indexed by rate time dimension
    
Sample event times from an Inhomogenous Renewal Process with a given rate function
samples is an algorithm parameter, should be around the expect number of spikes
Assumes piecewise constant rate function

Samples intervals from :math:`q(\Delta)`, parallelizes sampling
Sample event times from an Inhomogenous Renewal Process with a given rate function samples is an algorithm parameter should be around the expect number of spikes Assumes piecewise constant rate function Samples intervals from : math : ` q ( \ Delta ) ` parallelizes sampling
def gen_IRP(interval_dist, rate, tbin, samples=100):
    sim_samples = rate.shape[2]
    N = rate.shape[1] 
    trials = rate.shape[0]
    T = np.transpose(np.cumsum(rate, axis=-1), (2, 0, 1))*tbin 
    psT = 0
    sT_cont = []
    while True:
        sT = psT + np.cumsum(interval_dist.sample((samples, trials,)), axis=0)
        sT_cont.append(sT)
        if not (T[-1, ...] >= sT[-1, ...]).any(): 
            break
        psT = np.tile(sT[-1:, ...], (samples, 1, 1))
    sT_cont = np.stack(sT_cont, axis=0).reshape(-1, trials, N)
    samples_tot = sT_cont.shape[0]
    st = []
    iterator = tqdm(range(samples_tot), leave=False)
    for ss in iterator: 
        comp = np.tile(sT_cont[ss:ss+1, ...], (sim_samples, 1, 1))
        st.append(np.argmax((comp < T), axis=0)) 
    st = np.array(st) 
    st_new = []
    for st_ in st.reshape(samples_tot, -1).T:
        if not st_.any(): 
            st_new.append(np.array([]).astype(int))
        else: 
            for k in range(samples_tot):
                if st_[-1-k] != 0:
                    break
            if k == 0:
                st_new.append(st_)
            else:
                st_new.append(st_[:-k])            
    return st_new
def gen_IRP ( interval_dist , rate , tbin , samples = 100 ) : sim_samples = rate . shape [ 2 ] N = rate . shape [ 1 ] trials = rate . shape [ 0 ] T = np . transpose ( np . cumsum ( rate , axis = - 1 ) , ( 2 , 0 , 1 ) ) * tbin psT = 0 sT_cont = [ ] while True : sT = psT + np . cumsum ( interval_dist . sample ( ( samples , trials , ) ) , axis = 0 ) sT_cont . append ( sT ) if not ( T [ - 1 , ... ] >= sT [ - 1 , ... ] ) . any ( ) : break psT = np . tile ( sT [ - 1 : , ... ] , ( samples , 1 , 1 ) ) sT_cont = np . stack ( sT_cont , axis = 0 ) . reshape ( - 1 , trials , N ) samples_tot = sT_cont . shape [ 0 ] st = [ ] iterator = tqdm ( range ( samples_tot ) , leave = False ) for ss in iterator : comp = np . tile ( sT_cont [ ss : ss + 1 , ... ] , ( sim_samples , 1 , 1 ) ) st . append ( np . argmax ( ( comp < T ) , axis = 0 ) ) st = np . array ( st ) st_new = [ ] for st_ in st . reshape ( samples_tot , - 1 ) . T : if not st_ . any ( ) : st_new . append ( np . array ( [ ] ) . astype ( int ) ) else : for k in range ( samples_tot ) : if st_ [ - 1 - k ] != 0 : break if k == 0 : st_new . append ( st_ ) else : st_new . append ( st_ [ : - k ] ) return st_new
Sample event times from an Inhomogenous Renewal Process with a given rate function
samples is an algorithm parameter, should be around the expect number of spikes
Assumes piecewise constant rate function
Sample event times from an Inhomogenous Renewal Process with a given rate function samples is an algorithm parameter should be around the expect number of spikes Assumes piecewise constant rate function
"""
    Sample event times from an Inhomogenous Renewal Process with a given rate function
    samples is an algorithm parameter, should be around the expect number of spikes
    Assumes piecewise constant rate function
    
    Samples intervals from :math:`q(\Delta)`, parallelizes sampling
    
    :param np.array rate: (trials, neurons, timestep)
    :param ISI_dist interval_dist: renewal interval distribution :math:`q(\tau)`
    :returns: event times as integer indices of the rate array time dimension
    :rtype: list of spike time indices as indexed by rate time dimension
    """ # neurons # actual time to rescaled, (time, trials, neuron) # all False # AR assignment # convert to rescaled time indices # (samples_tot, trials, neurons) # all zero # first zeros in this case counts as a spike indices
event times as integer indices of the rate array time dimension
event times as integer indices of the rate array time dimension
list of spike time indices as indexed by rate time dimension
interval_dist
renewal interval distribution :math:`q(\tau)`
renewal interval distribution : math : ` q ( \ tau ) `
rate
(trials, neurons, timestep)
( trials neurons timestep )
tbin
samples