def test_opt0_traj8_1(): """ test_opt0_traj8_1 """ traj = simple_traj8() start_theta = np.array([-1.0]) choices = [1, 0] traj_choices = [(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 assert np.abs(theta_ref) < 1e-4 (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) 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 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)
def test_opt0_traj8_1(): """ test_opt0_traj8_1 """ traj = simple_traj8() start_theta = np.array([-1.0]) choices = [1, 0] traj_choices = [(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 assert np.abs(theta_ref) < 1e-4 (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) 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 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)
def test_hess_traj8_2(): """ test_hess_traj8_2 """ traj = simple_traj8() theta = np.array([0.0]) choices = [1, 0] elts = LearningElementsSecure(traj, theta, choices) elts.computeHessianLogZ() elts_ref = LearningElementsRef(traj, theta, choices) elts_ref.computeHessianLogZ() h = elts.hess_logZ h_ref = elts_ref.hess_logZ assert(np.abs(h - h_ref).max() < 1e-3), \ (h, h_ref, elts.hess_Z, elts_ref.hess_Z, \ elts.grad_Z, elts_ref.grad_Z, elts.Z, elts_ref.Z,)