예제 #1
0
def test_continue_example():
    # A test of the documentation example:
    # ./continue.py -n 10 01101
    model = ctw.create_model()
    model.see_generated(to_bits("01101"))
    p_given = _get_history_p(model)
    model.see_generated(to_bits("1011011011"))
    p_seq = _get_history_p(model)
    eq_float_(p_seq / float(p_given), 0.052825, precision=6)
예제 #2
0
def test_continue_example():
    # A test of the documentation example:
    # ./continue.py -n 10 01101
    model = ctw.create_model()
    model.see_generated(to_bits("01101"))
    p_given = _get_history_p(model)
    model.see_generated(to_bits("1011011011"))
    p_seq = _get_history_p(model)
    eq_float_(p_seq/float(p_given), 0.052825, precision=6)
예제 #3
0
def test_predict_one():
    seq_len = 8
    for determ in [False, True]:
        for seq in iter_all_seqs(seq_len):
            model = ctw.create_model(determ)
            verifier = naive_ctw.create_model(determ)
            for c in seq:
                model.see_generated(to_bits(c))
                verifier.see_generated(to_bits(c))
                eq_float_(model.predict_one(), verifier.predict_one(),
                        precision=10)
예제 #4
0
def test_predict_one():
    seq_len = 8
    for determ in [False, True]:
        for seq in iter_all_seqs(seq_len):
            model = ctw.create_model(determ)
            verifier = naive_ctw.create_model(determ)
            for c in seq:
                model.see_generated(to_bits(c))
                verifier.see_generated(to_bits(c))
                eq_float_(model.predict_one(),
                          verifier.predict_one(),
                          precision=10)
예제 #5
0
def test_max_depth_sum():
    for seq_len in xrange(10):
        total = 0.0
        for seq in iter_all_seqs(seq_len):
            model = ctw.create_model(max_depth=8)
            model.see_generated(to_bits(seq))
            total += _get_history_p(model)

        eq_float_(total, 1.0, precision=15)
예제 #6
0
def test_max_depth_sum():
    for seq_len in xrange(10):
        total = 0.0
        for seq in iter_all_seqs(seq_len):
            model = ctw.create_model(max_depth=8)
            model.see_generated(to_bits(seq))
            total += _get_history_p(model)

        eq_float_(total, 1.0, precision=15)
예제 #7
0
def test_max_depth_example():
    # The calculated probablities are from the
    # 'Reflections on "The Context-Tree Weighting Method: Basic Properties"'
    # paper (figure 6 and 7).
    model = ctw.create_model(max_depth=3)
    model.see_added([1,1,0])
    model.see_generated(to_bits("0100110"))
    p_seq = _get_history_p(model)
    eq_float_(p_seq, 7/2048.0)

    model.see_generated([0])
    p_seq2 = _get_history_p(model)
    eq_float_(p_seq2, 153/65536.0)
예제 #8
0
def test_max_depth_example():
    # The calculated probablities are from the
    # 'Reflections on "The Context-Tree Weighting Method: Basic Properties"'
    # paper (figure 6 and 7).
    model = ctw.create_model(max_depth=3)
    model.see_added([1, 1, 0])
    model.see_generated(to_bits("0100110"))
    p_seq = _get_history_p(model)
    eq_float_(p_seq, 7 / 2048.0)

    model.see_generated([0])
    p_seq2 = _get_history_p(model)
    eq_float_(p_seq2, 153 / 65536.0)
예제 #9
0
def test_see():
    contexted =naive_ctw._Contexted(naive_ctw._estim_kt_p)
    for seq in iter_all_seqs(seq_len=10):
        model = ctw.create_model()
        model.see_generated(to_bits(seq))
        eq_float_(_get_history_p(model), contexted.calc_p("", seq))
예제 #10
0
def test_see():
    contexted = naive_ctw._Contexted(naive_ctw._estim_kt_p)
    for seq in iter_all_seqs(seq_len=10):
        model = ctw.create_model()
        model.see_generated(to_bits(seq))
        eq_float_(_get_history_p(model), contexted.calc_p("", seq))
예제 #11
0
def _create_history(options, input_seq):
    if options.bytes:
        seq = byting.to_binseq(input_seq)
    else:
        seq = input_seq
    return formatting.to_bits(seq)
예제 #12
0
def _assert_context(extractor, history_seq, expected_seq):
    eq_(extractor.extract_context(to_bits(history_seq)),
            to_bits(expected_seq))
예제 #13
0
def _create_history(options, input_seq):
    if options.bytes:
        seq = byting.to_binseq(input_seq)
    else:
        seq = input_seq
    return formatting.to_bits(seq)