Exemple #1
0
def test_cal_method1(input2, input3, input4, input5, input6, expectation):
    with expectation:
        assert calibrator(emu=emu_test,
                          y=input2,
                          x=input3,
                          thetaprior=input4,
                          method=input5,
                          yvar=input6) is not None
Exemple #2
0
def test_cal_MLcal(input1, input2, expectation):
    with expectation:
        assert calibrator(emu=input1,
                          y=y,
                          x=x_std,
                          thetaprior=prior_balldrop,
                          method='directbayes',
                          yvar=obsvar,
                          args=input2) is not None
Exemple #3
0
def test_cal_emu(input1, input2, input3, input4, input5, expectation):
    with expectation:
        assert calibrator(emu=input1,
                          y=input2,
                          x=input3,
                          thetaprior=input4,
                          method='directbayes',
                          yvar=input5,
                          args=args1) is not None
Exemple #4
0
def test_cal_predict(input1, expectation):
    cal_test = calibrator(emu=emulator_f_1,
                          y=y,
                          x=x_std,
                          thetaprior=prior_balldrop,
                          method='directbayes',
                          yvar=obsvar,
                          args=args2)
    with expectation:
        assert cal_test.predict(x=input1) is not None
Exemple #5
0
def test_call(expectation):
    cal = calibrator(emu=emu_test,
                     y=y,
                     x=x,
                     thetaprior=priorphys_lin,
                     method='directbayes',
                     yvar=obsvar,
                     args=args1)
    with expectation:
        assert cal(x=x) is not None
Exemple #6
0
def test_call(expectation):
    cal = calibrator(emu=emulator_f_1,
                     y=y,
                     x=x_std,
                     thetaprior=prior_balldrop,
                     method='directbayes',
                     yvar=obsvar,
                     args=args2)
    pred_test = cal.predict(x=x_std)
    with expectation:
        assert pred_test() is not None
Exemple #7
0
def test_prediction_thetalpdf(cmdopt2):
    emu = emulator(x=x, theta=theta, f=f, method='PCGPwM')
    cal = calibrator(emu=emu,
                     y=y,
                     x=x,
                     thetaprior=prior_balldrop,
                     method=cmdopt2,
                     yvar=obsvar)
    try:
        cal.theta.lpdf()
    except:
        pytest.fail('theta.lpdf() functionality does not exist in the method')
Exemple #8
0
def test_supplement_cal(expectation):
    emu = emulator(x=x, theta=theta, f=f, method='PCGPwM')
    args1 = {
        'theta0': np.array([[0, 9]]),
        'numsamp': 50,
        'stepType': 'normal',
        'stepParam': [0.1, 1]
    }
    cal = calibrator(emu=emu,
                     y=y,
                     x=x,
                     thetaprior=priorphys_lin,
                     method='directbayes',
                     yvar=obsvar,
                     args=args1)
    with expectation:
        assert emu.supplement(size=10, cal=cal) is not None
Exemple #9
0
    axs[3].plot(xrep[0:21].reshape(21), median, color='black')
    axs[3].fill_between(xrep[0:21].reshape(21), lower, upper, color='grey')
    axs[3].plot(xrep, y, 'ro', markersize=5, color='red')

    plt.show()


# %%
obsvar = np.maximum(0.2 * y, 0.1)
# Fit a calibrator with emulator 1 via via method = 'directbayes' and 'sampler' = 'metropolis_hastings'
cal_1 = calibrator(emu=emulator_1,
                   y=y,
                   x=xrep_std,
                   thetaprior=prior_balldrop,
                   method='directbayes',
                   yvar=obsvar,
                   args={
                       'theta0': np.array([[0.4]]),
                       'numsamp': 1000,
                       'stepType': 'normal',
                       'stepParam': [0.3]
                   })

plot_pred(x_std, xrep, y, cal_1, theta_range)

# %%
# Fit a calibrator via method = 'directbayeswoodbury' and 'sampler' : 'LMC'
cal_2 = calibrator(emu=emulator_1,
                   y=y,
                   x=xrep_std,
                   thetaprior=prior_balldrop,
                   method='directbayeswoodbury',
Exemple #10
0

# %%
obsvar = np.maximum(0.2 * real_data, 5)

# %%
# Calibrator 1
cal_1 = calibrator(
    emu=emulator_1,
    y=real_data,
    x=x,
    thetaprior=prior_covid,
    method='directbayes',
    yvar=obsvar,
    args={
        'theta0':
        np.array([[2, 4, 4, 1.875, 14, 18, 20, 14, 13, 12]]),
        'numsamp':
        100,
        'stepType':
        'normal',
        'stepParam':
        np.array([0.01, 0.01, 0.01, 0.01, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03])
    })

plot_pred_interval(cal_1)

# %%
# Calibrator 2
cal_2 = calibrator(emu=emulator_1,
                   y=real_data,
Exemple #11
0
        upper = np.percentile(rndm_m[:, inds], 97.5, axis=0)
        lower = np.percentile(rndm_m[:, inds], 2.5, axis=0)
        axs.fill_between(xv[inds, 0], lower, upper, color='grey', alpha=0.25)
        axs.plot(xv[inds, 0], y[inds], 'ro', markersize=5, color='red')
    return (axs)


# %% [markdown]
# ### Calibrators for Model 1

# %%
cal_grav_1 = calibrator(emu=emu_grav,
                        y=y,
                        x=x,
                        thetaprior=priorphys_grav,
                        method='directbayes',
                        yvar=obsvar,
                        args={
                            'stepType': 'normal',
                            'stepParam': np.array([1])
                        })

# %%
cal_grav_2 = calibrator(emu=emu_grav,
                        y=y,
                        x=x,
                        thetaprior=priorphys_grav,
                        method='directbayes',
                        yvar=obsvar,
                        args={'sampler': 'LMC'})

# %%
Exemple #12
0
    rndm_m = post.rnd(s=1000)
    upper = np.percentile(rndm_m, 97.5, axis=0)
    lower = np.percentile(rndm_m, 2.5, axis=0)
    median = np.percentile(rndm_m, 50, axis=0)

    axs[3].plot(xrep[0:21].reshape(21), median, color='black')
    axs[3].fill_between(xrep[0:21].reshape(21), lower, upper, color='grey')
    axs[3].plot(xrep, y, 'ro', markersize=5, color='red')

    plt.show()


# %%
obsvar = np.maximum(0.2 * y, 0.1)

# Fit a calibrator with emulator 1 via via method = 'directbayes' and 'sampler' = 'metropolis_hastings'
cal_1 = calibrator(emu=emulator_1,
                   y=y,
                   x=x_std,
                   thetaprior=prior_balldrop,
                   method='directbayes',
                   yvar=obsvar,
                   args={
                       'theta0': np.array([[0.4]]),
                       'numsamp': 1000,
                       'stepType': 'normal',
                       'stepParam': [0.3]
                   })

plot_pred(x_std, x, y, cal_1, theta_range)