Пример #1
0
def test_l1tf_on_mock(alpha=1.0, beta=0.0, noise=0.0, doplot=doplot):
    if doplot:
        plt.clf()
    mock = make_l1tf_mock(noise=noise)
    l1tf_fit = myl1tf.l1tf(mock["y"], alpha=alpha, beta=beta)

    resid = l1tf_fit["x"] - mock["y_with_seasonal"]
    assert_is_good(resid, mean_abs_resid_max=0.035, max_abs_resid_max=0.1)

    if doplot:
        plt.plot(mock["x"], l1tf_fit["x"], marker="o", linestyle="-", label="L1TF, alpha=%s" % alpha)
        plt.legend(loc="lower center")
        plt.show()
Пример #2
0
def test_first_derivative_on_noisy_data(
    num=10, slope=1.0, offset=3.0, noise=1.0, alpha=1.0, beta=0.0, seed=7863, doplot=doplot
):
    if doplot:
        plt.clf()
    np.random.seed(seed)
    i = np.arange(num)
    x = i * slope + offset
    y = x + noise * np.random.randn(num)
    l1tf_fit = myl1tf.l1tf(y, alpha=alpha, beta=beta)

    resid = l1tf_fit["x"] - y
    assert_is_good(resid, mean_abs_resid_max=0.6, max_abs_resid_max=1)

    if doplot:
        plt.plot(i, y, marker="o", markersize=12, alpha=0.8, linestyle="")
        plt.plot(i, l1tf_fit["x"], marker="o", linestyle="-", markersize=4, alpha=0.8)
Пример #3
0
def test_l1tf_on_mock_with_period_l1p(alpha=1.0, period=6, eta=0.1, sea_amp=0.05, doplot=doplot):
    if doplot:
        plt.clf()
    mock = make_l1tf_mock(period=period, sea_amp=sea_amp)
    l1tf_fit = myl1tf.l1tf(mock["y_with_seasonal"], alpha=alpha, period=period, eta=eta, with_l1p=True)

    resid = l1tf_fit["x"] - mock["y_with_seasonal"]
    assert_is_good(resid, mean_abs_resid_max=0.035, max_abs_resid_max=0.1)

    if doplot:
        lab = "L1TF, period=%s, alpha=%s, eta=%s" % (period, alpha, eta)
        plt.plot(mock["x"], l1tf_fit["x"], marker="o", linestyle="-", markersize=4, alpha=0.8, label=lab)
        lab = "L1TF + seasonal, period=%s, alpha=%s, eta=%s" % (period, alpha, eta)
        plt.plot(mock["x"], l1tf_fit["x_with_seasonal"], marker="o", markersize=4, linestyle="-", label=lab)
        plt.legend(loc="lower left")
        plt.ylim(0, 1)
        plt.show()
Пример #4
0
def test_l1tf_on_mock_with_period_l1p_with_spike_and_step(alpha=0.5, period=6, eta=0.1, doplot=doplot, sea_amp=0.05):
    # no test for this yet

    if doplot:
        plt.clf()
    mock = make_l1tf_mock2(period=period, sea_amp=sea_amp)
    y = mock["y_with_seasonal"]
    ymax = max(y)
    l1tf_fit = myl1tf.l1tf(y, alpha=alpha, period=period, eta=eta, with_l1p=True)
    if doplot:
        lab = "L1TF, period=%s, alpha=%s, eta=%s" % (period, alpha, eta)
        plt.plot(mock["x"], l1tf_fit["x"], marker="o", linestyle="-", markersize=4, alpha=0.8, label=lab)
        lab = "L1TF + seasonal, period=%s, alpha=%s, eta=%s" % (period, alpha, eta)
        plt.plot(mock["x"], l1tf_fit["x_with_seasonal"], marker="o", markersize=4, linestyle="-", label=lab)
        plt.legend(loc="upper left")
        plt.ylim(0, ymax)
        plt.plot(mock["x"], y)
        plt.show()
    return l1tf_fit