コード例 #1
0
def test_grad_Z2():
  """ Test of implementation 2 of gradient. """
  traj = simple_traj2()
  theta = np.array([0.0, -1.0])
  choices = [0, 1]
  elts = LearningElements(traj, theta, choices)
  elts.computeGradientLogZ()
  elts_ref = LearningElementsRef(traj, theta, choices)
  elts_ref.computeGradientLogZ()
  g = elts.grad_logZ
  g_ref = elts_ref.grad_logZ
  assert(np.abs(g - g_ref).max() < 1e-3), (g, g_ref)