예제 #1
0
        return collections.deque(iterable, maxlen=n)

    n = stat.window_size
    X = [random.random() for _ in range(30)]

    for i, x in enumerate(X):
        stat.update(x)
        if i >= 1:
            assert math.isclose(stat.get(),
                                func(tail(X[:i + 1], n)),
                                abs_tol=1e-10)


@pytest.mark.parametrize(
    'stat, func',
    [(stats.Cov(), lambda x, y: np.cov(x, y)[0, 1]),
     (stats.PearsonCorr(), lambda x, y: sp_stats.pearsonr(x, y)[0])])
def test_bivariate(stat, func):

    # Shhh
    np.warnings.filterwarnings('ignore')

    X = [random.random() for _ in range(30)]
    Y = [random.random() * x for x in X]

    for i, (x, y) in enumerate(zip(X, Y)):
        stat.update(x, y)
        if i >= 1:
            assert math.isclose(stat.get(),
                                func(X[:i + 1], Y[:i + 1]),
                                abs_tol=1e-10)
예제 #2
0
 def __init__(self):
     self.x_m = stats.Mean()
     self.g_var = stats.Var()
     self.h_var = stats.Var()
     self.gh_cov = stats.Cov()
예제 #3
0
        if i < len(X) - 2:
            assert math.isclose((stat1 - stat2).get(), func(X[i + 1 :]), abs_tol=1e-10)

    # Test inplace subtraction
    X.extend(random.random() for _ in range(3))
    for i in range(30, 33):
        stat1.update(X[i])

    stat1 -= stat2
    assert math.isclose(stat1.get(), func(X[30:33]), abs_tol=1e-10)


@pytest.mark.parametrize(
    "stat1, stat2, func",
    [
        (stats.Cov(ddof=0), stats.Cov(ddof=0), functools.partial(np.cov, ddof=0)),
        (stats.Cov(ddof=1), stats.Cov(ddof=1), functools.partial(np.cov, ddof=1)),
    ],
)
def test_add_cov(stat1, stat2, func):
    X = [random.random() for _ in range(30)]
    Y = [random.random() for _ in range(30)]

    W = [random.random() for _ in range(30)]
    Z = [random.random() for _ in range(30)]

    for i, (x, y, w, z) in enumerate(zip(X, Y, W, Z)):
        stat1.update(x, y)
        stat2.update(w, z)
        if i >= 1:
            assert math.isclose(