Esempio n. 1
0
        X_s_tmp = X[:, idx] - np.sqrt(tau_sqd) * norm.rvs(size=n_s)
        lower_limit = R[idx]**phi
        X_s_tmp[X_s_tmp < lower_limit] = lower_limit + 0.01
        Z[:, idx] = norm.ppf(1 - 1 / (X_s_tmp / (R[idx]**phi)))

    # import matplotlib.pyplot as plt
    # plt.scatter(Stations_local[:,0], Stations_local[:,1],c=Z[:,rank], marker='o', alpha=0.5, cmap='jet')
    # plt.colorbar()
    # plt.title("Z onetime");

    v_q = np.repeat(2.4**2, n_s)
    for idx in np.arange(n_t):
        tmp = utils.Z_update_onetime(Y[:, idx], X[:, idx], R[idx], Z[:, idx],
                                     cen[:, idx], cen_above[:,
                                                            idx], prob_below,
                                     prob_above, tau_sqd, phi, gamma, Loc[:,
                                                                          idx],
                                     Scale[:, idx], Shape[:, idx], xp, surv_p,
                                     den_p, thresh_X, thresh_X_above, Cor,
                                     cholesky_inv, v_q, random_generator)

    Y_onetime = Y[:, rank]
    X_onetime = X[:, rank]
    R_onetime = R[rank]
    X_s_onetime = (R_onetime**phi) * utils.norm_to_Pareto(Z[:, rank])
    Z_onetime = Z[:, rank]

    # Initial trace objects
    Z_1t_accept = np.zeros(n_s)
    R_accept = 0
    Z_1t_trace = np.empty((n_s, n_updates_thinned))
    Z_1t_trace[:] = np.nan
n_updates = 5000
Z_trace = np.empty((3, n_updates))

Z_new = np.empty(n_s)
Z_new[:] = Z[:, t_chosen]
K = 10
k = 3
r_opt = .234
c_0 = 10
c_1 = .8
accept = np.zeros(n_s)
Sigma_m = np.repeat(np.sqrt(tau_sqd), n_s)
for idx in np.arange(n_updates):
    tmp = utils.Z_update_onetime(
        Y[:, t_chosen], X[:, t_chosen], R[t_chosen], Z_new, cen[:, t_chosen],
        cen_above[:, t_chosen], prob_below, prob_above, tau_sqd, phi, gamma,
        Loc[:, t_chosen], Scale[:, t_chosen], Shape[:, t_chosen], xp, surv_p,
        den_p, thresh_X, thresh_X_above, V, d, Sigma_m, random_generator)
    Z_trace[:, idx] = np.array([Z_new[4], Z_new[6], Z_new[7]])
    accept = accept + tmp

    if (idx % K) == 0:
        print('Finished ' + str(idx) + ' out of ' + str(n_updates) +
              ' iterations ')
        gamma2 = 1 / ((idx / K) + k)**(c_1)
        gamma1 = c_0 * gamma2
        R_hat = accept / K
        Sigma_m = np.exp(np.log(Sigma_m) + gamma1 * (R_hat - r_opt))
        accept[:] = 0

plt.plot(np.arange(n_updates), Z_trace[0, :], linestyle='solid')