Beispiel #1
0
def run(casename):

    fh = Dataset("../data/" + casename + ".nc", mode="r")
    lons = fh.variables["lon"][:]
    lats = fh.variables["lat"][:]
    depths = fh.variables["elevation"][:]

    # Rescale data and flip depths to have anomalies as minima

    lons = MinMaxScaler().fit_transform(lons.reshape(-1, 1))
    lats = MinMaxScaler().fit_transform(lats.reshape(-1, 1))
    tmp = StandardScaler().fit_transform(depths.reshape(-1, 1))
    depths = -tmp.reshape(depths.shape)
    if casename in ["cuba", "challenger", "izu", "izu2", "izu3"]:
        depths = -depths

    domain = [[0, 1], [0, 1]]
    inputs = UniformInputs(domain)
    inputs = GaussianInputs(domain, [0.5, 0.5], [0.01, 0.01])
    noise_var = 0.0

    interpolant = interpolate.interp2d(lons, lats, depths, kind="cubic")
    my_map = BlackBox(map_def, args=(interpolant, ), noise_var=noise_var)
    idx_max = np.unravel_index(depths.argmin(), depths.shape)
    true_xmin = [lons[idx_max[1]], lats[idx_max[0]]]
    true_ymin = np.min(depths)

    record_time = np.linspace(0, 15, 226)
    n_trials = 50
    n_jobs = 40

    pts = inputs.draw_samples(n_samples=int(1e5), sample_method="uni")
    yy = my_map.evaluate(pts, parallel=True, include_noise=False)
    y_list = [yy] * len(record_time)
    pt_list = [custom_KDE(yy, weights=inputs.pdf(pts))] * len(record_time)
    true_ymin_list = [true_ymin] * len(record_time)
    true_xmin_list = [true_xmin] * len(record_time)

    metric = [(rmse, dict(pts=pts, y_list=y_list, t_list=record_time)),
              (mll, dict(pts=pts, y_list=y_list, t_list=record_time)),
              (log_pdf, dict(pts=pts, pt_list=pt_list, t_list=record_time)),
              (distmin_model,
               dict(true_xmin_list=true_xmin_list, t_list=record_time)),
              (regret_tmap,
               dict(true_ymin_list=true_ymin_list,
                    tmap=my_map,
                    t_list=record_time))]

    X_pose = (0, 0, np.pi / 4)
    planner = PathPlanner(inputs.domain, look_ahead=0.2, turning_radius=0.02)

    acq_list = ["US_IW", "US_LW", "IVR_IW", "IVR_LW"]

    for acq in acq_list:
        print("Benchmarking " + acq)
        b = BenchmarkerPath(my_map, acq, planner, X_pose, record_time, inputs,
                            metric)
        result = b.run_benchmark(n_trials,
                                 n_jobs=n_jobs,
                                 filename=casename + "_" + acq)
Beispiel #2
0
def test_blackbox_shape_2D():
    n_init = 10
    domain = [[-1., 2.], [-1., 2.]]
    inputs = UniformInputs(domain)
    X = inputs.draw_samples(n_init, "lhs")
    Ys = BlackBox(map_def2D).evaluate(X)
    Yp = BlackBox(map_def2D).evaluate(X, parallel=True)
    np.testing.assert_allclose(Ys, Yp)
Beispiel #3
0
    def __init__(self,
                 function,
                 domain,
                 ymin,
                 xmin,
                 args={},
                 kwargs={},
                 noise_var=0.0,
                 rescale_X=False):
        self.ymin = ymin
        self.bounds = domain
        self.function = function

        if rescale_X:
            self.xmin = self.rescale_X(xmin)
            domain = [[0, 1]] * len(domain)
            self.my_map = BlackBox(self.function_sc,
                                   args=args,
                                   kwargs=kwargs,
                                   noise_var=noise_var)
        else:
            self.xmin = xmin
            self.my_map = BlackBox(self.function,
                                   args=args,
                                   kwargs=kwargs,
                                   noise_var=noise_var)

        self.inputs = UniformInputs(domain)
Beispiel #4
0
def main():

    ndim = 10

    x2, y2 = 1, 0.3
    x = np.linspace(0, x2, ndim + 2)
    x_pts = x[1:-1]

    xc, yc = cycloid(x2, y2, N=200)
    tc = travel_time(xc, yc)  # Best ever
    ff = interpolate.interp1d(xc, yc)

    noise_var = 1e-2
    my_map = BlackBox(map_def, args=(x, y2, tc), noise_var=noise_var)
    domain = [[0.05, 2 * y2] for n in np.arange(0, ndim)]
    inputs = UniformInputs(domain)

    prefix = "tclog_noise2_"

    n_init = 10
    n_iter = 300
    n_trials = 40
    n_jobs = 40

    true_ymin = 0.0
    metric = [("regret_tmap", dict(true_ymin=true_ymin, tmap=my_map)),
              ("regret_obs", dict(true_ymin=true_ymin))]

    acq_list = ["EI", "PI", "LCB", "LCB_LW", "LCB_LWraw", "IVR_BO", "IVR_LWBO"]

    for acq in acq_list:
        print("Benchmarking " + acq)
        b = Benchmarker(my_map, acq, n_init, n_iter, inputs, metric=metric)
        result = b.run_benchmark(n_trials,
                                 n_jobs=n_jobs,
                                 filename=prefix + acq)
Beispiel #5
0
def main():

    np.random.seed(2)
    n_init = 10

    domain = [[-1., 2.]]
    inputs = UniformInputs(domain)
    X = inputs.draw_samples(n_init, "lhs")
    Ys = BlackBox(map_def1D).evaluate(X)
    Yp = BlackBox(map_def1D).evaluate(X, parallel=True)
    OptimalDesign(X, Ys, BlackBox(map_def1D), inputs)
    OptimalDesign(X, Yp, BlackBox(map_def1D), inputs)
    print(X, Ys, Yp)

    domain = [[-1., 2.], [-1., 2.]]
    inputs = UniformInputs(domain)
    X = inputs.draw_samples(n_init, "lhs")
    Ys = BlackBox(map_def2D).evaluate(X)
    Yp = BlackBox(map_def2D).evaluate(X, parallel=True)
    OptimalDesign(X, Ys, BlackBox(map_def2D), inputs)
    OptimalDesign(X, Yp, BlackBox(map_def2D), inputs)
    print(X, Ys, Yp)