当前位置: 首页>>代码示例>>Python>>正文


Python dit.Distribution类代码示例

本文整理汇总了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))
开发者ID:gto00002,项目名称:dit,代码行数:7,代码来源:test_npscalardist.py

示例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'])
开发者ID:Autoplectic,项目名称:dit,代码行数:7,代码来源:test_helpers.py

示例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)
开发者ID:Autoplectic,项目名称:dit,代码行数:7,代码来源:test_pr_box.py

示例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
开发者ID:chebee7i,项目名称:dit,代码行数:7,代码来源:test_distribution.py

示例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
开发者ID:Autoplectic,项目名称:dit,代码行数:30,代码来源:nonsignalling_boxes.py

示例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)
开发者ID:fiatflux,项目名称:dit,代码行数:8,代码来源:test_ci.py

示例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)
开发者ID:fiatflux,项目名称:dit,代码行数:8,代码来源:test_ci.py

示例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))
开发者ID:manolomartinez,项目名称:dit,代码行数:8,代码来源:test_npscalardist.py

示例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)
开发者ID:chebee7i,项目名称:dit,代码行数:9,代码来源:test_gk_common_information.py

示例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)
开发者ID:Autoplectic,项目名称:dit,代码行数:9,代码来源:test_gk_common_information.py

示例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)
开发者ID:Autoplectic,项目名称:dit,代码行数:9,代码来源:test_gk_common_information.py

示例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)
开发者ID:Autoplectic,项目名称:dit,代码行数:9,代码来源:test_gk_common_information.py

示例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)
开发者ID:chebee7i,项目名称:dit,代码行数:10,代码来源:test_gk_common_information.py

示例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)
开发者ID:chebee7i,项目名称:dit,代码行数:10,代码来源:test_distribution.py

示例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)
开发者ID:chebee7i,项目名称:dit,代码行数:11,代码来源:test_lattice.py


注:本文中的dit.Distribution类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。