コード例 #1
0
 def fun(poly_coef):
     p = Poly(poly_coef)
     tg = p.get_taylor_grid(params=[
         tf.constant([0, 1, 2], dtype=tf.float32),
         tf.constant([0, 1], dtype=tf.float32)
     ],
                            truncs=2)
     return tg.coef
コード例 #2
0
def test_2d_poly():
    f = Poly(tf.constant(rnd.randint(-3, 3, size=(10, 1, 6)), K.floatx()),
             batch_ndim=1)
    g = Poly(tf.constant(rnd.randint(-3, 3, size=(10, 2, 1)), K.floatx()),
             batch_ndim=1)

    f * g
    assert list((f + g).degs) == [2, 6]
    (f * g).truncate_degs(2)
    f.truncated_exp()
コード例 #3
0
 def fun(coef):
     p = Poly(coef)
     return p.truncated_exp().coef
コード例 #4
0
def test_1d_poly():
    p = Poly(tf.constant([0., 1, 0]))

    # test __mul__
    assert np.allclose((p * p).coef, [0, 0, 1, 0, 0])

    # test truncated_exp
    exp_p = p.truncated_exp()
    assert np.allclose(exp_p.coef, [1, 1, 1 / 2])

    # test truncated_fun
    exp_p = p.truncated_fun(lambda k, t: np.exp(t))
    assert np.allclose(exp_p.coef, [1, 1, 1 / 2])

    # test truncated_inverse
    q = Poly(tf.constant([1., 1, 0]))
    assert np.allclose(q.truncated_inverse().coef, [1, -1, 1])
    assert np.allclose((q * q.truncated_inverse()).truncate_degs(3).coef,
                       [1, 0, 0])

    # test der
    assert np.allclose(q.der().coef, [1, 0])

    # test unit_like
    assert q.unit_like().coef.shape == [1]
    assert np.allclose(q.unit_like().coef, [1])
コード例 #5
0
 def fun(coef, x):
     p = Poly(coef)
     return p(x)
コード例 #6
0
 def fun(coef):
     p = Poly(coef)
     return (p + p).coef
コード例 #7
0
 def poly_square(coef):
     p = Poly(coef)
     return (p * p).coef
コード例 #8
0
 def fun(coef, point):
     p = Poly(coef)
     return p.taylor_at(point).coef
コード例 #9
0
 def fun(b, batch_ndim=0):
     p = Poly.from_tensor(b, batch_ndim=batch_ndim)
     return p.coef