scripts/model_utils.py
def marginalized_P(full_model, eval_points, eval_dims, rcov, bs, use_neuron, MC=100, skip=1):
    """
    Marginalize over the behaviour p(X) for X not evaluated over.
    """
    rcov = [rc[::skip] for rc in rcov] # set dilution
    animal_T = rcov[0].shape[0]
    Ep = eval_points[0].shape[0]
    tot_len = Ep*animal_T
    
    covariates = []
    k = 0
    for d, rc in enumerate(rcov):
        if d in eval_dims:
            covariates.append(eval_points[k].repeat(animal_T))
            k += 1
        else:
            covariates.append(np.tile(rc, Ep))
    
    P_tot = np.empty((MC, len(use_neuron), Ep, full_model.likelihood.K))
    batches = int(np.ceil(animal_T / bs))
    for e in range(Ep):
        print(e)
        P_ = np.empty((MC, len(use_neuron), animal_T, full_model.likelihood.K))
        for b in range(batches):
            bcov = [c[e*animal_T:(e+1)*animal_T][b*bs:(b+1)*bs] for c in covariates]
            P_mc = compute_P(full_model, bcov, use_neuron, MC=MC).cpu()
            P_[..., b*bs:(b+1)*bs, :] = P_mc
            
        P_tot[..., e, :] = P_.mean(-2)
        
    return P_tot

    Marginalize over the behaviour p(X) for X not evaluated over.
    
Marginalize over the behaviour p(X) for X not evaluated over.
Marginalize over the behaviour p ( X ) for X not evaluated over .
def marginalized_P(full_model, eval_points, eval_dims, rcov, bs, use_neuron, MC=100, skip=1):
    rcov = [rc[::skip] for rc in rcov] 
    animal_T = rcov[0].shape[0]
    Ep = eval_points[0].shape[0]
    tot_len = Ep*animal_T
    covariates = []
    k = 0
    for d, rc in enumerate(rcov):
        if d in eval_dims:
            covariates.append(eval_points[k].repeat(animal_T))
            k += 1
        else:
            covariates.append(np.tile(rc, Ep))
    P_tot = np.empty((MC, len(use_neuron), Ep, full_model.likelihood.K))
    batches = int(np.ceil(animal_T / bs))
    for e in range(Ep):
        print(e)
        P_ = np.empty((MC, len(use_neuron), animal_T, full_model.likelihood.K))
        for b in range(batches):
            bcov = [c[e*animal_T:(e+1)*animal_T][b*bs:(b+1)*bs] for c in covariates]
            P_mc = compute_P(full_model, bcov, use_neuron, MC=MC).cpu()
            P_[..., b*bs:(b+1)*bs, :] = P_mc
        P_tot[..., e, :] = P_.mean(-2)
    return P_tot
def marginalized_P ( full_model , eval_points , eval_dims , rcov , bs , use_neuron , MC = 100 , skip = 1 ) : rcov = [ rc [ : : skip ] for rc in rcov ] animal_T = rcov [ 0 ] . shape [ 0 ] Ep = eval_points [ 0 ] . shape [ 0 ] tot_len = Ep * animal_T covariates = [ ] k = 0 for d , rc in enumerate ( rcov ) : if d in eval_dims : covariates . append ( eval_points [ k ] . repeat ( animal_T ) ) k += 1 else : covariates . append ( np . tile ( rc , Ep ) ) P_tot = np . empty ( ( MC , len ( use_neuron ) , Ep , full_model . likelihood . K ) ) batches = int ( np . ceil ( animal_T / bs ) ) for e in range ( Ep ) : print ( e ) P_ = np . empty ( ( MC , len ( use_neuron ) , animal_T , full_model . likelihood . K ) ) for b in range ( batches ) : bcov = [ c [ e * animal_T : ( e + 1 ) * animal_T ] [ b * bs : ( b + 1 ) * bs ] for c in covariates ] P_mc = compute_P ( full_model , bcov , use_neuron , MC = MC ) . cpu ( ) P_ [ ... , b * bs : ( b + 1 ) * bs , : ] = P_mc P_tot [ ... , e , : ] = P_ . mean ( - 2 ) return P_tot
Marginalize over the behaviour p(X) for X not evaluated over.
Marginalize over the behaviour p ( X ) for X not evaluated over .
"""
    Marginalize over the behaviour p(X) for X not evaluated over.
    """ # set dilution
full_model
eval_points
eval_dims
rcov
bs
use_neuron
MC
skip