当前位置: 首页>>代码示例>>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;未经允许,请勿转载。