コード例 #1
0
def _function(init_vals):
    for k, v in init_vals.items():
        globals()[k] = AD(v, 1, k)
    f = x1**2 - x2
    g = x1 - 2 * x2
    v = AD([f, g])
    v.sort(['x1', 'x2'])
    return v
コード例 #2
0
def test_multi_dim_4():
    x = AD(1, 1, 'x')
    y = AD(2, 2, 'y')
    z = AD([y.cos() + x.cos(), y.tan() + x.tanh()])
    z.sort(['x', 'y'])
    np.testing.assert_allclose(z.val,
                               np.array([0.12415547,
                                         -1.42344571]).reshape(2, 1),
                               atol=1e-5)
    np.testing.assert_allclose(z.der,
                               np.array([[-0.84147098, -1.81859485],
                                         [0.41997434, 11.54879841]]),
                               atol=1e-5)
    assert z.name == ['x', 'y']