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)
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))
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]
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)]
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
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
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)
def test_mean1(n, p): """ Test mean on binomial distribution """ d = binomial(n, p) assert mean(d) == pytest.approx(n * p)
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)
def test_binomial2(n): """ Test binomial distribution failures """ with pytest.raises(ValueError): binomial(n, 1/2)
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)
def test_binomial2(n): """ Test binomial distribution failures """ with pytest.raises(ValueError): binomial(n, 1 / 2)
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)))
def test_mean1(n, p): """ Test mean on binomial distribution """ d = binomial(n, p) assert mean(d) == pytest.approx(n*p)
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)])
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])
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)
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)
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)))
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]
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)]
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)]
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)))
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]
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)
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)
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)