inv = np.linalg.inv(cov)
assert np.allclose(inv.dot(cov), np.eye(5))
x_ = floatX(np.random.randn(5))
x = tt.vector()x.tag.test_value = x_
pots = [
quadpotential.quad_potential(cov, False, False),
quadpotential.quad_potential(inv, True, False),
]
if quadpotential.chol_available:
pots.append(quadpotential.quad_potential(cov, False, False))
v = np.linalg.solve(cov, x_)
e = 0.5 * x_.dot(v)
for pot in pots:
v_function = theano.function([x], pot.velocity(x))
e_function = theano.function([x], pot.energy(x))
assert np.allclose(v_function(x_), v)
assert np.allclose(e_function(x_), e)
After Change
e = 0.5 * x.dot(v)
for pot in pots:
v_ = pot.velocity(x)
e_ = pot.energy(x)
npt.assert_allclose(v_, v, rtol=1e-4)
npt.assert_allclose(e_, e, rtol=1e-4)