File: test_empirical.py

package info (click to toggle)
astroml 1.0.2-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 932 kB
  • sloc: python: 5,731; makefile: 3
file content (34 lines) | stat: -rw-r--r-- 843 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import numpy as np
from numpy.testing import assert_allclose
from scipy.stats import norm
from astroML.density_estimation import\
    EmpiricalDistribution, FunctionDistribution


def test_empirical_distribution(N=1000, rseed=0):
    np.random.seed(rseed)
    X = norm.rvs(0, 1, size=N)
    dist = EmpiricalDistribution(X)
    X2 = dist.rvs(N)

    meanX = X.mean()
    meanX2 = X2.mean()

    stdX = X.std()
    stdX2 = X2.std()

    assert_allclose([meanX, stdX], [meanX2, stdX2], atol=3 / np.sqrt(N))


def test_function_distribution(N=1000, rseed=0):
    f = norm(0, 1).pdf
    # go from -10 to 10 to check interpolation in presence of zeros
    dist = FunctionDistribution(f, -10, 10)

    np.random.seed(rseed)
    X = dist.rvs(N)

    meanX = X.mean()
    stdX = X.std()

    assert_allclose([meanX, stdX], [0, 1], atol=3 / np.sqrt(N))