本文整理汇总了Python中dit.Distribution类的典型用法代码示例。如果您正苦于以下问题:Python Distribution类的具体用法?Python Distribution怎么用?Python Distribution使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Distribution类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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))
示例2: test_parse_rvs2
def test_parse_rvs2():
outcomes = ['00', '11']
pmf = [1/2]*2
d = Distribution(outcomes, pmf)
d.set_rv_names('XY')
with pytest.raises(ditException):
parse_rvs(d, ['X', 'Y', 'Z'])
示例3: test_pr_1
def test_pr_1():
"""
Test
"""
d1 = Distribution(list(product([0, 1], repeat=4)), [1/16]*16)
d2 = pr_box(0.0)
assert d1.is_approx_equal(d2)
示例4: test_to_dict
def test_to_dict():
outcomes = ['00', '01', '10', '11']
pmf = [1/4]*4
d = Distribution(outcomes, pmf)
dd = d.to_dict()
for o, p in dd.items():
yield assert_almost_equal, d[o], p
示例5: pr_box
def pr_box(eta=1, name=False):
"""
The Popescu-Rohrlich box, or PR box, is the canonical non-signalling, non-local probability
distribution used in the study of superquantum correlations. It has two space-like seperated
inputs, X and Y, and two associated outputs, A and B.
`eta` is the noise level of this correlation. For 0 <= eta <= 1/2 the box can be realized
classically. For 1/2 < eta <= 1/sqrt(2) the box can be realized quantum-mechanically.
Parameters
----------
eta : float, 0 <= eta <= 1
The noise level of the box. Defaults to 1.
name : bool
Whether to set rv names or not. Defaults to False.
Returns
-------
pr : Distribution
The PR box distribution.
"""
outcomes = list(product([0, 1], repeat=4))
pmf = [ ((1+eta)/16 if (x*y == a^b) else (1-eta)/16) for x, y, a, b in outcomes ]
pr = Distribution(outcomes, pmf)
if name:
pr.set_rv_names("XYAB")
return pr
示例6: test_K4
def test_K4():
outcomes = ['00', '01', '10', '11', '22', '33']
pmf = [1/8, 1/8, 1/8, 1/8, 1/4, 1/4]
d = Distribution(outcomes, pmf)
assert_almost_equal(K(d), 1.5)
assert_almost_equal(K(d, [[0],[1]]), 1.5)
d.set_rv_names("XY")
assert_almost_equal(K(d, [['X'],['Y']]), 1.5)
示例7: test_K1
def test_K1():
outcomes = ['00', '11']
pmf = [1/2, 1/2]
d = Distribution(outcomes, pmf)
assert_almost_equal(K(d), 1.0)
assert_almost_equal(K(d, [[0],[1]]), 1.0)
d.set_rv_names("XY")
assert_almost_equal(K(d, [['X'],['Y']]), 1.0)
示例8: 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))
示例9: test_K3
def test_K3():
""" Test K for mixed events """
outcomes = ['00', '01', '11']
pmf = [1/3, 1/3, 1/3]
d = Distribution(outcomes, pmf)
assert_almost_equal(K(d), 0.0)
assert_almost_equal(K(d, [[0], [1]]), 0.0)
d.set_rv_names("XY")
assert_almost_equal(K(d, [['X'], ['Y']]), 0.0)
示例10: test_K4
def test_K4():
""" Test K in a canonical example """
outcomes = ['00', '01', '10', '11', '22', '33']
pmf = [1/8, 1/8, 1/8, 1/8, 1/4, 1/4]
d = Distribution(outcomes, pmf)
assert K(d) == pytest.approx(1.5)
assert K(d, [[0], [1]]) == pytest.approx(1.5)
d.set_rv_names("XY")
assert K(d, [['X'], ['Y']]) == pytest.approx(1.5)
示例11: test_K1
def test_K1():
""" Test K for dependent events """
outcomes = ['00', '11']
pmf = [1/2, 1/2]
d = Distribution(outcomes, pmf)
assert K(d) == pytest.approx(1.0)
assert K(d, [[0], [1]]) == pytest.approx(1.0)
d.set_rv_names("XY")
assert K(d, [['X'], ['Y']]) == pytest.approx(1.0)
示例12: test_K3
def test_K3():
""" Test K for mixed events """
outcomes = ['00', '01', '11']
pmf = [1/3, 1/3, 1/3]
d = Distribution(outcomes, pmf)
assert K(d) == pytest.approx(0.0)
assert K(d, [[0], [1]]) == pytest.approx(0.0)
d.set_rv_names("XY")
assert K(d, [['X'], ['Y']]) == pytest.approx(0.0)
示例13: test_K2
def test_K2():
""" Test conditional K for dependent events """
outcomes = ['00', '11']
pmf = [1/2, 1/2]
d = Distribution(outcomes, pmf)
assert_almost_equal(K(d, [[0], [1]], [0]), 0.0)
assert_almost_equal(K(d, [[0], [1]], [1]), 0.0)
d.set_rv_names("XY")
assert_almost_equal(K(d, [['X'], ['Y']], ['X']), 0.0)
assert_almost_equal(K(d, [['X'], ['Y']], ['Y']), 0.0)
示例14: test_really_big_words
def test_really_big_words():
"""
Test to ensure that large but sparse outcomes are fast.
"""
outcomes = ['01'*45, '10'*45]
pmf = [1/2]*2
d = Distribution(outcomes, pmf)
d = d.coalesce([range(30), range(30, 60), range(60, 90)])
new_outcomes = (('10'*15,)*3, ('01'*15,)*3)
assert_equal(d.outcomes, new_outcomes)
示例15: test_insert_join
def test_insert_join():
""" Test insert_join """
outcomes = ['00', '01', '10', '11']
pmf = [1/4]*4
d = Distribution(outcomes, pmf)
assert_raises(IndexError, insert_join, d, 5, [[0], [1]])
for idx in range(d.outcome_length()):
d2 = insert_join(d, idx, [[0], [1]])
m = d2.marginal([idx])
npt.assert_allclose(d2.pmf, m.pmf)