示例#1
0
def sine():
    return (
        gammy.Function(
            utils.compose(np.sin, lambda t: 0.5 * np.pi * t),
            (0, 1)
        ),
        np.array([0., 1., 2.])
    )
示例#2
0
def test_lift():
    def function(t):
        return t**2

    def f(t):
        return t - 2

    x = ArrayMapper(function)
    testing.assert_almost_equal(x.lift(f)(data),
                                utils.compose(f, function)(data),
                                decimal=8)
    return
示例#3
0
 def lift(self, f):
     return ArrayMapper(compose(f, self.function))
示例#4
0
    input_data = np.vstack((
        2 * np.pi * np.random.rand(n),
        np.random.rand(n),
    )).T
    y = (np.abs(np.cos(input_data[:, 0])) * input_data[:, 1] + 1 +
         0.1 * np.random.randn(n))
    formula = gammy.ExpSineSquared1d(
        np.arange(0, 2 * np.pi, 0.1),
        corrlen=1.0,
        sigma=1.0,
        period=2 * np.pi,
        energy=0.99)(x[:, 0]) * x[:, 1] + gammy.Scalar(prior=(0, 1e-6))
    return (input_data, y, formula)


assert_arrays_equal = utils.compose(
    utils.listmap(lambda xs: assert_array_equal(*xs)), list, zip)


def assert_nodes_equal(a, b):
    """Assert that two bp.expfamily nodes coincide

    """
    assert_arrays_equal(a.u, b.u)
    assert_arrays_equal(a.phi, b.phi)
    assert_array_equal(a.f, b.f)
    assert_array_equal(a.g, b.g)
    assert a.observed == b.observed
    return


@pytest.mark.parametrize("data", [polynomial(), gp()])
示例#5
0
 def lifted(mapper):
     return ArrayMapper(compose(f, mapper.function))
示例#6
0
def test_compose(fs, xs, g):
    assert all([utils.compose(*fs)(*args) == g(*args) for args in xs])
    return