def test_Z3():
  """ Test of implementation 2. """
  traj = simple_traj10()
  theta = np.array([500.0, -100.0])
  weights = [[0.1, 0.9], [0.9, 0.1]]
  elts = LearningElementsSecure(traj, theta, weights=weights)
  elts.computeLogZ()
def test_opt0_traj10_1():
  """ test_opt0_traj10_1 """
  traj = simple_traj10()
  start_theta = np.array([-1.0, 2.0])
  choices = [0, 0]
  traj_choices = [(traj, choices)]
  obj_fun_2 = trajs_obj_fun_2(traj_choices)
  obj_fun_1 = trajs_obj_fun_1(traj_choices)
  obj_fun_0bis = trajs_obj_fun_0bis(traj_choices)
  max_iters = 5
  (theta_0bis, ys_0bis) = \
    optimize_function(obj_fun_0bis, start_theta, max_iters, regularizer=1e-4)
  (theta_1, ys_1) = \
    optimize_function(obj_fun_1, start_theta, max_iters, regularizer=1e-4)
  (theta_2, ys_2) = \
    optimize_function(obj_fun_2, start_theta, max_iters, regularizer=1e-4)
  assert(np.abs(theta_1 - theta_0bis).max() < 1e-3), (theta_1, theta_0bis)
  assert(np.abs(theta_2 - theta_0bis).max() < 1e-3), (theta_2, theta_0bis)
  assert within(ys_1[0], ys_0bis[0], 1e-3), (theta_0bis, ys_0bis, theta_1, ys_1)
  assert within(ys_2[0], ys_0bis[0], 1e-3), (theta_0bis, ys_0bis, theta_2, ys_2)
Exemple #3
0
def test_opt0_traj10_1():
    """ test_opt0_traj10_1 """
    traj = simple_traj10()
    start_theta = np.array([-1.0, 2.0])
    choices = [0, 0]
    traj_choices = [(traj, choices)]
    obj_fun_2 = trajs_obj_fun_2(traj_choices)
    obj_fun_1 = trajs_obj_fun_1(traj_choices)
    obj_fun_0bis = trajs_obj_fun_0bis(traj_choices)
    max_iters = 5
    (theta_0bis, ys_0bis) = \
      optimize_function(obj_fun_0bis, start_theta, max_iters, regularizer=1e-4)
    (theta_1, ys_1) = \
      optimize_function(obj_fun_1, start_theta, max_iters, regularizer=1e-4)
    (theta_2, ys_2) = \
      optimize_function(obj_fun_2, start_theta, max_iters, regularizer=1e-4)
    assert (np.abs(theta_1 - theta_0bis).max() < 1e-3), (theta_1, theta_0bis)
    assert (np.abs(theta_2 - theta_0bis).max() < 1e-3), (theta_2, theta_0bis)
    assert within(ys_1[0], ys_0bis[0],
                  1e-3), (theta_0bis, ys_0bis, theta_1, ys_1)
    assert within(ys_2[0], ys_0bis[0],
                  1e-3), (theta_0bis, ys_0bis, theta_2, ys_2)