Esempio n. 1
0
def test_combine_symbols():
    '''
    test infomration.combine_symbols, takes a bunch of 1D
    symbols and generates another 1D symbol
    '''
    x = [1,1,2,2]
    y = [1,2,1,2]
    z = ((1,1),(1,2),(2,1),(2,2))
    assert_equal(z, info.combine_symbols(x,y))

    # Combine categorical symbols
    x = ('r', 'r', 'g', 'g', 'b', 'b')
    y = ('r', 1, 'r', 1, 'r', 1)
    z = (('r', 'r'), ('r', 1), ('g', 'r'), ('g', 1), ('b', 'r'), ('b', 1))
    assert_equal(z, info.combine_symbols(x,y))

    # Combine 4 sequences at once
    x0 = (1, 1, 1, 1)
    x1 = (1, 1, 2, 2)
    x2 = (1, 2, 2, 1)
    x3 = (2, 2, 1, 1)
    z  = ((1,1,1,2), (1,1,2,2), (1,2,2,1), (1,2,1,1))
    assert_equal(z, info.combine_symbols(x0, x1, x2, x3))

    # raise an exception when trying to combine iterables with different lengths
    x = (1,2,3,4)
    y = (1,2,3)
    assert_raises(ValueError, info.combine_symbols, x, y)
Esempio n. 2
0
def test_combine_symbols():
    '''
    test infomration.combine_symbols, takes a bunch of 1D
    symbols and generates another 1D symbol
    '''
    x = [1, 1, 2, 2]
    y = [1, 2, 1, 2]
    z = ((1, 1), (1, 2), (2, 1), (2, 2))
    assert_equal(z, discrete.combine_symbols(x, y))

    # Combine categorical symbols
    x = ('r', 'r', 'g', 'g', 'b', 'b')
    y = ('r', 1, 'r', 1, 'r', 1)
    z = (('r', 'r'), ('r', 1), ('g', 'r'), ('g', 1), ('b', 'r'), ('b', 1))
    assert_equal(z, discrete.combine_symbols(x, y))

    # Combine 4 sequences at once
    x0 = (1, 1, 1, 1)
    x1 = (1, 1, 2, 2)
    x2 = (1, 2, 2, 1)
    x3 = (2, 2, 1, 1)
    z = ((1, 1, 1, 2), (1, 1, 2, 2), (1, 2, 2, 1), (1, 2, 1, 1))
    assert_equal(z, discrete.combine_symbols(x0, x1, x2, x3))

    # raise an exception when trying to combine iterables with different lengths
    x = (1, 2, 3, 4)
    y = (1, 2, 3)
    assert_raises(ValueError, discrete.combine_symbols, x, y)
Esempio n. 3
0
def test_symbols_to_prob():
    #pdb.set_trace()
    # a trivial example
    x=[1]*5 + [2]*5
    prob0=array((.5, .5))           # this is what the probabilities should be
    prob1=info.symbols_to_prob(x).prob()
    assert_true((prob0==prob1).all())

    # an example combining different symbols
    x = [1,1,1,1]
    y = ['r', 'r', 'b', 'b']
    z = [1,'r',1,'r']
    s0 = info.combine_symbols(x,y)       # instead of running info.combine_symbols(x,y,z) I 
    s1 = info.combine_symbols(s0, z)     # split combination of symbols in two lines and test
                                        # chain rule for combining symbols as well
    prob0 = array([.25]*4)
    prob1 = info.symbols_to_prob(s1).prob()
    assert_true((prob0==prob1).all())
Esempio n. 4
0
def test_symbols_to_prob():
    #pdb.set_trace()
    # a trivial example
    x = [1] * 5 + [2] * 5
    prob0 = array((.5, .5))  # this is what the probabilities should be
    prob1 = discrete.symbols_to_prob(x).prob()
    assert_true((prob0 == prob1).all())

    # an example combining different symbols
    x = [1, 1, 1, 1]
    y = ['r', 'r', 'b', 'b']
    z = [1, 'r', 1, 'r']
    s0 = discrete.combine_symbols(
        x, y)  # instead of running discrete.combine_symbols(x,y,z) I
    s1 = discrete.combine_symbols(
        s0, z)  # split combination of symbols in two lines and test
    # chain rule for combining symbols as well
    prob0 = array([.25] * 4)
    prob1 = discrete.symbols_to_prob(s1).prob()
    assert_true((prob0 == prob1).all())