예제 #1
0
        pickle.dump(sampler1, f)

mcmc_samples_hidden_in = sampler1.get_samples_alt(prior_obj_name="hidden_in",
                                                  permuted=False)
samples = mcmc_samples_hidden_in["samples"]
w_indices = mcmc_samples_hidden_in["indices_dict"]["w"]
sigma2_indices = mcmc_samples_hidden_in["indices_dict"]["sigma2"]

#samples[:,:,sigma2_indices] = numpy.exp(samples[:,:,sigma2_indices])

posterior_mean_sigma2 = numpy.mean(samples[:, :, sigma2_indices].reshape(
    -1, len(sigma2_indices)),
                                   axis=0)

print("sigma2 diagnostics")
print(diagnostics_stan(samples[:, :, sigma2_indices]))

print("posterior mean sigma2 {}".format(posterior_mean_sigma2))
print("posterior sd sigma2 {}".format(numpy.std(samples[:, :,
                                                        sigma2_indices])))

#print(mcmc_samples_beta["indices_dict"])
print("overall diagnostics")
full_mcmc_tensor = get_params_mcmc_tensor(sampler=sampler1)

print(get_short_diagnostics(full_mcmc_tensor))

#print(mcmc_samples_beta["indices_dict"])

out = sampler1.get_diagnostics(permuted=False)
예제 #2
0
hidden_in_tau_indices = mcmc_samples_hidden_in["indices_dict"]["tau"]
hidden_in_w_indices = mcmc_samples_hidden_in["indices_dict"]["w"]
hidden_out_w_indices = mcmc_samples_hidden_out["indices_dict"]["w"]

print(samples[:, :, hidden_in_tau_indices].shape)
#print(numpy.mean(samples[3,400:500,hidden_in_tau_indices]))

#print(samples.shape)
posterior_mean_hidden_in_tau = numpy.mean(
    samples[:, :, hidden_in_tau_indices].reshape(-1,
                                                 len(hidden_in_tau_indices)),
    axis=0)

print("diagnostics for tau")

print(diagnostics_stan(samples[:, :, hidden_in_tau_indices]))

print("posterior mean tau {}".format(posterior_mean_hidden_in_tau))

print("overall diagnostics")
full_mcmc_tensor = get_params_mcmc_tensor(sampler=sampler1)

print(get_short_diagnostics(full_mcmc_tensor))

#print(mcmc_samples_beta["indices_dict"])

out = sampler1.get_diagnostics(permuted=False)

print("num divergences after warmup")
processed_diag = process_diagnostics(out, name_list=["divergent"])
예제 #3
0
#exit()
#samples[:,:,hidden_in_sigma2_indices] = numpy.exp(samples[:,:,hidden_in_sigma2_indices])

posterior_mean_hidden_in_sigma2 = numpy.mean(
    samples[:, :,
            hidden_in_sigma2_indices].reshape(-1,
                                              len(hidden_in_sigma2_indices)),
    axis=0)
posterior_median_hidden_in_sigma2 = numpy.median(
    samples[:, :,
            hidden_in_sigma2_indices].reshape(-1,
                                              len(hidden_in_sigma2_indices)),
    axis=0)
print("diagnostics sigma2")

print(diagnostics_stan(samples[:, :, hidden_in_sigma2_indices]))

print("posterior mean sigma2 {}".format(posterior_mean_hidden_in_sigma2))
print("posterior median sigma2 {}".format(posterior_median_hidden_in_sigma2))
#print(mcmc_samples_beta["indices_dict"])

full_mcmc_tensor = get_params_mcmc_tensor(sampler=sampler1)

print(get_short_diagnostics(full_mcmc_tensor))

out = sampler1.get_diagnostics(permuted=False)

print("divergent")
processed_diag = process_diagnostics(out, name_list=["divergent"])

print(processed_diag.sum(axis=1))
예제 #4
0
samples = mcmc_samples_beta["samples"]
w_indices = mcmc_samples_beta["indices_dict"]["w"]
tau_indices = mcmc_samples_beta["indices_dict"]["tau"]

print(samples.shape)
posterior_mean = numpy.mean(samples[:, :,
                                    w_indices].reshape(-1, len(w_indices)),
                            axis=0)
print(posterior_mean[:non_zero_num_p])
print(true_beta[:non_zero_num_p])

posterior_mean_tau = numpy.mean(samples[:, :, tau_indices].reshape(
    -1, len(tau_indices)),
                                axis=0)

print(diagnostics_stan(samples[:, :, tau_indices]))

print("posterior mean tau {}".format(posterior_mean_tau))

print("overall diagnostics")
full_mcmc_tensor = get_params_mcmc_tensor(sampler=sampler1)

print(get_short_diagnostics(full_mcmc_tensor))

#print(mcmc_samples_beta["indices_dict"])

out = sampler1.get_diagnostics(permuted=False)

print("num divergences after warmup")
processed_diag = process_diagnostics(out, name_list=["divergent"])
예제 #5
0
    "par_type": "fast"
}
#
adapt_cov_arguments = [
    adapt_cov_default_arguments(
        par_type="slow",
        dim=V_hierarchical_logistic_gibbs(
            precision_type="torch.DoubleTensor").get_model_dim())
]
dual_args_list = [ep_dual_metadata_argument]
other_arguments = other_default_arguments()
#tune_settings_dict = tuning_settings([],[],[],[])
tune_settings_dict = tuning_settings(dual_args_list, [], adapt_cov_arguments,
                                     other_arguments)
tune_dict = tuneinput_class(input_dict).singleton_tune_dict()

sampler1 = mcmc_sampler(tune_dict=tune_dict,
                        mcmc_settings_dict=mcmc_meta,
                        tune_settings_dict=tune_settings_dict)

sampler1.start_sampling()

samples = sampler1.get_samples(permuted=False)

transformed_samples = samples
transformed_samples[:, :, 7] = numpy.exp(samples[:, :, 7])
out = diagnostics_stan(mcmc_samples_tensor=transformed_samples)

print(numpy.mean(transformed_samples[:, :, 7]))
print(numpy.var(transformed_samples[:, :, 7]))
print(out)