Esempio n. 1
0
def test_dfd():
    """
    Test distribution_from_data.
    """
    data = [0,0,0,1,1,1]
    d1 = Distribution([(0,), (1,)], [1/2, 1/2])
    d2 = Distribution([(0,0), (0,1), (1,1)], [2/5, 1/5, 2/5])
    d1_ = distribution_from_data(data, 1, base='linear')
    d2_ = distribution_from_data(data, 2, base='linear')
    assert d1.is_approx_equal(d1_)
    assert d2.is_approx_equal(d2_)
Esempio n. 2
0
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 not d.is_approx_equal(sd)
Esempio n. 3
0
def test_pr_1():
    """
    Test
    """
    d1 = Distribution(list(product([0, 1], repeat=4)), [1 / 16] * 16)
    d2 = pr_box(0.0)
    assert d1.is_approx_equal(d2)
Esempio n. 4
0
def test_pr_1():
    """
    Test
    """
    d1 = Distribution(list(product([0, 1], repeat=4)), [1/16]*16)
    d2 = pr_box(0.0)
    assert d1.is_approx_equal(d2)
Esempio n. 5
0
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))
Esempio n. 6
0
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))
Esempio n. 7
0
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))
Esempio n. 8
0
def test_pr_2():
    """
    Test
    """
    d1 = Distribution([(0, 0, 0, 0), (0, 0, 1, 1), (0, 1, 0, 0), (0, 1, 1, 1),
                       (1, 0, 0, 0), (1, 0, 1, 1), (1, 1, 0, 1), (1, 1, 1, 0)],
                      [1 / 8] * 8)
    d2 = pr_box(1.0, name=True)
    assert d1.is_approx_equal(d2)
Esempio n. 9
0
def test_pr_2():
    """
    Test
    """
    d1 = Distribution([(0, 0, 0, 0),
                       (0, 0, 1, 1),
                       (0, 1, 0, 0),
                       (0, 1, 1, 1),
                       (1, 0, 0, 0),
                       (1, 0, 1, 1),
                       (1, 1, 0, 1),
                       (1, 1, 1, 0)], [1/8]*8)
    d2 = pr_box(1.0, name=True)
    assert d1.is_approx_equal(d2)