コード例 #1
0
ファイル: test_npdist.py プロジェクト: chebee7i/dit
def test_setitem2():
    d = Distribution(['00', '11'], [1, 0])
    d.make_sparse()
    d['11'] = 1/2
    d.normalize()
    assert_true('11' in d)
    assert_almost_equal(d['11'], 1/3)
コード例 #2
0
ファイル: test_npdist.py プロジェクト: skinnersrat/dit
def test_setitem2():
    d = Distribution(['00', '11'], [1, 0])
    d.make_sparse()
    d['11'] = 1 / 2
    d.normalize()
    assert '11' in d
    assert d['11'] == pytest.approx(1 / 3)
コード例 #3
0
ファイル: test_npdist.py プロジェクト: Autoplectic/dit
def test_setitem2():
    d = Distribution(['00', '11'], [1, 0])
    d.make_sparse()
    d['11'] = 1/2
    d.normalize()
    assert '11' in d
    assert d['11'] == pytest.approx(1/3)
コード例 #4
0
ファイル: test_npdist.py プロジェクト: liangkai/dit
def test_setitem2():
    d = Distribution(['00', '11'], [1, 0])
    d.make_sparse()
    d['11'] = 1 / 2
    d.normalize()
    assert_true('11' in d)
    assert_almost_equal(d['11'], 1 / 3)
コード例 #5
0
ファイル: test_npdist.py プロジェクト: skinnersrat/dit
def test_zipped():
    pmf = [0.125, 0.125, 0.125, 0.125, 0.25, 0, 0.25]
    outcomes = ['000', '011', '101', '110', '222', '321', '333']
    d = Distribution(outcomes, pmf)

    outcomes_, pmf_ = list(zip(*d.zipped()))
    d2 = Distribution(outcomes_, pmf_)
    assert d.is_approx_equal(d2)

    outcomes_, pmf_ = list(zip(*d.zipped(mode='atoms')))
    d3 = Distribution(outcomes_, pmf_)
    assert d.is_approx_equal(d3)

    outcomes_, pmf_ = list(zip(*d.zipped(mode='patoms')))
    d4 = Distribution(outcomes_, pmf_)
    d.make_sparse()
    assert np.allclose(d.pmf, d4.pmf)
コード例 #6
0
ファイル: test_npdist.py プロジェクト: chebee7i/dit
def test_zipped():
    pmf = [.125, .125, .125, .125, .25, 0, .25]
    outcomes = ['000', '011', '101', '110', '222', '321', '333']
    d = Distribution(outcomes, pmf)

    outcomes_, pmf_ = list(zip(*d.zipped()))
    d2 = Distribution(outcomes_, pmf_)
    assert_true(d.is_approx_equal(d2))

    outcomes_, pmf_ = list(zip(*d.zipped(mode='atoms')))
    d3 = Distribution(outcomes_, pmf_)
    assert_true(d.is_approx_equal(d3))

    outcomes_, pmf_ = list(zip(*d.zipped(mode='patoms')))
    d4 = Distribution(outcomes_, pmf_)
    d.make_sparse()
    np.testing.assert_allclose(d.pmf, d4.pmf)
コード例 #7
0
ファイル: test_npdist.py プロジェクト: skinnersrat/dit
def test_has_outcome1():
    d = Distribution(['0', '1'], [1, 0])
    d.make_sparse()
    assert not d.has_outcome('1', null=False)
コード例 #8
0
ファイル: test_npdist.py プロジェクト: chebee7i/dit
def test_has_outcome1():
    d = Distribution(['0', '1'], [1, 0])
    d.make_sparse()
    assert_false(d.has_outcome('1', null=False))