Exemplo n.º 1
0
l2_norm_vb_stan_means_i = compute_l2_norm_means(params_vb_stan_means, W_mean)
l2_norm_vb_stan_sigmas_i = compute_l2_norm_Sigmas(params_vb_stan_std, W_cov)
l2_norm_vb_stan_means = np.repeat(l2_norm_vb_stan_means_i, itt_max)
l2_norm_vb_stan_sigmas = np.repeat(l2_norm_vb_stan_sigmas_i, itt_max)
warmup = start_swa_iter
if start_swa_iter % 2 == 1:
    warmup = warmup + 1

if warmup < 3000:
    chains_warmup = max(start_swa_iter + 100, int(itt_max / 2))

chains = vi_params_collapsed
chains_clr2 = vi_params_collapsed2
chains2 = vi_params_collapsed[:, chains_warmup:, :]
R_hat = compute_R_hat_fn(chains[1:, :, :], chains_warmup)
print(R_hat)
R_hat2 = compute_R_hat_fn(chains_clr2[1:, :, :], chains_warmup)
print(R_hat2)

if debug_mode:
    print(W_mean)
    print(np.diag(W_sigma))
    print(params_hmc_mean)
    print(params_hmc_sigmas)
    print(params_vb_stan_means)
    print(params_vb_stan_std)
    print(means_vb_clr)
    print(sigmas_vb_clr)
    print(means_vb_clr2)
    print(sigmas_vb_clr2)
Exemplo n.º 2
0
            #q_swa = stats.norm.pdf(samples_vb_swa, means_vb_swa, sigmas_vb_swa)
            #logp_swa = np.array([fit_hmc.log_prob(s) for s in samples_vb_swa])
            #log_iw_swa = logp_swa - np.sum(np.log(q_swa), axis=1)
            #psis_lw_swa, K_hat_swa = psislw(log_iw_swa.T)
            #print('K hat statistic for SWA')
            #print(K_hat_swa)
            #K_hat_swa_list[j,n] = K_hat_swa
            # VB-CLR
            #
            print('hii')
            #plt.figure(figsize=(20,6))

    chains_clr2 = vi_params_collapsed2
    #chains2 = vi_params_collapsed[:, warmup:, :]
    #chains_clr2_noisy = add_noise_chains(chains_clr2, sd=0.1)
    _, R_hat2 = compute_R_hat_fn(chains_clr2[:, :, :], warmup)
    R_hat_list_mean_max.append(np.max(R_hat2[:K]))
    R_hat_list_sigma_max.append(np.max(R_hat2[K:]))
    R_hat_list_mean_median.append(np.median(R_hat2[:K]))
    R_hat_list_sigma_median.append(np.median(R_hat2[K:]))

fit_vb_samples = np.array(fit_vb['sampler_params']).T
stan_vb_w = fit_vb_samples[:, 0:K]
params_vb_stan_means = np.mean(stan_vb_w, axis=0)
params_vb_stan_std = np.std(stan_vb_w, axis=0)
params_vb_stan_sq = np.mean(stan_vb_w**2, axis=0)

l2_norm_vb_stan_i = compute_l2_norm(params_vb_stan_means,
                                    params_vb_stan_std, params_hmc_mean,
                                    np.diag(params_hmc_sigmas))
l2_norm_vb = np.repeat(l2_norm_vb_stan_i, itt_max)