示例#1
0
def test_standard_moment1():
    ns = range(3, 10)
    ps = np.linspace(0.1, 0.9, 9)
    for n, p in product(ns, ps):
        d = binomial(n, p)
        for i, m in {1: 0, 2: 1, 3: (1-2*p)/np.sqrt(n*p*(1-p))}.items():
            assert_almost_equal(standard_moment(d, i), m, places=5)
示例#2
0
def test_standard_deviation1():
    """ Test standard_deviation on binomial distribution """
    ns = range(2, 10)
    ps = np.linspace(0, 1, 11)
    for n, p in product(ns, ps):
        d = binomial(n, p)
        yield assert_almost_equal, standard_deviation(d), np.sqrt(n*p*(1-p))
示例#3
0
def test_mode1():
    """ Test mode on binomial distribution """
    ns = range(2, 10)
    ps = np.linspace(0, 1, 11)
    for n, p in product(ns, ps):
        d = binomial(n, p)
        yield assert_true, mode(d)[0][0] in [floor((n+1)*p), floor((n+1)*p)-1]
示例#4
0
def test_median1():
    """ Test median on binomial distribution """
    ns = range(2, 10)
    ps = np.linspace(0, 1, 11)
    for n, p in product(ns, ps):
        d = binomial(n, p)
        yield assert_true, median(d) in [floor(n*p), n*p, ceil(n*p)]
示例#5
0
def test_mean1():
    """ Test mean on binomial distribution """
    ns = range(2, 10)
    ps = np.linspace(0, 1, 11)
    for n, p in product(ns, ps):
        d = binomial(n, p)
        yield assert_almost_equal, mean(d), n*p
示例#6
0
def test_standard_moment1():
    """ Test standard_moment on binomial distribution """
    ns = range(3, 10)
    ps = np.linspace(0.1, 0.9, 9)
    for n, p in product(ns, ps):
        d = binomial(n, p)
        for i, m in {1: 0, 2: 1, 3: (1-2*p)/np.sqrt(n*p*(1-p))}.items():
            yield assert_almost_equal, standard_moment(d, i), m, 5
示例#7
0
def test_standard_moment1(n, p):
    """ Test standard_moment on binomial distribution """
    d = binomial(n, p)
    for i, m in {
            1: 0,
            2: 1,
            3: (1 - 2 * p) / np.sqrt(n * p * (1 - p))
    }.items():
        assert standard_moment(d, i) == pytest.approx(m, abs=1e-5)
示例#8
0
def test_mean1(n, p):
    """ Test mean on binomial distribution """
    d = binomial(n, p)
    assert mean(d) == pytest.approx(n * p)
示例#9
0
def test_binomial1(n):
    """ Test binomial distribution """
    d = binomial(n, 1/2)
    assert d.outcomes == tuple(range(n+1))
    assert sum(d.pmf) == pytest.approx(1)
示例#10
0
def test_binomial2(n):
    """ Test binomial distribution failures """
    with pytest.raises(ValueError):
        binomial(n, 1/2)
示例#11
0
def test_binomial1(n):
    """ Test binomial distribution """
    d = binomial(n, 1 / 2)
    assert d.outcomes == tuple(range(n + 1))
    assert sum(d.pmf) == pytest.approx(1)
示例#12
0
def test_binomial2(n):
    """ Test binomial distribution failures """
    with pytest.raises(ValueError):
        binomial(n, 1 / 2)
示例#13
0
def test_standard_deviation1(n, p):
    """ Test standard_deviation on binomial distribution """
    d = binomial(n, p)
    assert standard_deviation(d) == pytest.approx(np.sqrt(n * p * (1 - p)))
示例#14
0
def test_mean1(n, p):
    """ Test mean on binomial distribution """
    d = binomial(n, p)
    assert mean(d) == pytest.approx(n*p)
示例#15
0
def test_median1():
    ns = range(2, 10)
    ps = np.linspace(0, 1, 11)
    for n, p in product(ns, ps):
        d = binomial(n, p)
        assert(median(d) in [floor(n*p), n*p, ceil(n*p)])
示例#16
0
def test_mode1():
    ns = range(2, 10)
    ps = np.linspace(0, 1, 11)
    for n, p in product(ns, ps):
        d = binomial(n, p)
        assert(mode(d)[0][0] in [floor((n+1)*p), floor((n+1)*p)-1])
示例#17
0
def test_standard_moment1(n, p):
    """ Test standard_moment on binomial distribution """
    d = binomial(n, p)
    for i, m in {1: 0, 2: 1, 3: (1-2*p)/np.sqrt(n*p*(1-p))}.items():
        assert standard_moment(d, i) == pytest.approx(m, abs=1e-5)
示例#18
0
def test_binomial1():
    """ Test binomial distribution """
    for n in range(1, 10):
        d = binomial(n, 1 / 2)
        assert_equal(d.outcomes, tuple(range(n + 1)))
        assert_almost_equal(sum(d.pmf), 1)
示例#19
0
def test_standard_deviation1(n, p):
    """ Test standard_deviation on binomial distribution """
    d = binomial(n, p)
    assert standard_deviation(d) == pytest.approx(np.sqrt(n*p*(1-p)))
示例#20
0
def test_mode1(n, p):
    """ Test mode on binomial distribution """
    d = binomial(n, p)
    assert mode(d)[0][0] in [floor((n+1)*p), floor((n+1)*p)-1]
示例#21
0
def test_median1(n, p):
    """ Test median on binomial distribution """
    d = binomial(n, p)
    assert median(d) in [floor(n*p), n*p, ceil(n*p)]
示例#22
0
def test_median1(n, p):
    """ Test median on binomial distribution """
    d = binomial(n, p)
    assert median(d) in [floor(n * p), n * p, ceil(n * p)]
示例#23
0
def test_standard_deviation1():
    ns = range(2, 10)
    ps = np.linspace(0, 1, 11)
    for n, p in product(ns, ps):
        d = binomial(n, p)
        assert_almost_equal(standard_deviation(d), np.sqrt(n*p*(1-p)))
示例#24
0
def test_mode1(n, p):
    """ Test mode on binomial distribution """
    d = binomial(n, p)
    assert mode(d)[0][0] in [floor((n + 1) * p), floor((n + 1) * p) - 1]
示例#25
0
def test_binomial1():
    """ Test binomial distribution """
    for n in range(1, 10):
        d = binomial(n, 1/2)
        assert_equal(d.outcomes, tuple(range(n+1)))
        assert_almost_equal(sum(d.pmf), 1)
示例#26
0
def test_mean1():
    ns = range(2, 10)
    ps = np.linspace(0, 1, 11)
    for n, p in product(ns, ps):
        d = binomial(n, p)
        assert_almost_equal(mean(d), n*p)
示例#27
0
def test_binomial1():
    for n in range(1, 10):
        d = binomial(n, 1/2)
        assert_equal(d.outcomes, tuple(range(n+1)))
        assert_almost_equal(sum(d.pmf), 1)