當前位置: 首頁>>代碼示例>>Python>>正文


Python Distribution.set_rv_names方法代碼示例

本文整理匯總了Python中dit.Distribution.set_rv_names方法的典型用法代碼示例。如果您正苦於以下問題:Python Distribution.set_rv_names方法的具體用法?Python Distribution.set_rv_names怎麽用?Python Distribution.set_rv_names使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在dit.Distribution的用法示例。


在下文中一共展示了Distribution.set_rv_names方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: pr_box

# 需要導入模塊: from dit import Distribution [as 別名]
# 或者: from dit.Distribution import set_rv_names [as 別名]
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,代碼行數:32,代碼來源:nonsignalling_boxes.py

示例2: test_parse_rvs2

# 需要導入模塊: from dit import Distribution [as 別名]
# 或者: from dit.Distribution import set_rv_names [as 別名]
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,代碼行數:9,代碼來源:test_helpers.py

示例3: test_K1

# 需要導入模塊: from dit import Distribution [as 別名]
# 或者: from dit.Distribution import set_rv_names [as 別名]
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,代碼行數:10,代碼來源:test_ci.py

示例4: test_K4

# 需要導入模塊: from dit import Distribution [as 別名]
# 或者: from dit.Distribution import set_rv_names [as 別名]
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,代碼行數:10,代碼來源:test_ci.py

示例5: test_K3

# 需要導入模塊: from dit import Distribution [as 別名]
# 或者: from dit.Distribution import set_rv_names [as 別名]
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,代碼行數:11,代碼來源:test_gk_common_information.py

示例6: test_K4

# 需要導入模塊: from dit import Distribution [as 別名]
# 或者: from dit.Distribution import set_rv_names [as 別名]
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,代碼行數:11,代碼來源:test_gk_common_information.py

示例7: test_K3

# 需要導入模塊: from dit import Distribution [as 別名]
# 或者: from dit.Distribution import set_rv_names [as 別名]
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,代碼行數:11,代碼來源:test_gk_common_information.py

示例8: test_K1

# 需要導入模塊: from dit import Distribution [as 別名]
# 或者: from dit.Distribution import set_rv_names [as 別名]
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,代碼行數:11,代碼來源:test_gk_common_information.py

示例9: test_K2

# 需要導入模塊: from dit import Distribution [as 別名]
# 或者: from dit.Distribution import set_rv_names [as 別名]
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,代碼行數:12,代碼來源:test_gk_common_information.py

示例10: test_K5

# 需要導入模塊: from dit import Distribution [as 別名]
# 或者: from dit.Distribution import set_rv_names [as 別名]
def test_K5():
	outcomes = ['000', '010', '100', '110', '221', '331']
	pmf = [1/8, 1/8, 1/8, 1/8, 1/4, 1/4]
	d = Distribution(outcomes, pmf)
	assert_almost_equal(K(d, [[0],[1]]), 1.5)
	assert_almost_equal(K(d), 1.0)
	assert_almost_equal(K(d, [[0],[1],[2]]), 1.0)
	d.set_rv_names("XYZ")
	assert_almost_equal(K(d, [['X'],['Y']]), 1.5)
	assert_almost_equal(K(d, [['X'],['Y'],['Z']]), 1.0)
	assert_almost_equal(K(d, ['X', 'Y'], ['Z']), 0.5)
	assert_almost_equal(K(d, ['XY', 'YZ']), 2.0)
開發者ID:fiatflux,項目名稱:dit,代碼行數:14,代碼來源:test_ci.py

示例11: test_K5

# 需要導入模塊: from dit import Distribution [as 別名]
# 或者: from dit.Distribution import set_rv_names [as 別名]
def test_K5():
    """ Test K on subvariables and conditionals """
    outcomes = ['000', '010', '100', '110', '221', '331']
    pmf = [1/8, 1/8, 1/8, 1/8, 1/4, 1/4]
    d = Distribution(outcomes, pmf)
    assert K(d, [[0], [1]]) == pytest.approx(1.5)
    assert K(d) == pytest.approx(1.0)
    assert K(d, [[0], [1], [2]]) == pytest.approx(1.0)
    d.set_rv_names("XYZ")
    assert K(d, [['X'], ['Y']]) == pytest.approx(1.5)
    assert K(d, [['X'], ['Y'], ['Z']]) == pytest.approx(1.0)
    assert K(d, ['X', 'Y'], ['Z']) == pytest.approx(0.5)
    assert K(d, ['XY', 'YZ']) == pytest.approx(2.0)
開發者ID:Autoplectic,項目名稱:dit,代碼行數:15,代碼來源:test_gk_common_information.py

示例12: test_M2

# 需要導入模塊: from dit import Distribution [as 別名]
# 或者: from dit.Distribution import set_rv_names [as 別名]
def test_M2():
    """ Test M with rv names """
    outcomes = ['000',
                'a00',
                '00c',
                'a0c',
                '011',
                'a11',
                '101',
                'b01',
                '01d',
                'a1d',
                '10d',
                'b0d',
                '110',
                'b10',
                '11c',
                'b1c',]
    pmf = [1/16]*16
    d = Distribution(outcomes, pmf)
    d.set_rv_names('XYZ')
    assert_almost_equal(M(d), 2.0)
開發者ID:manolomartinez,項目名稱:dit,代碼行數:24,代碼來源:test_joint_mss.py

示例13: Distribution

# 需要導入模塊: from dit import Distribution [as 別名]
# 或者: from dit.Distribution import set_rv_names [as 別名]
from hypothesis import given

import numpy as np

from dit import Distribution
from dit.example_dists.intrinsic import intrinsic_1, intrinsic_2, intrinsic_3
from dit.exceptions import ditException
from dit.multivariate import total_correlation
from dit.multivariate.secret_key_agreement import intrinsic_mutual_informations as IMI


from dit.utils.testing import distributions

dist1 = Distribution([(0,0,0), (0,1,1), (1,0,1), (1,1,0), (2,2,2), (3,3,3)], [1/8]*4+[1/4]*2)
dist2 = Distribution(['000', '011', '101', '110', '222', '333'], [1/8]*4+[1/4]*2)
dist2.set_rv_names('XYZ')
dist3 = Distribution(['00000', '00101', '11001', '11100', '22220', '33330'], [1/8]*4+[1/4]*2)
dist4 = Distribution(['00000', '00101', '11001', '11100', '22220', '33330'], [1/8]*4+[1/4]*2)
dist4.set_rv_names('VWXYZ')
dist5 = Distribution(['0000', '0011', '0101', '0110', '1001', '1010', '1100', '1111'], [1/8]*8)
dist6 = Distribution(['0000', '0011', '0101', '0110', '1001', '1010', '1100', '1111'], [1/8]*8)
dist6.set_rv_names('WXYZ')


@pytest.mark.flaky(reruns=5)
def test_itc1():
    """
    Test against standard result.
    """
    itc = IMI.intrinsic_total_correlation(dist1, [[0], [1]], [2])
    assert itc == pytest.approx(0)
開發者ID:Autoplectic,項目名稱:dit,代碼行數:33,代碼來源:test_intrinsic_mutual_information.py

示例14: Distribution

# 需要導入模塊: from dit import Distribution [as 別名]
# 或者: from dit.Distribution import set_rv_names [as 別名]
"""

from __future__ import division

import pytest

import numpy as np

from dit import Distribution
from dit.profiles import ConnectedInformations, ConnectedDualInformations

ex1 = Distribution(['000', '001', '010', '011', '100', '101', '110', '111'], [1/8]*8)
ex2 = Distribution(['000', '111'], [1/2]*2)
ex3 = Distribution(['000', '001', '110', '111'], [1/4]*4)
ex4 = Distribution(['000', '011', '101', '110'], [1/4]*4)
ex4.set_rv_names('XYZ')


@pytest.mark.parametrize(('ex', 'prof'), [
    (ex1, (0.0, 0.0, 0.0)),
    (ex2, (0.0, 2.0, 0.0)),
    (ex3, (0.0, 1.0, 0.0)),
    (ex4, (0.0, 0.0, 1.0)),
])
def test_connected_information(ex, prof):
    """
    Test against known examples.
    """
    ci = ConnectedInformations(ex)
    assert np.allclose([ci.profile[i] for i in (1, 2, 3)], prof, atol=1e-5)
開發者ID:Autoplectic,項目名稱:dit,代碼行數:32,代碼來源:test_schneidman.py

示例15: test_parse_rvs2

# 需要導入模塊: from dit import Distribution [as 別名]
# 或者: from dit.Distribution import set_rv_names [as 別名]
def test_parse_rvs2():
    outcomes = ['00', '11']
    pmf = [1/2]*2
    d = Distribution(outcomes, pmf)
    d.set_rv_names('XY')
    assert_raises(ditException, parse_rvs, d, ['X', 'Y', 'Z'])
開發者ID:chebee7i,項目名稱:dit,代碼行數:8,代碼來源:test_helpers.py


注:本文中的dit.Distribution.set_rv_names方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。