Exemple #1
0
                                      num_steps_per_sample=L,
                                      step_size=step_size,
                                      burn=burn,
                                      tau_priors=tau_priors,
                                      tau_likes=tau_likes,
                                      device=device,
                                      n_params_single=n_params_single,
                                      pde=pde,
                                      pinns=pinns,
                                      epochs=epochs)

pred_list, log_prob_list = util.predict_model_bpinns(
    nets,
    params_hmc,
    data_val,
    model_loss=model_loss,
    tau_priors=tau_priors,
    tau_likes=tau_likes,
    n_params_single=n_params_single,
    pde=pde)

print('\nExpected validation log probability: {:.3f}'.format(
    torch.stack(log_prob_list).mean()))

print('\nThe exact values of single parameters: {}'.format(exact_single))
params_single = torch.stack(params_hmc)[:, :n_params_single].cpu().numpy()
print('The means of single parameters: {}'.format(
    np.exp(params_single).mean(0)))
print('The variances of single parameters: {}'.format(
    np.exp(params_single).std(0)))
Exemple #2
0
params_init_val = None

params_hmc = util.sample_model_bpinns(nets,
                                      data,
                                      model_loss=model_loss,
                                      step_size=step_size,
                                      device=device,
                                      pde=True,
                                      pinns=True,
                                      epochs=epochs,
                                      params_init_val=params_init_val)

pred_list, log_prob_list = util.predict_model_bpinns(nets,
                                                     params_hmc,
                                                     data_val,
                                                     model_loss=model_loss,
                                                     pde=True)

print('\nExpected validation log probability: {:.3f}'.format(
    torch.stack(log_prob_list).mean()))

pred_list_u = pred_list[0].cpu().numpy()
pred_list_U = pred_list[1].cpu().numpy()
pred_list_A = pred_list[2].cpu().numpy()
pred_list_Y = pred_list[3].cpu().numpy()

# plot

wxi = data_val['wxi'].cpu().numpy()
x = data_val['x'].cpu().numpy()