Пример #1
0
def test_printing():
    assert str(Normal(x + y, z)) == "Normal(x + y, z)"
    assert str(Sample([x, y, 1])) in [
        "Sample([x, y, 1])",
        "Sample([y, 1, x])",
        "Sample([1, x, y])",
        "Sample([y, x, 1])",
        "Sample([x, 1, y])",
        "Sample([1, y, x])",
    ]
    assert str(Uniform(x, y)) == "Uniform(x, y)"
    assert str(Uniform(x + y, y)) == "Uniform(x + y, y)"
Пример #2
0
def test_fit():
    import random
    random.seed(1234)
    n = Normal.fit(Uniform.fit(Normal(2, 1.5).random(1000)))
    #print n.mean
    #print n.stddev
    assert abs(n.mean - 2) < 0.3
    assert abs(n.stddev - 1.5) < 0.3
    n = Normal.fit([1, 2, 3, 4, 5])
    assert n.mean == 3
    assert n.stddev == sqrt(2)
    n = Uniform.fit([1, 2, 3, 4, 5])
    assert n.mean == 3
    assert n.stddev == sqrt(2)
Пример #3
0
def test_fit():
    import random
    random.seed(1234)
    n = Normal.fit(Uniform.fit(Normal(2, 1.5).random(1000)))
    #print n.mean
    #print n.stddev
    assert abs(n.mean - 2) < 0.3
    assert abs(n.stddev - 1.5) < 0.3
    n = Normal.fit([1, 2, 3, 4, 5])
    assert n.mean == 3
    assert n.stddev == sqrt(2)
    n = Uniform.fit([1, 2, 3, 4, 5])
    assert n.mean == 3
    assert n.stddev == sqrt(2)
Пример #4
0
def test_uniform():
    U = Uniform(-3, -1)
    assert str(U) == "Uniform(-3, -1)"
    assert repr(U) == "Uniform(-3, -1)"
    x = U.random()
    assert x < -1 and x > -3
    assert U.mean == -2
    assert U.confidence(1) == (-3, -1)
    assert U.confidence(Rational(1, 2)) == (Rational(-5, 2), Rational(-3, 2))
    assert U.pdf(-4) == 0
    assert U.pdf(-Rational(3, 2)) == Rational(1, 2)
    assert U.pdf(0) == 0
    assert U.cdf(-4) == 0
    assert U.cdf(-Rational(3, 2)) == Rational(3, 4)
    assert U.cdf(0) == 1
Пример #5
0
def test_Uniform():
    assert str(Uniform(x, y)) == "Uniform(x, y)"
    assert str(Uniform(x + y, y)) == "Uniform(x + y, y)"
Пример #6
0
def test_statistics():
    x = Symbol("x")
    y = Symbol("y")
    for c in (ContinuousProbability, ContinuousProbability(), Normal,
              Normal(x, y), Sample, Sample([1, 3, 4]), Uniform, Uniform(x, y)):
        check(c)
Пример #7
0
def test_uniform():
    U = Uniform(-3, -1)
    assert str(U) == "Uniform(-3, -1)"
    assert repr(U) == "Uniform(-3, -1)"
    x = U.random()
    assert x < -1 and x > -3
    assert U.mean == -2
    assert U.confidence(1) == (-3, -1)
    assert U.confidence(Rational(1, 2)) == (Rational(-5, 2), Rational(-3, 2))
    assert U.pdf(-4) == 0
    assert U.pdf(-Rational(3, 2)) == Rational(1, 2)
    assert U.pdf(0) == 0
    assert U.cdf(-4) == 0
    assert U.cdf(-Rational(3, 2)) == Rational(3, 4)
    assert U.cdf(0) == 1
Пример #8
0
def test_pickling():
    for c in (ContinuousProbability, ContinuousProbability(), Normal,
              Normal(x, y), Sample, Sample([1, 3, 4]), Uniform, Uniform(x, y)):
        check(c)