def test_hess_traj4_1(): """ test_hess_traj4_1 """ traj = simple_traj4() theta = np.array([0.0, -1.0]) choices = [1, 0, 2] elts = LearningElements(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)
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,)
def res(theta): """ inner closure. """ elts = LearningElementsRef(traj, theta, choices) elts.computeHessianLogZ() return elts.hess_Z