Exemplo n.º 1
0
def generate_input_data(n_simulations, method = "random"):
    "Generate random points x1 and x2 for evaluating the multivalued 2D Branin function"
    
    n_simulations = int(n_simulations)
    assert(n_simulations > 0)
    assert method == "random" or method == "lhd"
    
    if method == "random":
        ed = MonteCarloDesign([uniform(loc = -5., scale = 15.).ppf, uniform(loc = 0., scale = 15.).ppf])
    elif method == "lhd":
        ed = LatinHypercubeDesign([uniform(loc = -5., scale = 15.).ppf, uniform(loc = 0., scale = 15.).ppf])
    inputs = ed.sample(n_simulations)
    return inputs
Exemplo n.º 2
0
def run_model(n_simulations, n_testing):
    "Generate training data, fit emulator, and test model accuracy on random points, returning RMSE"

    # run MICE Model
    print('running MICE')
    ed = LatinHypercubeDesign(design_space)

    n_init = 5

    md = MICEDesign(ed,
                    f,
                    n_samples=n_simulations - n_init,
                    n_init=n_init,
                    n_cand=100)

    md.run_sequential_design()

    inputs_mice = md.get_inputs()
    targets_mice = md.get_targets()

    print('fitting GPs')

    gp_mice = GaussianProcess(inputs_mice, np.squeeze(targets_mice))
    gp_mice = fit_GP_MAP(gp_mice)

    # run LHD model
    inputs, targets = generate_training_data(n_simulations)

    gp = GaussianProcess(inputs, targets)
    gp = fit_GP_MAP(gp)

    print("making predictions")

    testing, test_targets = generate_test_data(n_testing)

    norm_const = np.max(test_targets) - np.min(test_targets)

    test_vals_mice, unc_mice, deriv = gp_mice.predict(testing,
                                                      deriv=False,
                                                      unc=True)
    test_vals, unc, deriv = gp.predict(testing, deriv=False, unc=True)

    return (
        np.sqrt(np.sum(
            (test_vals - test_targets)**2) / float(n_testing)) / norm_const,
        np.sqrt(np.sum(unc**2) / float(n_testing)) / norm_const**2,
        np.sqrt(np.sum(
            (test_vals_mice - test_targets)**2) / float(n_testing)) /
        norm_const,
        np.sqrt(np.sum(unc_mice**2) / float(n_testing)) / norm_const**2)
def generate_input_data(n_simulations, n_dimensions, method="random"):
    "Generate n_simulations evaluation points the n_dimensions dimensional Rosenbrock function"

    n_simulations = int(n_simulations)
    n_dimensions = int(n_dimensions)
    assert (n_simulations > 0)
    assert (n_dimensions > 0)
    assert method == "random" or method == "lhd"

    if method == "random":
        ed = MonteCarloDesign(n_dimensions, (-5., 10.))
    elif method == "lhd":
        ed = LatinHypercubeDesign(n_dimensions, (-5., 10.))
    inputs = ed.sample(n_simulations)
    return inputs