當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。