Beispiel #1
0
def main():
    options, input_seq = _parse_args()
    history = _create_history(options, input_seq)
    model = _create_model(options, history)

    if options.bytes:
        num_predicted_bits = _round_up(options.num_predicted_bits, 8)
    else:
        num_predicted_bits = options.num_predicted_bits

    probs = []
    bits = ""
    probability = 1.0
    sys.stdout.write("%s -> " % formatting.to_seq(history))
    for i in xrange(num_predicted_bits):
        bit, bit_p = modeling.advance(model)
        probs.append(bit_p)
        probability *= bit_p
        sys.stdout.write(str(bit))
        sys.stdout.flush()
        bits += str(bit)

    print
    if options.bytes:
        print "%s -> %s" % (input_seq, byting.to_bytes(bits))

    if len(probs) > 10:
        probs_info = _format_products(probs[:9]) + " * ..."
    else:
        probs_info = _format_products(probs)
    print "with P = %f = %s" % (probability, probs_info)
Beispiel #2
0
def main():
    options, input_seq = _parse_args()
    history = _create_history(options, input_seq)
    model = _create_model(options, history)

    if options.bytes:
        num_predicted_bits = _round_up(options.num_predicted_bits, 8)
    else:
        num_predicted_bits = options.num_predicted_bits

    probs = []
    bits = ""
    probability = 1.0
    sys.stdout.write("%s -> " % formatting.to_seq(history))
    for i in xrange(num_predicted_bits):
        bit, bit_p = modeling.advance(model)
        probs.append(bit_p)
        probability *= bit_p
        sys.stdout.write(str(bit))
        sys.stdout.flush()
        bits += str(bit)

    print
    if options.bytes:
        print "%s -> %s" % (input_seq, byting.to_bytes(bits))

    if len(probs) > 10:
        probs_info = _format_products(probs[:9]) + " * ..."
    else:
        probs_info = _format_products(probs)
    print "with P = %f = %s" % (probability, probs_info)
Beispiel #3
0
def test_conversion():
    eq_(byting.to_bytes(byting.to_binseq("hello world")), "hello world")
Beispiel #4
0
def test_to_bytes():
    eq_(byting.to_bytes("01000001"), "A")
    eq_(byting.to_bytes("0100000101000011"), "AC")