neuroprob/rate_models.py
def w_to_gaussian(w):
    """
    Get Gaussian and orthogonal theta parameterization from the GLM parameters.
    
    :param np.array w: input GLM parameters of shape (neurons, dims), dims labelling (w_1, w_x,
                       w_y, w_xx, w_yy, w_xy, w_cos, w_sin)
    """
    neurons = mu.shape[0]
    w_spat = w[:, 0:6]
    prec = np.empty((neurons, 3)) # xx, yy and xy/yx
    mu = np.empty((neurons, 2)) # x and y
    prec[:, 0] = -2*w_spat[:, 3]
    prec[:, 1] = -2*w_spat[:, 4]
    prec[:, 2] = -w_spat[:, 5]
    prec_mat = []
    for n in range(neurons):
        prec_mat.append([[prec[n, 0], prec[n, 2]], [prec[n, 2], prec[n, 1]]])
    prec_mat = np.array(prec_mat)
    denom = prec[:, 0]*prec[:, 1] - prec[:, 2]**2
    mu[:, 0] = (w_spat[:, 1]*prec[:, 1] - w_spat[:, 2]*prec[:, 2])/denom
    mu[:, 1] = (w_spat[:, 2]*prec[:, 0] - w_spat[:, 1]*prec[:, 2])/denom
    rate_0 = np.exp(w_spat[:, 0] + 0.5*(mu * np.einsum('nij,nj->ni', prec_mat, mu)).sum(1))

    w_theta = w[:, 6:]
    theta_0 = np.angle(w_theta[:, 0] + w_theta[:, 1]*1j)
    beta = np.sqrt(w_theta[:, 0]**2 + w_theta[:, 1]**2)

    return mu, prec, rate_0, np.concatenate((beta[:, None], theta_0[:, None]), axis=1)

    Get Gaussian and orthogonal theta parameterization from the GLM parameters.
    
    :param np.array w: input GLM parameters of shape (neurons, dims), dims labelling (w_1, w_x,
                       w_y, w_xx, w_yy, w_xy, w_cos, w_sin)
    
Get Gaussian and orthogonal theta parameterization from the GLM parameters.
Get Gaussian and orthogonal theta parameterization from the GLM parameters .
def w_to_gaussian(w):
    neurons = mu.shape[0]
    w_spat = w[:, 0:6]
    prec = np.empty((neurons, 3)) 
    mu = np.empty((neurons, 2)) 
    prec[:, 0] = -2*w_spat[:, 3]
    prec[:, 1] = -2*w_spat[:, 4]
    prec[:, 2] = -w_spat[:, 5]
    prec_mat = []
    for n in range(neurons):
        prec_mat.append([[prec[n, 0], prec[n, 2]], [prec[n, 2], prec[n, 1]]])
    prec_mat = np.array(prec_mat)
    denom = prec[:, 0]*prec[:, 1] - prec[:, 2]**2
    mu[:, 0] = (w_spat[:, 1]*prec[:, 1] - w_spat[:, 2]*prec[:, 2])/denom
    mu[:, 1] = (w_spat[:, 2]*prec[:, 0] - w_spat[:, 1]*prec[:, 2])/denom
    rate_0 = np.exp(w_spat[:, 0] + 0.5*(mu * np.einsum('nij,nj->ni', prec_mat, mu)).sum(1))
    w_theta = w[:, 6:]
    theta_0 = np.angle(w_theta[:, 0] + w_theta[:, 1]*1j)
    beta = np.sqrt(w_theta[:, 0]**2 + w_theta[:, 1]**2)
    return mu, prec, rate_0, np.concatenate((beta[:, None], theta_0[:, None]), axis=1)
def w_to_gaussian ( w ) : neurons = mu . shape [ 0 ] w_spat = w [ : , 0 : 6 ] prec = np . empty ( ( neurons , 3 ) ) mu = np . empty ( ( neurons , 2 ) ) prec [ : , 0 ] = - 2 * w_spat [ : , 3 ] prec [ : , 1 ] = - 2 * w_spat [ : , 4 ] prec [ : , 2 ] = - w_spat [ : , 5 ] prec_mat = [ ] for n in range ( neurons ) : prec_mat . append ( [ [ prec [ n , 0 ] , prec [ n , 2 ] ] , [ prec [ n , 2 ] , prec [ n , 1 ] ] ] ) prec_mat = np . array ( prec_mat ) denom = prec [ : , 0 ] * prec [ : , 1 ] - prec [ : , 2 ] ** 2 mu [ : , 0 ] = ( w_spat [ : , 1 ] * prec [ : , 1 ] - w_spat [ : , 2 ] * prec [ : , 2 ] ) / denom mu [ : , 1 ] = ( w_spat [ : , 2 ] * prec [ : , 0 ] - w_spat [ : , 1 ] * prec [ : , 2 ] ) / denom rate_0 = np . exp ( w_spat [ : , 0 ] + 0.5 * ( mu * np . einsum ( 'nij,nj->ni' , prec_mat , mu ) ) . sum ( 1 ) ) w_theta = w [ : , 6 : ] theta_0 = np . angle ( w_theta [ : , 0 ] + w_theta [ : , 1 ] * 1j ) beta = np . sqrt ( w_theta [ : , 0 ] ** 2 + w_theta [ : , 1 ] ** 2 ) return mu , prec , rate_0 , np . concatenate ( ( beta [ : , None ] , theta_0 [ : , None ] ) , axis = 1 )
Get Gaussian and orthogonal theta parameterization from the GLM parameters.
Get Gaussian and orthogonal theta parameterization from the GLM parameters .
"""
    Get Gaussian and orthogonal theta parameterization from the GLM parameters.
    
    :param np.array w: input GLM parameters of shape (neurons, dims), dims labelling (w_1, w_x,
                       w_y, w_xx, w_yy, w_xy, w_cos, w_sin)
    """ # xx, yy and xy/yx # x and y
w
input GLM parameters of shape (neurons, dims), dims labelling (w_1, w_x,
w_y, w_xx, w_yy, w_xy, w_cos, w_sin)
input GLM parameters of shape ( neurons dims ) dims labelling ( w_1 w_x w_y w_xx w_yy w_xy w_cos w_sin )