Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 3
0
def save_perception(env, path):
    bits = _get_seen_bits(env, path)
    with open(STORE_FILENAME, "ab") as output:
        output.write(formatting.to_seq(bits))
        output.write("\n")
Ejemplo n.º 4
0
 def __str__(self):
     return ("Impossible history. Try non-deterministic prior. " +
             "History: %s" % formatting.to_seq(self.history))
Ejemplo n.º 5
0
 def __str__(self):
     return "Impossible history. Try non-deterministic prior. " + "History: %s" % formatting.to_seq(self.history)