Example #1
0
beta_cr = norm.ppf( Rel )
zc      = norm.ppf(Con)

d_s = fD_star(Rel)

D_lsm = np.zeros((len(N_ALL),M)); D_pi = np.zeros((len(N_ALL),M))
R_lsm = np.zeros((len(N_ALL),M)); R_pi = np.zeros((len(N_ALL),M))
M_lsm = np.zeros((len(N_ALL),M)); M_pi = np.zeros((len(N_ALL),M))
D_bv  = np.zeros((len(N_ALL),M)); D_psm = np.zeros((len(N_ALL),M))
R_bv  = np.zeros((len(N_ALL),M)); R_psm = np.zeros((len(N_ALL),M))
M_bv  = np.zeros((len(N_ALL),M)); M_psm = np.zeros((len(N_ALL),M))

M_samp = np.zeros((len(N_ALL),M))

t0 = time.time()
ut.print_progress(0,len(N_ALL)-1,bar_length=60)
for jnd in range(len(N_ALL)):
    for ind in range(M):
        X_dat = np.random.multivariate_normal(mean=[MU_CR,MU_A],
                                              cov=np.diag([TAU_CR**2,TAU_A**2]),
                                              size=N_ALL[jnd]).T
        mu_dat = np.mean(X_dat[0])
        s2_dat = np.var(X_dat[0])
        T_dat  = [mu_dat,s2_dat]

        ## Analytic BV approach
        B = mu_dat - fK_pc(Pop, Con, N_ALL[jnd]) * np.sqrt(s2_dat)
        D_bv[jnd,ind] = fD_bv(B,Rel)
        R_bv[jnd,ind] = fRel_eff(D_bv[jnd,ind])
        M_bv[jnd,ind] = (D_bv[jnd,ind]-d_s) / d_s
Example #2
0
    Theta[:, ind, 3] = chi2.rvs(df=M_ALL[ind] - 1,
                                size=repl) * TAU_Y**2 / (M_ALL[ind] - 1)

## Reserve space
D_ALL = np.zeros((repl, len(M_ALL), 2))
R_ALL_stress = np.zeros((repl, len(M_ALL)))
R_ALL_disp = np.zeros((repl, len(M_ALL)))
G_ALL = np.zeros((repl, len(M_ALL)))

## Main loop
# --------------------------------------------------
## Infinite-sample 'true' solution
fs_true, ds_true = opt_run(THETA, 1e32)

t0 = time.time()
ut.print_progress(0, repl - 1, bar_length=60)
for ind in range(repl):
    for jnd in range(len(M_ALL)):
        theta = Theta[ind, jnd]

        fs, ds = opt_run(theta, M_ALL[jnd])

        D_ALL[ind, jnd] = ds
        R_ALL_stress[ind, jnd] = R_stress(D_ALL[ind, jnd])
        R_ALL_disp[ind, jnd] = R_disp(D_ALL[ind, jnd])
        G_ALL[ind, jnd] = (fs - fs_true) / fs_true

    ut.print_progress(ind, repl - 1, bar_length=60)
t1 = time.time()

## Post-process
Example #3
0
zc = norm.ppf(Con)

d_s = fD_star(Rel)

D_lsm_mc = np.zeros((len(N_ALL), M, len(L_ALL)))
R_lsm_mc = np.zeros((len(N_ALL), M, len(L_ALL)))
M_lsm_mc = np.zeros((len(N_ALL), M, len(L_ALL)))
D_pri_mc = np.zeros((len(N_ALL), M, len(L_ALL)))
R_pri_mc = np.zeros((len(N_ALL), M, len(L_ALL)))
M_pri_mc = np.zeros((len(N_ALL), M, len(L_ALL)))
D_mip_mc = np.zeros((len(N_ALL), M, len(L_ALL)))
R_mip_mc = np.zeros((len(N_ALL), M, len(L_ALL)))
M_mip_mc = np.zeros((len(N_ALL), M, len(L_ALL)))

t0 = time.time()
ut.print_progress(0, len(N_ALL), bar_length=60)
for jnd in range(len(N_ALL)):
    for ind in range(M):
        ## Sampling simulation
        X_dat = np.random.multivariate_normal(mean=[MU_CR, MU_A],
                                              cov=np.diag(
                                                  [TAU_CR**2, TAU_A**2]),
                                              size=N_ALL[jnd]).T
        mu_dat = np.mean(X_dat[0])
        s2_dat = np.var(X_dat[0])
        T_dat = [mu_dat, s2_dat]

        # Common random numbers
        Z_sim = np.random.multivariate_normal(np.zeros(2),
                                              cov=np.eye(2),
                                              size=max(L_ALL))