neuroprob/utils/neural.py
def IPP_model(sample_bin, bin_thres, covariates, cov_bins, spiketimes, divide=True):
    """
    Compute the occupancy-normalized activity histogram for neural data, corresponding to maximum 
    likelihood estimation of the rate in an inhomogeneous Poisson process.
    
    :param float sample_bin: binning time
    :param float bin_thres: only count bins with total occupancy time above bin_thres
    :param list covariates: list of time series that describe animal behaviour
    :param tuple cov_bins: tuple of arrays describing bin boundary locations
    :param list spiketimes: list of arrays containing spike times of neurons
    :param bool divide: return the histogram divisions (rate and histogram probability in region) 
                        or the activity and time histograms
    """
    units = len(spiketimes)
    c_bins = ()
    tg_c = ()
    sg_c = [() for u in range(units)]
    for k, cov in enumerate(covariates):
        c_bins += (len(cov_bins[k])-1,)
        tg_c += (np.digitize(cov, cov_bins[k])-1,)
        for u in range(units):
            sg_c[u] += (np.digitize(cov[spiketimes[u]], cov_bins[k])-1,)

    # get time spent in each bin
    bin_time = np.zeros(tuple(len(bins)-1 for bins in cov_bins))
    np.add.at(bin_time, tg_c, sample_bin)

    # get activity of each bin per neuron
    activity = np.zeros((units,)+tuple(len(bins)-1 for bins in cov_bins))
    for u in range(units):
        np.add.at(activity[u], sg_c[u], 1)

    if divide:
        sess_rate = np.zeros((units,)+tuple(len(bins)-1 for bins in cov_bins))
        bin_time[bin_time <= bin_thres] = -1.0 # avoid division by zero
        for u in range(units):
            activity[u][bin_time < bin_thres] = 0.0
            sess_rate[u] = activity[u]/bin_time
        bin_time[bin_time < bin_thres] = 0.0 # take care of unvisited/uncounted bins
        prob = bin_time / bin_time.sum()

        return sess_rate, prob
    else:
        return activity, bin_time

    Compute the occupancy-normalized activity histogram for neural data, corresponding to maximum 
    likelihood estimation of the rate in an inhomogeneous Poisson process.
    
    :param float sample_bin: binning time
    :param float bin_thres: only count bins with total occupancy time above bin_thres
    :param list covariates: list of time series that describe animal behaviour
    :param tuple cov_bins: tuple of arrays describing bin boundary locations
    :param list spiketimes: list of arrays containing spike times of neurons
    :param bool divide: return the histogram divisions (rate and histogram probability in region) 
                        or the activity and time histograms
    
Compute the occupancy-normalized activity histogram for neural data, corresponding to maximum
likelihood estimation of the rate in an inhomogeneous Poisson process.
Compute the occupancy - normalized activity histogram for neural data corresponding to maximum likelihood estimation of the rate in an inhomogeneous Poisson process .
def IPP_model(sample_bin, bin_thres, covariates, cov_bins, spiketimes, divide=True):
    units = len(spiketimes)
    c_bins = ()
    tg_c = ()
    sg_c = [() for u in range(units)]
    for k, cov in enumerate(covariates):
        c_bins += (len(cov_bins[k])-1,)
        tg_c += (np.digitize(cov, cov_bins[k])-1,)
        for u in range(units):
            sg_c[u] += (np.digitize(cov[spiketimes[u]], cov_bins[k])-1,)
    bin_time = np.zeros(tuple(len(bins)-1 for bins in cov_bins))
    np.add.at(bin_time, tg_c, sample_bin)
    activity = np.zeros((units,)+tuple(len(bins)-1 for bins in cov_bins))
    for u in range(units):
        np.add.at(activity[u], sg_c[u], 1)
    if divide:
        sess_rate = np.zeros((units,)+tuple(len(bins)-1 for bins in cov_bins))
        bin_time[bin_time <= bin_thres] = -1.0 
        for u in range(units):
            activity[u][bin_time < bin_thres] = 0.0
            sess_rate[u] = activity[u]/bin_time
        bin_time[bin_time < bin_thres] = 0.0 
        prob = bin_time / bin_time.sum()
        return sess_rate, prob
    else:
        return activity, bin_time
def IPP_model ( sample_bin , bin_thres , covariates , cov_bins , spiketimes , divide = True ) : units = len ( spiketimes ) c_bins = ( ) tg_c = ( ) sg_c = [ ( ) for u in range ( units ) ] for k , cov in enumerate ( covariates ) : c_bins += ( len ( cov_bins [ k ] ) - 1 , ) tg_c += ( np . digitize ( cov , cov_bins [ k ] ) - 1 , ) for u in range ( units ) : sg_c [ u ] += ( np . digitize ( cov [ spiketimes [ u ] ] , cov_bins [ k ] ) - 1 , ) bin_time = np . zeros ( tuple ( len ( bins ) - 1 for bins in cov_bins ) ) np . add . at ( bin_time , tg_c , sample_bin ) activity = np . zeros ( ( units , ) + tuple ( len ( bins ) - 1 for bins in cov_bins ) ) for u in range ( units ) : np . add . at ( activity [ u ] , sg_c [ u ] , 1 ) if divide : sess_rate = np . zeros ( ( units , ) + tuple ( len ( bins ) - 1 for bins in cov_bins ) ) bin_time [ bin_time <= bin_thres ] = - 1.0 for u in range ( units ) : activity [ u ] [ bin_time < bin_thres ] = 0.0 sess_rate [ u ] = activity [ u ] / bin_time bin_time [ bin_time < bin_thres ] = 0.0 prob = bin_time / bin_time . sum ( ) return sess_rate , prob else : return activity , bin_time
Compute the occupancy-normalized activity histogram for neural data, corresponding to maximum
likelihood estimation of the rate in an inhomogeneous Poisson process.
Compute the occupancy - normalized activity histogram for neural data corresponding to maximum likelihood estimation of the rate in an inhomogeneous Poisson process .
"""
    Compute the occupancy-normalized activity histogram for neural data, corresponding to maximum 
    likelihood estimation of the rate in an inhomogeneous Poisson process.
    
    :param float sample_bin: binning time
    :param float bin_thres: only count bins with total occupancy time above bin_thres
    :param list covariates: list of time series that describe animal behaviour
    :param tuple cov_bins: tuple of arrays describing bin boundary locations
    :param list spiketimes: list of arrays containing spike times of neurons
    :param bool divide: return the histogram divisions (rate and histogram probability in region) 
                        or the activity and time histograms
    """ # get time spent in each bin # get activity of each bin per neuron # avoid division by zero # take care of unvisited/uncounted bins
sample_bin
None
bin_thres
only count bins with total occupancy time above bin_thres
only count bins with total occupancy time above bin_thres
covariates
list of time series that describe animal behaviour
list of time series that describe animal behaviour
cov_bins
tuple of arrays describing bin boundary locations
tuple of arrays describing bin boundary locations
spiketimes
list of arrays containing spike times of neurons
list of arrays containing spike times of neurons
divide
return the histogram divisions (rate and histogram probability in region)
or the activity and time histograms
return the histogram divisions ( rate and histogram probability in region ) or the activity and time histograms