Пример #1
0
def mogp_configuration_initialization(sample_points,
                                      results_dir,
                                      isSWEEP, seed=0):

    ed = mogp_emulator.LatinHypercubeDesign(
        [(-120., -80.), (0.1, 0.4), (0.9, 1.1)])

    # We can now generate a design of sample_points by calling the sample

    if seed == 0:
        seed = None

    np.random.seed(seed)
    input_points = ed.sample(sample_points)

    if isSWEEP == False:
        # save input_points array data into file
        np.save(join(results_dir, "input_points.npy"), input_points)
        with open(join(results_dir, "ed.pickle"), 'wb') as output:
            pickle.dump(ed, output, pickle.HIGHEST_PROTOCOL)
    else:
        counter = 1
        for point in input_points:
            folder_name = "sample_point_" + str(counter)
            np.save(join(results_dir, "SWEEP", folder_name,
                         "input_points.npy"), point)
            counter += 1
            with open(join(results_dir, "SWEEP", folder_name, "ed.pickle"),
                      'wb') as output:
                pickle.dump(ed, output, pickle.HIGHEST_PROTOCOL)
Пример #2
0
import mogp_emulator
import numpy as np
from projectile import simulator, print_results

# simple MICE examples using the projectile demo

# Base design -- requires a list of parameter bounds if you would like to use
# uniform distributions. If you want to use different distributions, you
# can use any of the standard distributions available in scipy to create
# the appropriate ppf function (the inverse of the cumulative distribution).
# Internally, the code creates the design on the unit hypercube and then uses
# the distribution to map from [0,1] to the real parameter space.

lhd = mogp_emulator.LatinHypercubeDesign([(-5., 1.), (0., 1000.)])

###################################################################################

# first example -- run entire design internally within the MICE class.

# first argument is base design (required), second is simulator function (optional,
# but required if you want the code to run the simualtions internally)

# Other optional arguments include:
# n_samples (number of sequential design steps, optional, default is not specified
# meaning that you will specify when running the sequential design)
# n_init (size of initial design, default 10)
# n_cand (number of candidate points, default is 50)
# nugget (nugget parameter for design GP, default is to set adaptively)
# nugget_s (nugget parameter for candidate GP, default is 1.)

n_init = 5
Пример #3
0
# Having a grid of theta-s
theta0 = np.arange(-np.pi / 30, np.pi / 30 + 0.001, np.pi / 180)
Nsamples = theta0.shape[0]**3  #30

baseAngles = [np.pi / 4, 0.0, -np.pi / 4]

#theta = np.random.normal(0.0, 0.0872665, size = (Nsamples, 3)) #
theta = np.array([(x, y, z) for x in theta0 for y in theta0 for z in theta0])

myModel = Cantilever(param, comm)

### Multiple Output Gaussian Process Emulator: first, Latin hypercube design as simulation points

theta_design = mogp_emulator.LatinHypercubeDesign([(-np.pi / 30, np.pi / 30),
                                                   (-np.pi / 30, np.pi / 30),
                                                   (-np.pi / 30, np.pi / 30)])

# Start with 50-100-... simulation points (should take about 5-10-... mins to run)
n_simulations = 100
simulation_points = theta_design.sample(n_simulations)
simulation_output = np.array([
    myModel.solve(baseAngles + p, True, iterativeSolver=False)
    for p in simulation_points
]).transpose()

# for m_point in np.delete(range(12),4):  #remove point 5, where displacement is always 0
#     simulation_output_single = simulation_output[m_point, :]
#
#     print("Measurement point " + str(m_point + 1))
#     print(simulation_output_single)
Пример #4
0
# simulator function -- needs to take a single input and output a single number


def f(x):
    return np.exp(-np.sum((x - 2.)**2, axis=-1) / 2.)


# Experimental design -- requires a list of parameter bounds if you would like to use
# uniform distributions. If you want to use different distributions, you
# can use any of the standard distributions available in scipy to create
# the appropriate ppf function (the inverse of the cumulative distribution).
# Internally, the code creates the design on the unit hypercube and then uses
# the distribution to map from [0,1] to the real parameter space.

ed = mogp_emulator.LatinHypercubeDesign([(0., 5.), (0., 5.)])

# sample space

inputs = ed.sample(20)

# run simulation

targets = np.array([f(p) for p in inputs])

###################################################################################

# First example -- fit GP using MLE and Squared Exponential Kernel and predict

print("Example 1: Basic GP")
import mogp_emulator
from earthquake import create_problem, run_simulation, compute_moment
import matplotlib.pyplot as plt
import matplotlib.tri

# This is a python script showing the mogp_emulator part of the demo, and contains the python
# code found in the tutorial. This code is included for illustration purposes, as it does not
# implement the workflow tools included with the FabSim plugin.

# create Latin Hypercube sample of the three stress parameters:
# first parameter is normal stress on the fault, which has a uniform distribution from -120 to -80 MPa
# (negative in compression)
# second parameter is the ratio between shear and normal stress, a uniform distribution from 0.1 to 0.4
# third is ratio between the two normal stress components, a uniform distribution between +/- 10%

ed = mogp_emulator.LatinHypercubeDesign([(-120., -80.), (0.1, 0.4),
                                         (0.9, 1.1)])

seed = None
sample_points = 20

np.random.seed(seed)
input_points = ed.sample(sample_points)

# Now we can actually run the simulations. First, we feed the input points to create_problem to
# write the input files, call run_simulation to actually simulate them, and compute_moment to
# load the data and compute the earthquake size. The simulation is parallelized, so if you
# have multiple cores available you can specify more processors to run the simulation.

# Each simulation takes about 20 seconds on 4 processors on my MacBook Pro, so the entire design
# will take several minutes to run.