neuroprob/utils/neural.py
def spike_var_MI(rate, prob):
    """
    Mutual information analysis for inhomogeneous Poisson process rate variable.
    
    .. math::
            I(x;\text{spike}) = \int p(x) \, \lambda(x) \, \log{\frac{\lambda(x)}{\langle \lambda \rangle}} \, \mathrm{d}x,
            
    :param np.array rate: rate variables of shape (neurons, covariate_dims...)
    :param np.array prob: occupancy values for each bin of shape (covariate_dims...)
    """
    units = rate.shape[0]
    
    MI = np.empty(units)
    logterm = rate/((rate*prob[np.newaxis, :]).sum(axis=tuple(k for k in range(1, len(rate.shape))), keepdims=True) + 1e-12)
    logterm[logterm == 0] = 1.0 # goes to zero in log terms
    for u in range(units): # MI in bits
        MI[u] = (prob * rate[u] * np.log2(logterm[u])).sum()

    return MI

    Mutual information analysis for inhomogeneous Poisson process rate variable.
    
    .. math::
            I(x;\text{spike}) = \int p(x) \, \lambda(x) \, \log{\frac{\lambda(x)}{\langle \lambda \rangle}} \, \mathrm{d}x,
            
    :param np.array rate: rate variables of shape (neurons, covariate_dims...)
    :param np.array prob: occupancy values for each bin of shape (covariate_dims...)
    
Mutual information analysis for inhomogeneous Poisson process rate variable.
Mutual information analysis for inhomogeneous Poisson process rate variable .
def spike_var_MI(rate, prob):
    units = rate.shape[0]
    MI = np.empty(units)
    logterm = rate/((rate*prob[np.newaxis, :]).sum(axis=tuple(k for k in range(1, len(rate.shape))), keepdims=True) + 1e-12)
    logterm[logterm == 0] = 1.0 
    for u in range(units): 
        MI[u] = (prob * rate[u] * np.log2(logterm[u])).sum()
    return MI
def spike_var_MI ( rate , prob ) : units = rate . shape [ 0 ] MI = np . empty ( units ) logterm = rate / ( ( rate * prob [ np . newaxis , : ] ) . sum ( axis = tuple ( k for k in range ( 1 , len ( rate . shape ) ) ) , keepdims = True ) + 1e-12 ) logterm [ logterm == 0 ] = 1.0 for u in range ( units ) : MI [ u ] = ( prob * rate [ u ] * np . log2 ( logterm [ u ] ) ) . sum ( ) return MI
Mutual information analysis for inhomogeneous Poisson process rate variable.
Mutual information analysis for inhomogeneous Poisson process rate variable .
"""
    Mutual information analysis for inhomogeneous Poisson process rate variable.
    
    .. math::
            I(x;\text{spike}) = \int p(x) \, \lambda(x) \, \log{\frac{\lambda(x)}{\langle \lambda \rangle}} \, \mathrm{d}x,
            
    :param np.array rate: rate variables of shape (neurons, covariate_dims...)
    :param np.array prob: occupancy values for each bin of shape (covariate_dims...)
    """ # goes to zero in log terms # MI in bits
rate
rate variables of shape (neurons, covariate_dims...)
rate variables of shape ( neurons covariate_dims ... )
prob
occupancy values for each bin of shape (covariate_dims...)
occupancy values for each bin of shape ( covariate_dims ... )