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)
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)
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)
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)
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)
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)
def test_has_outcome1(): d = Distribution(['0', '1'], [1, 0]) d.make_sparse() assert not d.has_outcome('1', null=False)
def test_has_outcome1(): d = Distribution(['0', '1'], [1, 0]) d.make_sparse() assert_false(d.has_outcome('1', null=False))