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


Python dit.ScalarDistribution類代碼示例

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


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

示例1: test_setitem1

def test_setitem1():
    pmf = [1 / 2, 1 / 2]
    d = ScalarDistribution(pmf)
    d[0] = 1
    d[1] = 0
    d.make_sparse()
    assert_equal(d.outcomes, (0,))
開發者ID:gto00002,項目名稱:dit,代碼行數:7,代碼來源:test_npscalardist.py

示例2: test_setitem3

def test_setitem3():
    outcomes = (0, 1)
    pmf = [1 / 2, 1 / 2]
    d = ScalarDistribution(outcomes, pmf, sample_space=(0, 1, 2))
    d[2] = 1 / 2
    d.normalize()
    assert_array_almost_equal(d.pmf, [1 / 3] * 3)
開發者ID:gto00002,項目名稱:dit,代碼行數:7,代碼來源:test_npscalardist.py

示例3: test_init9

def test_init9():
    outcomes = [0, 1, 2]
    pmf = [1 / 3] * 3
    d1 = ScalarDistribution(outcomes, pmf)
    d2 = ScalarDistribution.from_distribution(d1, base=10)
    d1.set_base(10)
    assert_true(d1.is_approx_equal(d2))
開發者ID:gto00002,項目名稱:dit,代碼行數:7,代碼來源:test_npscalardist.py

示例4: test_disequilibrium6

def test_disequilibrium6(n):
    """
    Test that peaked Distributions have non-zero disequilibrium.
    """
    d = ScalarDistribution([1] + [0]*(n-1))
    d.make_dense()
    d = Distribution.from_distribution(d)
    assert disequilibrium(d) >= 0
開發者ID:Autoplectic,項目名稱:dit,代碼行數:8,代碼來源:test_disequilibrium.py

示例5: test_LMPR_complexity5

def test_LMPR_complexity5(n):
    """
    Test that peaked Distributions have zero complexity.
    """
    d = ScalarDistribution([1] + [0]*(n-1))
    d.make_dense()
    d = Distribution.from_distribution(d)
    assert LMPR_complexity(d) == pytest.approx(0)
開發者ID:Autoplectic,項目名稱:dit,代碼行數:8,代碼來源:test_disequilibrium.py

示例6: test_disequilibrium6

def test_disequilibrium6():
    """
    Test that peaked Distributions have non-zero disequilibrium.
    """
    for n in range(2, 11):
        d = ScalarDistribution([1] + [0]*(n-1))
        d.make_dense()
        d = Distribution.from_distribution(d)
        yield assert_greater, disequilibrium(d), 0
開發者ID:manolomartinez,項目名稱:dit,代碼行數:9,代碼來源:test_disequilibrium.py

示例7: test_LMPR_complexity4

def test_LMPR_complexity4():
    """
    Test that peaked Distributions have zero complexity.
    """
    for n in range(2, 11):
        d = ScalarDistribution([1] + [0]*(n-1))
        d.make_dense()
        d = Distribution.from_distribution(d)
        yield assert_almost_equal, LMPR_complexity(d), 0
開發者ID:manolomartinez,項目名稱:dit,代碼行數:9,代碼來源:test_disequilibrium.py

示例8: test_to_string10

def test_to_string10():
    # Basic
    d = ScalarDistribution([], sample_space=[0, 1], validate=False)
    s = d.to_string()
    s_ = """Class:    ScalarDistribution
Alphabet: (0, 1)
Base:     2

x   log p(x)"""
    assert_equal(s, s_)
開發者ID:chebee7i,項目名稱:dit,代碼行數:10,代碼來源:test_distribution.py

示例9: test_mss

def test_mss():
    """
    Test the construction of minimal sufficient statistics.
    """
    d = get_gm()
    d1 = mss(d, [0, 1], [2, 3])
    d2 = mss(d, [2, 3], [0, 1])
    dist = ScalarDistribution([0, 1], [1 / 3, 2 / 3])
    assert_true(dist.is_approx_equal(d1))
    assert_true(dist.is_approx_equal(d2))
    assert_true(d1.is_approx_equal(d2))
開發者ID:gto00002,項目名稱:dit,代碼行數:11,代碼來源:test_minimal_sufficient_statistic.py

示例10: 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

示例11: test_to_string7

def test_to_string7():
    # Basic
    outcomes = ['00', '01', '10', '11']
    pmf = [1/4]*4
    d = ScalarDistribution(outcomes, pmf)
    s = d.to_string()
    s_ = """Class:    ScalarDistribution
Alphabet: ('00', '01', '10', '11')
Base:     linear

x    p(x)
00   0.25
01   0.25
10   0.25
11   0.25"""
    assert_equal(s, s_)
開發者ID:chebee7i,項目名稱:dit,代碼行數:16,代碼來源:test_distribution.py

示例12: 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

示例13: test_dist_from_induced

def test_dist_from_induced():
    """ Test dist_from_induced_sigalg """
    outcomes = [(0,), (1,), (2,)]
    pmf = np.array([1/3] * 3)
    d = ScalarDistribution(outcomes, pmf)

    sigalg = frozenset(map(frozenset, d.event_space()))
    d2 = dist_from_induced_sigalg(d, sigalg)
    assert np.allclose(pmf, d2.pmf)

    sigalg = [(), ((0,),), ((1,), (2,)), ((0,), (1,), (2,))]
    sigalg = frozenset(map(frozenset, sigalg))
    d2 = dist_from_induced_sigalg(d, sigalg, int_outcomes=True)
    pmf = np.array([1/3, 2/3])
    assert np.allclose(pmf, d2.pmf)

    d2 = dist_from_induced_sigalg(d, sigalg, int_outcomes=False)
    outcomes = (((0,),), ((1,), (2,)))
    assert outcomes == d2.outcomes
開發者ID:Autoplectic,項目名稱:dit,代碼行數:19,代碼來源:test_lattice.py

示例14: test_del2

def test_del2():
    d = ScalarDistribution([1 / 2, 1 / 2])
    d.make_dense()
    del d[1]
    d.normalize()
    assert_almost_equal(d[0], 1)
開發者ID:gto00002,項目名稱:dit,代碼行數:6,代碼來源:test_npscalardist.py

示例15: test_is_approx_equal3

def test_is_approx_equal3():
    d1 = ScalarDistribution([1 / 2, 1 / 2], sample_space=(0, 1, 2))
    d2 = ScalarDistribution([1 / 2, 1 / 2])
    assert_false(d1.is_approx_equal(d2))
開發者ID:gto00002,項目名稱:dit,代碼行數:4,代碼來源:test_npscalardist.py


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