Ejemplo n.º 1
0
def test_ccmaes():
    x = np.zeros(1)
    opt = CCMAESOptimizer(x, random_state=0)
    opt.init(1, 1)
    r = eval_loop(x, opt, n_evals=1000)
    assert_less(-1e-7, r.max())
    return r
Ejemplo n.º 2
0
def test_linear_contextual_sphere():
    random_state = np.random.RandomState(0)
    n_params = 3
    n_context_dims = 2
    obj = LinearContextualSphere(random_state, n_params, n_context_dims)

    opt = CCMAESOptimizer(context_features="affine", random_state=random_state,
                          log_to_stdout=False)
    opt.init(n_params, n_context_dims)
    params = np.empty(n_params)
    for i in range(1000):
        context = random_state.rand(n_context_dims) * 2.0 - 1.0
        opt.set_context(context)
        opt.get_next_parameters(params)
        opt.set_evaluation_feedback([obj.feedback(params, context)])
    policy = opt.best_policy()
    mean_reward = evaluate(policy, obj)
    assert_greater(mean_reward, -1e-4)
Ejemplo n.º 3
0
def test_cmaes_no_initial_params():
    opt = CCMAESOptimizer()
    opt.init(10, 5)
    params = np.empty(10)
    opt.set_context(np.zeros(5))
    opt.get_next_parameters(params)
Ejemplo n.º 4
0
def test_cmaes_diagonal_cov():
    opt = CCMAESOptimizer(covariance=np.zeros(10))
    opt.init(10, 5)
    params = np.empty(10)
    opt.set_context(np.zeros(5))
    opt.get_next_parameters(params)