def test_opt0_traj4_1ref():
  """ test_opt0_traj4_1 """
  traj = simple_traj4()
  start_theta = np.array([0.0, 0.0])
  choices = [1, 0, 2]
  estims = [np.array([0.0, 1.0]), np.array([1.0]), np.array([0.0, 0.0, 1.0])]
  traj_choices = [(traj, choices)]
  traj_estims = [(traj, estims)]
  obj_fun_2 = trajs_obj_fun_2(traj_choices)
  obj_fun_1 = trajs_obj_fun_1(traj_choices)
  obj_fun_0 = trajs_obj_fun_0(traj_choices)
  obj_fun_ref = trajs_obj_fun_ref(traj_choices)
  obj_fun_estim_ref = trajs_estim_obj_fun_ref(traj_estims)
  max_iters = 5
  (theta_0, ys_0) = optimize_function(obj_fun_0, start_theta, max_iters)
  (theta_1, ys_1) = optimize_function(obj_fun_1, start_theta, max_iters)
  (theta_2, ys_2) = optimize_function(obj_fun_2, start_theta, max_iters)
  (theta_ref, ys_ref) = optimize_function(obj_fun_ref, start_theta, max_iters)
  (theta_estim_ref, ys_estim_ref) = optimize_function(obj_fun_estim_ref, \
                                                      start_theta, max_iters)
  assert(np.abs(theta_0 - theta_ref).max() < 1e-3), (theta_0, theta_ref)
  assert(np.abs(theta_1 - theta_ref).max() < 1e-3), (theta_1, theta_ref)
  assert(np.abs(theta_2 - theta_ref).max() < 1e-3), (theta_2, theta_ref)
  assert(np.abs(theta_estim_ref - theta_ref).max() < 1e-3), (theta_estim_ref, \
                                                             theta_ref)
  assert within(ys_0[0], ys_ref[0], 1e-3), (theta_ref, ys_ref, theta_0, ys_0)
  assert within(ys_1[0], ys_ref[0], 1e-3), (theta_ref, ys_ref, theta_1, ys_1)
  assert within(ys_2[0], ys_ref[0], 1e-3), (theta_ref, ys_ref, theta_2, ys_2)
  assert within(ys_estim_ref[0], ys_ref[0], 1e-3), (theta_ref, ys_ref, \
                                                    theta_estim_ref, \
                                                    ys_estim_ref)
def test_opt0_traj9_1():
  """ test_opt0_traj9_1 """
  traj = simple_traj9()
  start_theta = np.array([-1.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_0 = trajs_obj_fun_0(traj_choices)
  obj_fun_0bis = trajs_obj_fun_0bis(traj_choices)
  obj_fun_ref = trajs_obj_fun_ref(traj_choices)
  max_iters = 5
  (theta_ref, ys_ref) = \
    optimize_function(obj_fun_ref, start_theta, max_iters, regularizer=1e-4)
  print ys_ref, theta_ref
  (theta_0bis, ys_0bis) = \
    optimize_function(obj_fun_0bis, start_theta, max_iters, regularizer=1e-4)
  (theta_0, ys_0) = \
    optimize_function(obj_fun_0, 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_0bis - theta_ref).max() < 1e-3), (theta_0bis, theta_ref)
  assert(np.abs(theta_0 - theta_ref).max() < 1e-3), (theta_0, theta_ref)
  assert(np.abs(theta_1 - theta_ref).max() < 1e-3), (theta_1, theta_ref)
  assert(np.abs(theta_2 - theta_ref).max() < 1e-3), (theta_2, theta_ref)
  assert within(ys_0bis[0], ys_ref[0], 1e-3), \
    (theta_ref, ys_ref, theta_0bis, ys_0bis)
  assert within(ys_0[0], ys_ref[0], 1e-3), (theta_ref, ys_ref, theta_0, ys_0)
  assert within(ys_1[0], ys_ref[0], 1e-3), (theta_ref, ys_ref, theta_1, ys_1)
  assert within(ys_2[0], ys_ref[0], 1e-3), (theta_ref, ys_ref, theta_2, ys_2)
Esempio n. 3
0
def test_opt0_traj4_1ref():
    """ test_opt0_traj4_1 """
    traj = simple_traj4()
    start_theta = np.array([0.0, 0.0])
    choices = [1, 0, 2]
    estims = [np.array([0.0, 1.0]), np.array([1.0]), np.array([0.0, 0.0, 1.0])]
    traj_choices = [(traj, choices)]
    traj_estims = [(traj, estims)]
    obj_fun_2 = trajs_obj_fun_2(traj_choices)
    obj_fun_1 = trajs_obj_fun_1(traj_choices)
    obj_fun_0 = trajs_obj_fun_0(traj_choices)
    obj_fun_ref = trajs_obj_fun_ref(traj_choices)
    obj_fun_estim_ref = trajs_estim_obj_fun_ref(traj_estims)
    max_iters = 5
    (theta_0, ys_0) = optimize_function(obj_fun_0, start_theta, max_iters)
    (theta_1, ys_1) = optimize_function(obj_fun_1, start_theta, max_iters)
    (theta_2, ys_2) = optimize_function(obj_fun_2, start_theta, max_iters)
    (theta_ref, ys_ref) = optimize_function(obj_fun_ref, start_theta,
                                            max_iters)
    (theta_estim_ref, ys_estim_ref) = optimize_function(obj_fun_estim_ref, \
                                                        start_theta, max_iters)
    assert (np.abs(theta_0 - theta_ref).max() < 1e-3), (theta_0, theta_ref)
    assert (np.abs(theta_1 - theta_ref).max() < 1e-3), (theta_1, theta_ref)
    assert (np.abs(theta_2 - theta_ref).max() < 1e-3), (theta_2, theta_ref)
    assert(np.abs(theta_estim_ref - theta_ref).max() < 1e-3), (theta_estim_ref, \
                                                               theta_ref)
    assert within(ys_0[0], ys_ref[0], 1e-3), (theta_ref, ys_ref, theta_0, ys_0)
    assert within(ys_1[0], ys_ref[0], 1e-3), (theta_ref, ys_ref, theta_1, ys_1)
    assert within(ys_2[0], ys_ref[0], 1e-3), (theta_ref, ys_ref, theta_2, ys_2)
    assert within(ys_estim_ref[0], ys_ref[0], 1e-3), (theta_ref, ys_ref, \
                                                      theta_estim_ref, \
                                                      ys_estim_ref)
Esempio n. 4
0
def test_opt0_traj9_1():
    """ test_opt0_traj9_1 """
    traj = simple_traj9()
    start_theta = np.array([-1.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_0 = trajs_obj_fun_0(traj_choices)
    obj_fun_0bis = trajs_obj_fun_0bis(traj_choices)
    obj_fun_ref = trajs_obj_fun_ref(traj_choices)
    max_iters = 5
    (theta_ref, ys_ref) = \
      optimize_function(obj_fun_ref, start_theta, max_iters, regularizer=1e-4)
    print ys_ref, theta_ref
    (theta_0bis, ys_0bis) = \
      optimize_function(obj_fun_0bis, start_theta, max_iters, regularizer=1e-4)
    (theta_0, ys_0) = \
      optimize_function(obj_fun_0, 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_0bis - theta_ref).max() < 1e-3), (theta_0bis,
                                                           theta_ref)
    assert (np.abs(theta_0 - theta_ref).max() < 1e-3), (theta_0, theta_ref)
    assert (np.abs(theta_1 - theta_ref).max() < 1e-3), (theta_1, theta_ref)
    assert (np.abs(theta_2 - theta_ref).max() < 1e-3), (theta_2, theta_ref)
    assert within(ys_0bis[0], ys_ref[0], 1e-3), \
      (theta_ref, ys_ref, theta_0bis, ys_0bis)
    assert within(ys_0[0], ys_ref[0], 1e-3), (theta_ref, ys_ref, theta_0, ys_0)
    assert within(ys_1[0], ys_ref[0], 1e-3), (theta_ref, ys_ref, theta_1, ys_1)
    assert within(ys_2[0], ys_ref[0], 1e-3), (theta_ref, ys_ref, theta_2, ys_2)
def test_opt0_traj5_1():
  """ test_opt0_traj5_1 """
  traj = simple_traj5()
  start_theta = np.array([-1.0])
  choices = [1, 0, 2]
  traj_choices = [(traj, choices)]
  obj_fun_1 = trajs_obj_fun_1(traj_choices)
  obj_fun_0 = trajs_obj_fun_0(traj_choices)
  obj_fun_ref = trajs_obj_fun_ref(traj_choices)
  max_iters = 5
  (theta_0, ys_0) = optimize_function(obj_fun_0, start_theta, max_iters)
  (theta_1, ys_1) = optimize_function(obj_fun_1, start_theta, max_iters)
  (theta_ref, ys_ref) = optimize_function(obj_fun_ref, start_theta, max_iters)
  assert(np.abs(theta_0 - theta_ref).max() < 1e-3), (theta_0, theta_ref)
  assert(np.abs(theta_1 - theta_ref).max() < 1e-3), (theta_1, theta_ref)
  assert within(ys_0[0], ys_ref[0], 1e-3), (theta_ref, ys_ref, theta_0, ys_0)
  assert within(ys_1[0], ys_ref[0], 1e-3), (theta_ref, ys_ref, theta_1, ys_1)
Esempio n. 6
0
def test_opt0_traj5_1():
    """ test_opt0_traj5_1 """
    traj = simple_traj5()
    start_theta = np.array([-1.0])
    choices = [1, 0, 2]
    traj_choices = [(traj, choices)]
    obj_fun_1 = trajs_obj_fun_1(traj_choices)
    obj_fun_0 = trajs_obj_fun_0(traj_choices)
    obj_fun_ref = trajs_obj_fun_ref(traj_choices)
    max_iters = 5
    (theta_0, ys_0) = optimize_function(obj_fun_0, start_theta, max_iters)
    (theta_1, ys_1) = optimize_function(obj_fun_1, start_theta, max_iters)
    (theta_ref, ys_ref) = optimize_function(obj_fun_ref, start_theta,
                                            max_iters)
    assert (np.abs(theta_0 - theta_ref).max() < 1e-3), (theta_0, theta_ref)
    assert (np.abs(theta_1 - theta_ref).max() < 1e-3), (theta_1, theta_ref)
    assert within(ys_0[0], ys_ref[0], 1e-3), (theta_ref, ys_ref, theta_0, ys_0)
    assert within(ys_1[0], ys_ref[0], 1e-3), (theta_ref, ys_ref, theta_1, ys_1)