scripts/validation.py
def CMP_hdc(sample_bin, track_samples, covariates, neurons, trials=1):
    """
    CMP with separate mu and nu tuning curves
    """
    # Von Mises fields
    angle_0 = np.linspace(0, 2*np.pi, neurons+1)[:-1]
    beta = np.random.rand(neurons)*2.0 + 0.5
    rate_0 = np.random.rand(neurons)*4.0+4.0
    w = np.stack([np.log(rate_0), beta*np.cos(angle_0), beta*np.sin(angle_0)]).T # beta, phi_0 for theta modulation
    neurons = w.shape[0]

    vm_rate = mdl.rate_models.vonMises_GLM(neurons, inv_link='exp')
    vm_rate.set_params(w)

    # Dispersion tuning curve
    _angle_0 = np.random.permutation(angle_0)#angle_0 + 0.4*np.random.randn(neurons)#np.random.permutation(angle_0)
    _beta = 0.6*np.random.rand(neurons) + 0.1
    _rate_0 = np.random.rand(neurons)*0.5 + 0.5
    w = np.stack([np.log(_rate_0)+_beta, _beta*np.cos(_angle_0), _beta*np.sin(_angle_0)]).T # beta, phi_0 for theta modulation

    vm_disp = mdl.rate_models.vonMises_GLM(neurons, inv_link='identity')
    vm_disp.set_params(w)
    
    # sum for mu input
    comp_func = lambda x: ((x[0]*sample_bin)**(1/torch.exp(x[1])) - 0.5*(1/torch.exp(x[1])-1)) / sample_bin
    rate_model = mdl.parametrics.mixture_composition(1, [vm_rate, vm_disp], comp_func, inv_link='softplus')

    # CMP process output
    likelihood = mdl.likelihoods.COM_Poisson(sample_bin, neurons, 'softplus', dispersion_mapping=vm_disp)

    input_group = mdl.inference.input_group(1, [(None, None, None, 1)])
    input_group.set_XZ(covariates, track_samples, batch_size=track_samples, trials=trials)

    # NLL model
    glm = mdl.inference.VI_optimized(input_group, rate_model, likelihood)
    glm.validate_model(likelihood_set=False)
    return glm

    CMP with separate mu and nu tuning curves
    
CMP with separate mu and nu tuning curves
CMP with separate mu and nu tuning curves
def CMP_hdc(sample_bin, track_samples, covariates, neurons, trials=1):
    angle_0 = np.linspace(0, 2*np.pi, neurons+1)[:-1]
    beta = np.random.rand(neurons)*2.0 + 0.5
    rate_0 = np.random.rand(neurons)*4.0+4.0
    w = np.stack([np.log(rate_0), beta*np.cos(angle_0), beta*np.sin(angle_0)]).T 
    neurons = w.shape[0]
    vm_rate = mdl.rate_models.vonMises_GLM(neurons, inv_link='exp')
    vm_rate.set_params(w)
    _angle_0 = np.random.permutation(angle_0)
    _beta = 0.6*np.random.rand(neurons) + 0.1
    _rate_0 = np.random.rand(neurons)*0.5 + 0.5
    w = np.stack([np.log(_rate_0)+_beta, _beta*np.cos(_angle_0), _beta*np.sin(_angle_0)]).T 
    vm_disp = mdl.rate_models.vonMises_GLM(neurons, inv_link='identity')
    vm_disp.set_params(w)
    comp_func = lambda x: ((x[0]*sample_bin)**(1/torch.exp(x[1])) - 0.5*(1/torch.exp(x[1])-1)) / sample_bin
    rate_model = mdl.parametrics.mixture_composition(1, [vm_rate, vm_disp], comp_func, inv_link='softplus')
    likelihood = mdl.likelihoods.COM_Poisson(sample_bin, neurons, 'softplus', dispersion_mapping=vm_disp)
    input_group = mdl.inference.input_group(1, [(None, None, None, 1)])
    input_group.set_XZ(covariates, track_samples, batch_size=track_samples, trials=trials)
    glm = mdl.inference.VI_optimized(input_group, rate_model, likelihood)
    glm.validate_model(likelihood_set=False)
    return glm
def CMP_hdc ( sample_bin , track_samples , covariates , neurons , trials = 1 ) : angle_0 = np . linspace ( 0 , 2 * np . pi , neurons + 1 ) [ : - 1 ] beta = np . random . rand ( neurons ) * 2.0 + 0.5 rate_0 = np . random . rand ( neurons ) * 4.0 + 4.0 w = np . stack ( [ np . log ( rate_0 ) , beta * np . cos ( angle_0 ) , beta * np . sin ( angle_0 ) ] ) . T neurons = w . shape [ 0 ] vm_rate = mdl . rate_models . vonMises_GLM ( neurons , inv_link = 'exp' ) vm_rate . set_params ( w ) _angle_0 = np . random . permutation ( angle_0 ) _beta = 0.6 * np . random . rand ( neurons ) + 0.1 _rate_0 = np . random . rand ( neurons ) * 0.5 + 0.5 w = np . stack ( [ np . log ( _rate_0 ) + _beta , _beta * np . cos ( _angle_0 ) , _beta * np . sin ( _angle_0 ) ] ) . T vm_disp = mdl . rate_models . vonMises_GLM ( neurons , inv_link = 'identity' ) vm_disp . set_params ( w ) comp_func = lambda x : ( ( x [ 0 ] * sample_bin ) ** ( 1 / torch . exp ( x [ 1 ] ) ) - 0.5 * ( 1 / torch . exp ( x [ 1 ] ) - 1 ) ) / sample_bin rate_model = mdl . parametrics . mixture_composition ( 1 , [ vm_rate , vm_disp ] , comp_func , inv_link = 'softplus' ) likelihood = mdl . likelihoods . COM_Poisson ( sample_bin , neurons , 'softplus' , dispersion_mapping = vm_disp ) input_group = mdl . inference . input_group ( 1 , [ ( None , None , None , 1 ) ] ) input_group . set_XZ ( covariates , track_samples , batch_size = track_samples , trials = trials ) glm = mdl . inference . VI_optimized ( input_group , rate_model , likelihood ) glm . validate_model ( likelihood_set = False ) return glm
CMP with separate mu and nu tuning curves
CMP with separate mu and nu tuning curves
"""
    CMP with separate mu and nu tuning curves
    """ # Von Mises fields # beta, phi_0 for theta modulation # Dispersion tuning curve #angle_0 + 0.4*np.random.randn(neurons)#np.random.permutation(angle_0) # beta, phi_0 for theta modulation # sum for mu input # CMP process output # NLL model
sample_bin
track_samples
covariates
neurons
trials