scripts/model_utils.py
def LVM_pred_ll(model, z_dims, mode, cov_used, cv_set, f_neuron, v_neuron, eval_cov_MC=1, eval_ll_MC=100, eval_ll_mode='GH', 
                cov_MC=16, ll_MC=1, ll_mode='MC', beta=1.0, beta_z=1.0, bound='ELBO', max_iters=3000):
    """
    Compute the predictive log likelihood (ELBO).
    """
    ftrain, fcov, vtrain, vcov = cv_set
    time_steps = vtrain.shape[-1]
    
    vcov = cov_used(mode, vcov)
    
    model.inputs.set_XZ(vcov, time_steps, batch_size=time_steps)
    model.likelihood.set_Y(vtrain, batch_size=time_steps)
    
    # fit
    sch = lambda o: optim.lr_scheduler.MultiplicativeLR(o, lambda e: 0.9)
    opt_tuple = (optim.Adam, 100, sch)
    opt_lr_dict = {'default': 0}
    for z_dim in z_dims:
        opt_lr_dict['inputs.lv_mu_{}'.format(z_dim)] = 1e-2
        opt_lr_dict['inputs.lv_std_{}'.format(z_dim)] = 1e-3

    model.set_optimizers(opt_tuple, opt_lr_dict)

    annealing = lambda x: 1.0#min(1.0, 0.002*x)
    losses = model.fit(max_iters, neuron=f_neuron, loss_margin=-1e0, margin_epochs=100, ll_mode=ll_mode, 
                       kl_anneal_func=annealing, cov_samples=cov_MC, ll_samples=ll_MC)
    

    return -model.objective(0, neuron=v_neuron, cov_samples=eval_cov_MC, ll_mode=eval_ll_mode, bound=bound, 
                            beta=beta, beta_z=beta_z, ll_samples=eval_ll_MC).data.cpu().numpy(), losses

    Compute the predictive log likelihood (ELBO).
    
Compute the predictive log likelihood (ELBO).
Compute the predictive log likelihood ( ELBO ) .
def LVM_pred_ll(model, z_dims, mode, cov_used, cv_set, f_neuron, v_neuron, eval_cov_MC=1, eval_ll_MC=100, eval_ll_mode='GH', 
                cov_MC=16, ll_MC=1, ll_mode='MC', beta=1.0, beta_z=1.0, bound='ELBO', max_iters=3000):
    ftrain, fcov, vtrain, vcov = cv_set
    time_steps = vtrain.shape[-1]
    vcov = cov_used(mode, vcov)
    model.inputs.set_XZ(vcov, time_steps, batch_size=time_steps)
    model.likelihood.set_Y(vtrain, batch_size=time_steps)
    sch = lambda o: optim.lr_scheduler.MultiplicativeLR(o, lambda e: 0.9)
    opt_tuple = (optim.Adam, 100, sch)
    opt_lr_dict = {'default': 0}
    for z_dim in z_dims:
        opt_lr_dict['inputs.lv_mu_{}'.format(z_dim)] = 1e-2
        opt_lr_dict['inputs.lv_std_{}'.format(z_dim)] = 1e-3
    model.set_optimizers(opt_tuple, opt_lr_dict)
    annealing = lambda x: 1.0
    losses = model.fit(max_iters, neuron=f_neuron, loss_margin=-1e0, margin_epochs=100, ll_mode=ll_mode, 
                       kl_anneal_func=annealing, cov_samples=cov_MC, ll_samples=ll_MC)
    return -model.objective(0, neuron=v_neuron, cov_samples=eval_cov_MC, ll_mode=eval_ll_mode, bound=bound, 
                            beta=beta, beta_z=beta_z, ll_samples=eval_ll_MC).data.cpu().numpy(), losses
def LVM_pred_ll ( model , z_dims , mode , cov_used , cv_set , f_neuron , v_neuron , eval_cov_MC = 1 , eval_ll_MC = 100 , eval_ll_mode = 'GH' , cov_MC = 16 , ll_MC = 1 , ll_mode = 'MC' , beta = 1.0 , beta_z = 1.0 , bound = 'ELBO' , max_iters = 3000 ) : ftrain , fcov , vtrain , vcov = cv_set time_steps = vtrain . shape [ - 1 ] vcov = cov_used ( mode , vcov ) model . inputs . set_XZ ( vcov , time_steps , batch_size = time_steps ) model . likelihood . set_Y ( vtrain , batch_size = time_steps ) sch = lambda o : optim . lr_scheduler . MultiplicativeLR ( o , lambda e : 0.9 ) opt_tuple = ( optim . Adam , 100 , sch ) opt_lr_dict = { 'default' : 0 } for z_dim in z_dims : opt_lr_dict [ 'inputs.lv_mu_{}' . format ( z_dim ) ] = 1e-2 opt_lr_dict [ 'inputs.lv_std_{}' . format ( z_dim ) ] = 1e-3 model . set_optimizers ( opt_tuple , opt_lr_dict ) annealing = lambda x : 1.0 losses = model . fit ( max_iters , neuron = f_neuron , loss_margin = - 1e0 , margin_epochs = 100 , ll_mode = ll_mode , kl_anneal_func = annealing , cov_samples = cov_MC , ll_samples = ll_MC ) return - model . objective ( 0 , neuron = v_neuron , cov_samples = eval_cov_MC , ll_mode = eval_ll_mode , bound = bound , beta = beta , beta_z = beta_z , ll_samples = eval_ll_MC ) . data . cpu ( ) . numpy ( ) , losses
Compute the predictive log likelihood (ELBO).
Compute the predictive log likelihood ( ELBO ) .
"""
    Compute the predictive log likelihood (ELBO).
    """ # fit #min(1.0, 0.002*x)
model
z_dims
mode
cov_used
cv_set
f_neuron
v_neuron
eval_cov_MC
eval_ll_MC
eval_ll_mode
cov_MC
ll_MC
ll_mode
beta
beta_z
bound
max_iters