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


Python Distribution.to_string方法代碼示例

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


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

示例1: test_to_string8

# 需要導入模塊: from dit import Distribution [as 別名]
# 或者: from dit.Distribution import to_string [as 別名]
def test_to_string8():
    outcomes = ['00', '01', '10', '11']
    pmf = [1/4]*4
    d = Distribution(outcomes, pmf)
    d = d.marginal([0])
    s = d.to_string(show_mask='!')
    s_ = """Class:          Distribution
Alphabet:       ('0', '1') for all rvs
Base:           linear
Outcome Class:  str
Outcome Length: 1 (mask: 2)
RV Names:       None

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

示例2: test_prepare_string3

# 需要導入模塊: from dit import Distribution [as 別名]
# 或者: from dit.Distribution import to_string [as 別名]
def test_prepare_string3():
    outcomes = [(0, 0), (0, 1), (1, 0), (1, 1)]
    pmf = [1/4]*4
    d = Distribution(outcomes, pmf)
    s_ = """Class:          Distribution
Alphabet:       (0, 1) for all rvs
Base:           linear
Outcome Class:  tuple
Outcome Length: 2
RV Names:       None

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

示例3: test_to_string4

# 需要導入模塊: from dit import Distribution [as 別名]
# 或者: from dit.Distribution import to_string [as 別名]
def test_to_string4():
    # Basic with marginal
    outcomes = ['00', '01', '10', '11']
    pmf = [1/4]*4
    d = Distribution(outcomes, pmf)
    d = d.marginal([0])
    s = d.to_string()
    s_ = """Class:          Distribution
Alphabet:       ('0', '1') for all rvs
Base:           linear
Outcome Class:  str
Outcome Length: 1
RV Names:       None

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

示例4: test_to_string2

# 需要導入模塊: from dit import Distribution [as 別名]
# 或者: from dit.Distribution import to_string [as 別名]
def test_to_string2():
    # Test with exact.
    outcomes = ['00', '01', '10', '11']
    pmf = [1/4]*4
    d = Distribution(outcomes, pmf)
    s = d.to_string(exact=True)
    s_ = """Class:          Distribution
Alphabet:       ('0', '1') for all rvs
Base:           linear
Outcome Class:  str
Outcome Length: 2
RV Names:       None

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

示例5: test_to_string1

# 需要導入模塊: from dit import Distribution [as 別名]
# 或者: from dit.Distribution import to_string [as 別名]
def test_to_string1():
    # Basic
    outcomes = ['00', '01', '10', '11']
    pmf = [1/4]*4
    d = Distribution(outcomes, pmf)
    s = d.to_string()
    s_ = """Class:          Distribution
Alphabet:       ('0', '1') for all rvs
Base:           linear
Outcome Class:  str
Outcome Length: 2
RV Names:       None

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

示例6: test_to_string9

# 需要導入模塊: from dit import Distribution [as 別名]
# 或者: from dit.Distribution import to_string [as 別名]
def test_to_string9():
    # Basic
    outcomes = ['00', '01', '10', '11']
    pmf = [1/4]*4
    d = Distribution(outcomes, pmf)
    d.set_base(2)
    s = d.to_string()
    s_ = """Class:          Distribution
Alphabet:       ('0', '1') for all rvs
Base:           2
Outcome Class:  str
Outcome Length: 2
RV Names:       None

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

示例7: test_prepare_string4

# 需要導入模塊: from dit import Distribution [as 別名]
# 或者: from dit.Distribution import to_string [as 別名]
def test_prepare_string4():
    class WeirdInt(int):
        def __str__(self):
            raise Exception
    outcomes = [(0, 0), (0, 1), (1, 0), (1, 1)]
    outcomes = [(WeirdInt(x), WeirdInt(y)) for (x, y) in outcomes]
    pmf = [1/4]*4
    d = Distribution(outcomes, pmf)
    s_ = """Class:          Distribution
Alphabet:       (0, 1) for all rvs
Base:           linear
Outcome Class:  tuple
Outcome Length: 2
RV Names:       None

x        p(x)
(0, 0)   0.25
(0, 1)   0.25
(1, 0)   0.25
(1, 1)   0.25"""
    s = d.to_string(str_outcomes=True)
    assert_equal(s, s_)
開發者ID:chebee7i,項目名稱:dit,代碼行數:24,代碼來源:test_distribution.py


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