Exemplo n.º 1
0
def test_log_likelihood_is_correct(normal_data):
    ndata = normal_data[:1000]
    n = Normal(loc=kernels.linear(np.arange(len(ndata)))).fit_instance(ndata)
    actual = log_likelihood(n, ndata)
    expected = sum(
        norm.logpdf(x, loc=loc, scale=n.scale())
        for x, loc in zip(ndata, n.loc()))
    assert actual == approx(expected)
def test_fit_instance_fixed_params_extra_levels(dataset):
    covariate = np.arange(len(dataset))
    n = Normal(loc=kernels.linear(covariate, a=kernels.linear(covariate)))
    m = n.fit_instance(dataset, loc_a_a=5)
    assert m.loc.a.a() == 5
def linear_kernel(dataset):
    return kernels.linear(np.arange(len(dataset)))
Exemplo n.º 4
0
def test_trend_in_trend(dataset):
    inner_trend = kernels.linear(dataset)
    outer_trend = kernels.linear(dataset, b=inner_trend)
    assert {"a", "b_a", "b_b"} == set(outer_trend.flattened_param_dict.keys())
Exemplo n.º 5
0
def test_linear_trend_with_constraint(dataset):
    trend = kernels.linear(dataset, a=2)
    assert len(trend.params) == 2
    assert len(trend.optimisation_params) == 1
    assert trend.a() == 2
    assert (trend.with_params([3])() == 2 + dataset * 3).all()
Exemplo n.º 6
0
def test_linear_trend(dataset):
    trend = kernels.linear(dataset)
    assert len(trend.params) == 2
    assert len(trend.optimisation_params) == 2
    assert (trend.with_params([3, 4])() == 3 + dataset * 4).all()
Exemplo n.º 7
0
def test_kernel():
    x = np.array([1, 2, 3])
    linear = kernels.linear(x, a=0, b=2)
    assert list(linear()) == list(2 * x)
    assert list(linear.with_covariate(1 + x)()) == list(2 * (1 + x))
    assert list(linear()) == list(2 * x)
Exemplo n.º 8
0
def likelihood_with_trend(dataset):
    fit = GEV.fit(dataset,
                  loc=kernels.linear(np.linspace(1, len(dataset),
                                                 len(dataset))))
    return Profiler(fit, dataset)