Example #1
0
    def setUp(self):
        self.tempdirpath = tempfile.mkdtemp()
        # assuming we are in the test subdir
        import pyomo.contrib.parmest.examples.semibatch as sbroot
        p = str(sbroot.__path__)
        l = p.find("'")
        r = p.find("'", l + 1)
        sbrootpath = p[l + 1:r]

        for file in glob.glob(sbrootpath + os.sep + 'exp*.out'):
            shutil.copy(file, self.tempdirpath)
        self.save_cwd = os.getcwd()
        os.chdir(self.tempdirpath)
        num_experiments = 10
        exp_list = range(1, num_experiments +
                         1)  # callback uses one-based file names
        thetalist = ['k1', 'k2', 'E1', 'E2']

        np.random.seed(1134)

        from pyomo.contrib.parmest.examples.semibatch.semibatch import pysp_instance_creation_callback
        # non-string callback specification
        self.pest = parmest.ParmEstimator(None,
                                          pysp_instance_creation_callback,
                                          "SecondStageCost", exp_list,
                                          thetalist)
Example #2
0
    def setUp(self):
        self.thetalist = ['asymptote', 'rate_constant']
        self.num_samples = 6
        self.sample_list = range(self.num_samples)
        self.fsfilename = \
            "pyomo.contrib.parmest.examples.rooney_biegler.rooney_biegler"
        self.callback_funcname = "instance_creation_callback"
        experiment_data = pd.DataFrame(data=[[1, 8.3], [2, 10.3], [3, 19.0],
                                             [4, 16.0], [5, 15.6], [6, 19.8]],
                                       columns=['hour', 'y'])

        self.pest = parmest.ParmEstimator(self.fsfilename,
                                          self.callback_funcname,
                                          "SecondStageCost",
                                          self.sample_list,
                                          self.thetalist,
                                          cb_data=experiment_data)
Example #3
0
# prepare for the parmest object construction
experiment_data = pd.DataFrame(data=[[1, 8.3], [2, 10.3], [3, 19.0], [4, 16.0],
                                     [5, 15.6], [6, 19.8]],
                               columns=['hour', 'y'])
num_samples = 6
sample_list = list(range(num_samples))  # callback uses zero-based indexes
thetalist = ['asymptote', 'rate_constant']
fsfilename = "rooney_biegler"

np.random.seed(1134)

# Generate parmest object
pest = parmest.ParmEstimator(fsfilename,
                             "instance_creation_callback",
                             "SecondStageCost",
                             sample_list,
                             thetalist,
                             cb_data=experiment_data)

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

### Parameter estimation with entire data set
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
Example #4
0
# parmest example using mea

import numpy as np
import pyomo.contrib.parmest.parmest as parmest
import pyomo.contrib.parmest.mpi_utils as mpiu
import pyomo.contrib.parmest.graphics as grph

if __name__ == "__main__":

    thetalist = ['pp.Keq_a[1]', 'pp.Keq_a[2]']
    S = 4

    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]:
Example #5
0
if __name__ == '__main__':
    # Very simple, with just theta estimation and bootstrap
    # Not done in parallel.
    import pyomo.contrib.parmest.parmest as parmest
    import pyomo.contrib.parmest.graphics as grph

    # prepare for the parmest object construction
    num_samples = 6
    sample_list = list(range(num_samples))
    thetalist = ['asymptote', 'rate_constant']

    np.random.seed(1134)

    # Generate parmest object using the callback function itself,
    #   rather than a module and a function name
    pest = parmest.ParmEstimator(None, pysp_instance_creation_callback,
                                 "SecondStageCost", sample_list, thetalist)

    ### Parameter estimation with entire data set
    objval, thetavals = pest.theta_est()

    print("objective value=", str(objval))
    print("theta-star=", str(thetavals))

    ### Parameter estimation with bootstrap
    num_bootstraps = 10
    bootstrap_theta = pest.bootstrap(num_bootstraps)
    print("Bootstrap:")
    print(bootstrap_theta)
    grph.pairwise_bootstrap_plot(bootstrap_theta,
                                 thetavals,
                                 0.8,