Esempio n. 1
0
def pred3(traj):
    traj = traj[0]
    theta = np.array(traj).T[2]
    return min(0.2 - np.abs(theta))


smooth_details_r3 = []
ns_details_r3 = []
random_details_r3 = []

for r in rand_nums:
    np.random.seed(r)
    node0 = pred_node(f=lambda traj: pred1(traj))
    node1 = pred_node(f=lambda traj: pred2(traj))
    node2 = pred_node(f=lambda traj: pred3(traj))
    node3 = max_node(children=[node0, node1, node2])
    TM = test_module(bounds=bounds,
                     sut=lambda x0: sut(200, x0),
                     f_tree=node3,
                     init_sample=60,
                     optimize_restarts=3,
                     exp_weight=2,
                     normalizer=True)
    TM.initialize()
    TM.run_BO(140)

    np.random.seed(r)
    node0_ns = pred_node(f=lambda traj: pred1(traj))
    node1_ns = pred_node(f=lambda traj: pred2(traj))
    node2_ns = pred_node(f=lambda traj: pred3(traj))
    node3_ns = max_node(children=[node0_ns, node1_ns, node2_ns])
    return -iters / 350.


def pred3(traj):
    traj = traj[0]
    v_s = np.array(traj).T[1]
    return min(0.025 - np.abs(v_s))


for r in rand_nums:
    np.random.seed(r)
    node0 = pred_node(f=pred1)
    node1 = pred_node(f=pred2)
    node2 = pred_node(f=pred3)
    node3 = min_node(children=[node0, node2])
    node4 = max_node(children=[node3, node1])
    TM = test_module(bounds=bounds,
                     sut=lambda x0: sut(x0, max_steps=350),
                     f_tree=node4,
                     init_sample=60,
                     optimize_restarts=5,
                     exp_weight=2,
                     normalizer=True)
    TM.initialize()
    TM.run_BO(140)
    smooth_vals = TM.f_acqu.find_GP_func()
    smooth_details_r3.append([
        np.sum(smooth_vals < -0.25),
        np.sum(smooth_vals < -0.30), TM.smooth_min_x, TM.smooth_min_val,
        TM.smooth_min_loc
    ])
Esempio n. 3
0
import numpy as np
from matplotlib import pyplot as plt

bounds = [(0, 10)]
opt = delta_opt(bounds=bounds, epsilon=0.0001)

random_ints = [
    1414065923, 2448114469, 1906628456, 2644070884, 24268670, 2664125290,
    1182137443, 100813220, 1822558109, 2027862653
]
i = 0
for r in random_ints:
    np.random.seed(r)
    node1 = pred_node(f=lambda x: np.sin(x) + 0.65)
    node2 = pred_node(f=lambda x: np.cos(x) + 0.65)
    node0 = max_node(children=[node1, node2])

    TM = test_module(bounds=bounds,
                     sut=lambda x: x,
                     f_tree=node0,
                     with_ns=True,
                     with_random=True,
                     init_sample=5,
                     optimizer=opt,
                     optimize_restarts=3,
                     exp_weight=2)
    TM.initialize()
    TM.run_BO(50)

    plt.figure(i + 1)
    plt.plot(TM.smooth_X[5:])
def pred2(traj, gamma=0.25):
    traj = traj[0]
    cos_thetas = np.array(traj).T[0]
    theta_dots = np.array(traj).T[2]
    stab_vals = 0
    for ct, td in zip(cos_thetas, theta_dots):
        stab_vals = (np.pi - np.abs(np.arccos(ct)))**2 + np.abs(td)**2 + stab_vals*gamma
    return -stab_vals

# This set assumes random sampling and checking
for r in rand_nums:
    np.random.seed(r)
    node0 = pred_node(f = lambda traj:pred1(traj))
    node1 = pred_node(f = lambda traj:pred2(traj))
    node2 = max_node(children=[node0, node1])
    TM = test_module(bounds=bounds, sut=lambda x0: sut(500,x0, ead=True),
                     f_tree = node2,init_sample = 60,
                     optimize_restarts=5, exp_weight=10, normalizer=True)
    TM.initialize()
    TM.run_BO(30)
    TM.k  =5
    TM.run_BO(40)
    TM.k = 2
    TM.run_BO(70)
    smooth_vals = np.array(TM.f_acqu.find_GP_func())
    smooth_details_r3.append([np.sum(smooth_vals < -1.00),
                              np.sum(smooth_vals < -10.0),
                              TM.smooth_min_x,TM.smooth_min_val,
                              TM.smooth_min_loc])
    traj = traj[0]
    cos_thetas = np.array(traj).T[0]
    theta_dots = np.array(traj).T[2]
    stab_vals = 0
    for ct, td in zip(cos_thetas, theta_dots):
        stab_vals = (np.pi - np.abs(
            np.arccos(ct)))**2 + np.abs(td)**2 + stab_vals * gamma
    return -stab_vals


# This set assumes random sampling and checking
for r in rand_nums:
    np.random.seed(r)
    node0 = pred_node(f=lambda traj: pred1(traj))
    node1 = pred_node(f=lambda traj: pred2(traj))
    node2 = max_node(children=[node0, node1])
    TM = test_module(bounds=bounds,
                     sut=lambda x0: sut(500, x0, ead=True),
                     f_tree=node2,
                     init_sample=60,
                     optimize_restarts=5,
                     exp_weight=2,
                     normalizer=True)
    TM.initialize()
    TM.run_BO(140)
    smooth_vals = np.array(TM.f_acqu.find_GP_func())
    smooth_details_r3.append([
        np.sum(smooth_vals < -1.00),
        np.sum(smooth_vals < -10.0), TM.smooth_min_x, TM.smooth_min_val,
        TM.smooth_min_loc
    ])