本文整理汇总了Python中dit.ScalarDistribution类的典型用法代码示例。如果您正苦于以下问题:Python ScalarDistribution类的具体用法?Python ScalarDistribution怎么用?Python ScalarDistribution使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ScalarDistribution类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_setitem1
def test_setitem1():
pmf = [1 / 2, 1 / 2]
d = ScalarDistribution(pmf)
d[0] = 1
d[1] = 0
d.make_sparse()
assert_equal(d.outcomes, (0,))
示例2: test_setitem3
def test_setitem3():
outcomes = (0, 1)
pmf = [1 / 2, 1 / 2]
d = ScalarDistribution(outcomes, pmf, sample_space=(0, 1, 2))
d[2] = 1 / 2
d.normalize()
assert_array_almost_equal(d.pmf, [1 / 3] * 3)
示例3: test_init9
def test_init9():
outcomes = [0, 1, 2]
pmf = [1 / 3] * 3
d1 = ScalarDistribution(outcomes, pmf)
d2 = ScalarDistribution.from_distribution(d1, base=10)
d1.set_base(10)
assert_true(d1.is_approx_equal(d2))
示例4: test_disequilibrium6
def test_disequilibrium6(n):
"""
Test that peaked Distributions have non-zero disequilibrium.
"""
d = ScalarDistribution([1] + [0]*(n-1))
d.make_dense()
d = Distribution.from_distribution(d)
assert disequilibrium(d) >= 0
示例5: test_LMPR_complexity5
def test_LMPR_complexity5(n):
"""
Test that peaked Distributions have zero complexity.
"""
d = ScalarDistribution([1] + [0]*(n-1))
d.make_dense()
d = Distribution.from_distribution(d)
assert LMPR_complexity(d) == pytest.approx(0)
示例6: test_disequilibrium6
def test_disequilibrium6():
"""
Test that peaked Distributions have non-zero disequilibrium.
"""
for n in range(2, 11):
d = ScalarDistribution([1] + [0]*(n-1))
d.make_dense()
d = Distribution.from_distribution(d)
yield assert_greater, disequilibrium(d), 0
示例7: test_LMPR_complexity4
def test_LMPR_complexity4():
"""
Test that peaked Distributions have zero complexity.
"""
for n in range(2, 11):
d = ScalarDistribution([1] + [0]*(n-1))
d.make_dense()
d = Distribution.from_distribution(d)
yield assert_almost_equal, LMPR_complexity(d), 0
示例8: test_to_string10
def test_to_string10():
# Basic
d = ScalarDistribution([], sample_space=[0, 1], validate=False)
s = d.to_string()
s_ = """Class: ScalarDistribution
Alphabet: (0, 1)
Base: 2
x log p(x)"""
assert_equal(s, s_)
示例9: test_mss
def test_mss():
"""
Test the construction of minimal sufficient statistics.
"""
d = get_gm()
d1 = mss(d, [0, 1], [2, 3])
d2 = mss(d, [2, 3], [0, 1])
dist = ScalarDistribution([0, 1], [1 / 3, 2 / 3])
assert_true(dist.is_approx_equal(d1))
assert_true(dist.is_approx_equal(d2))
assert_true(d1.is_approx_equal(d2))
示例10: test_init11
def test_init11():
outcomes = ["0", "1"]
pmf = [1 / 2, 1 / 2]
d = Distribution(outcomes, pmf)
sd = ScalarDistribution.from_distribution(d)
# Different sample space representations
assert_false(d.is_approx_equal(sd))
示例11: test_to_string7
def test_to_string7():
# Basic
outcomes = ['00', '01', '10', '11']
pmf = [1/4]*4
d = ScalarDistribution(outcomes, pmf)
s = d.to_string()
s_ = """Class: ScalarDistribution
Alphabet: ('00', '01', '10', '11')
Base: linear
x p(x)
00 0.25
01 0.25
10 0.25
11 0.25"""
assert_equal(s, s_)
示例12: test_init12
def test_init12():
outcomes = ['0', '1']
pmf = [1/2, 1/2]
d = Distribution(outcomes, pmf)
sd = ScalarDistribution.from_distribution(d, base=10)
d.set_base(10)
# Different sample space representations
assert_false(d.is_approx_equal(sd))
示例13: test_dist_from_induced
def test_dist_from_induced():
""" Test dist_from_induced_sigalg """
outcomes = [(0,), (1,), (2,)]
pmf = np.array([1/3] * 3)
d = ScalarDistribution(outcomes, pmf)
sigalg = frozenset(map(frozenset, d.event_space()))
d2 = dist_from_induced_sigalg(d, sigalg)
assert np.allclose(pmf, d2.pmf)
sigalg = [(), ((0,),), ((1,), (2,)), ((0,), (1,), (2,))]
sigalg = frozenset(map(frozenset, sigalg))
d2 = dist_from_induced_sigalg(d, sigalg, int_outcomes=True)
pmf = np.array([1/3, 2/3])
assert np.allclose(pmf, d2.pmf)
d2 = dist_from_induced_sigalg(d, sigalg, int_outcomes=False)
outcomes = (((0,),), ((1,), (2,)))
assert outcomes == d2.outcomes
示例14: test_del2
def test_del2():
d = ScalarDistribution([1 / 2, 1 / 2])
d.make_dense()
del d[1]
d.normalize()
assert_almost_equal(d[0], 1)
示例15: test_is_approx_equal3
def test_is_approx_equal3():
d1 = ScalarDistribution([1 / 2, 1 / 2], sample_space=(0, 1, 2))
d2 = ScalarDistribution([1 / 2, 1 / 2])
assert_false(d1.is_approx_equal(d2))