예제 #1
0
def test_single_variable_trig_hyperbolic_2():
    x = ad.Variable()
    # x^2  Cosh[Sin[x] + Tanh[Exp[3 * x] + Log[x]]]
    g = ad.Sin(x) + ad.Tanh(ad.Exp(3 * x) + ad.Log(x))
    f = x * x * ad.Cosh(g)
    assert (equals(f.hessian({x: 1}), 11.464317742))
    assert (equals(f.hessian({x: 2}), -13.704377252))
def test_trig_multivar_hessian_2():
    x, y, z = ad.Variable(), ad.Variable(), ad.Variable()
    f = ad.Sinh(x * y) + (x + y) * (z**2) * ad.Cosh(z * ad.Tanh(1 / z))
    h = f.hessian({x: 1, y: 2, z: 3})
    assert (equals(h[x][x], 14.50744163138))
    assert (equals(h[y][y], 3.6268604078))
    assert (equals(h[z][z], 9.3022279093))
    assert (equals(h[x][y], 11.015916506))
    assert (equals(h[y][z], 9.2426242912))
    assert (equals(h[x][z], 9.2426242912))
예제 #3
0
def test_hyperbolic_expressions():
    x = ad.Variable('x')
    y = ad.Variable('y')
    f1 = ad.Tan(x)
    f2 = ad.Sinh(x)
    f3 = ad.Cosh(x)
    f4 = ad.Tanh(x)
    f5 = ad.Exp(x)
    f6 = ad.Cos(x)
    assert f1._d_expr(y).eval({x:1}) == 0
    assert np.isclose(f1._d_expr(x).eval({x:1}), f1.d({x: 1}))
    assert f2._d_expr(y).eval({x:1}) == 0
    assert np.isclose(f2._d_expr(x).eval({x:1}), f2.d({x: 1}))
    assert f3._d_expr(y).eval({x:1}) == 0
    assert np.isclose(f3._d_expr(x).eval({x:1}), f3.d({x: 1}))
    assert f4._d_expr(y).eval({x:1}) == 0
    assert np.isclose(f4._d_expr(x).eval({x:1}), f4.d({x: 1}))
    assert f5._d_expr(y).eval({x:1}) == 0
    assert np.isclose(f5._d_expr(x).eval({x:1}), f5.d({x: 1}))
    assert f6._d_expr(y).eval({x:1}) == 0
    assert np.isclose(f6._d_expr(x).eval({x:1}), f6.d({x: 1}))
예제 #4
0
def test_single_variable_trig_hyperbolic():
    x = ad.Variable()
    f = x * x * ad.Cosh(0.01 * x + 0.1) + x * ad.Sinh(x * x - 4.0)
    assert (equals(f.hessian({x: 1}), 22.351093955))
    assert (equals(f.hessian({x: 2}), 14.02444322))
    assert (equals(f.hessian({x: 3}), 9351.7592912))
예제 #5
0
def test_cosh_expression():
    a = ad.Variable('a')
    b = ad.Cosh(a)
    assert np.isclose(b.eval({a: pi/4}), 1.3246090892520057)
    assert np.isclose(b.d({a: pi/4}), 0.8686709614860095)