Пример #1
0
    def test_bootstrap(self):
        objval, thetavals = self.pest.theta_est()

        num_bootstraps = 10
        theta_est = self.pest.bootstrap(num_bootstraps)

        num_samples = theta_est['samples'].apply(len)
        self.assertTrue(len(theta_est.index), 10)
        self.assertTrue(num_samples.equals(pd.Series([6] * 10)))

        filename = os.path.abspath(os.path.join(testdir, 'pairwise.png'))
        if os.path.isfile(filename):
            os.remove(filename)
        graphics.pairwise_plot(theta_est, filename=filename)
        #self.assertTrue(os.path.isfile(filename))

        filename = os.path.abspath(
            os.path.join(testdir, 'pairwise_bootstrap.png'))
        if os.path.isfile(filename):
            os.remove(filename)
        graphics.pairwise_bootstrap_plot(theta_est,
                                         thetavals,
                                         0.8,
                                         filename=filename)
Пример #2
0
    fsfilename = "examples.contrib.projects.mea_simple.parameter_estimate.mea_estimate_pysp"

    pest = parmest.ParmEstimator(fsfilename, "pysp_instance_creation_callback",
                                 "SecondStageCost", range(1, S + 1), thetalist)

    mpii = mpiu.MPIInterface()  # works with, or without, mpi

    objval, thetavals = pest.theta_est()
    if mpii.rank in [0, None]:
        print("objective value=", str(objval))
        for t in thetavals:
            print(t, "=", thetavals[t])
        print("====")

    ### Parameter estimation with bootstrap
    np.random.seed(1134)  # make it reproducible
    num_bootstraps = 10
    bootstrap_theta = pest.bootstrap(num_bootstraps)
    if mpii.rank in [0, None]:
        print("Bootstrap:")
        print(bootstrap_theta)
        grph.pairwise_bootstrap_plot(bootstrap_theta,
                                     thetavals,
                                     0.8,
                                     filename="MEA_boot.png")

    ### Make the LR plot
    # SEE = pest.likelihood_ratio(0.8)
    # grph.pairwise_likelihood_ratio_plot(SSE, objval, 0.8, S, "MEA_LR.png")
Пример #3
0
objval, thetavals = pest.theta_est()

if mpii.rank in [0, None]:
    print("objective value=", str(objval))
    print("theta-star=", str(thetavals))

### Parameter estimation with bootstrap
alpha = 0.8
num_bootstraps = 10
bootstrap_theta = pest.bootstrap(num_bootstraps)
if mpii.rank in [0, None]:
    print("Bootstrap:")
    print(bootstrap_theta)
    grph.pairwise_plot(bootstrap_theta, filename="RB.png")
    grph.pairwise_bootstrap_plot(bootstrap_theta,
                                 thetavals,
                                 alpha,
                                 filename="RB_boot.png")

### Likelihood ratio
alpha = 0.8
search_ranges = {}
search_ranges["asymptote"] = np.arange(10, 30, 2)  # np.arange(10, 30, 0.01)
search_ranges["rate_constant"] = np.arange(0, 1.5,
                                           0.1)  # np.arange(0, 1.5, 0.005)
SSE = pest.likelihood_ratio(search_ranges=search_ranges)
if mpii.rank in [0, None]:
    print("Likelihood Ratio:")
    print(SSE)
    grph.pairwise_likelihood_ratio_plot(SSE,
                                        objval,
                                        alpha,