Beispiel #1
0
def test_unit_activate_decode():
    unit = Unit(get_conf(
        UNIT_INPUT_HEIGHT=2,
        UNIT_INPUT_WIDTH=4,
        UNIT_OUTPUT_WIDTH=4
    ))

    messages = [
        (
            from_plain_signal(i % 4, 4),
            from_plain_signal((i + 1) % 4, 4),
        )
        for i in range(100)
    ]

    for message in messages:
        unit.activate(message)

    message = (
        from_plain_signal(0, 4),
        from_plain_signal(1, 4),
    )
    output_signal = unit.activate(message)
    decoded_message = unit.decode(output_signal)

    plain_message = list(map(to_plain_signal, decoded_message))
    assert plain_message == [0, 1]

    assert len(output_signal) == 4
Beispiel #2
0
def test_time_unit_prediction():
    unit = TimeUnit(
        get_conf(UNIT_INPUT_HEIGHT=2,
                 UNIT_INPUT_WIDTH=4,
                 UNIT_OUTPUT_WIDTH=4,
                 TIME_UNIT_BUFFER_SIZE=1))

    # learning
    signals_to_learn = [from_plain_signal(i % 4, 4) for i in range(100)]
    for signal in signals_to_learn:
        unit.activate(signal)

    # set base signals for prediction
    signals = [
        from_plain_signal(0, 4),
    ]
    unit.reset()
    for signal in signals:
        unit.activate(signal)

    # predict
    expected_prediction = from_plain_signal(1, 4)
    prediction = unit.get_prediction()

    assert to_plain_signal(
        prediction[0]) == to_plain_signal(expected_prediction)
Beispiel #3
0
def test_unit_restore():
    unit = Unit(get_conf(
        UNIT_INPUT_HEIGHT=2,
        UNIT_INPUT_WIDTH=4,
        UNIT_OUTPUT_WIDTH=4
    ))

    messages = [
        (
            from_plain_signal(i % 4, 4),
            from_plain_signal((i + 1) % 4, 4),
        )
        for i in range(100)
    ]

    for message in messages:
        unit.activate(message)

    message = (
        from_plain_signal(0, 4),
        None
    )
    expected_message = (
        from_plain_signal(0, 4),
        from_plain_signal(1, 4),
    )

    restored_message = unit.restore(message)
    assert restored_message[0] == expected_message[0], 'first signal should be exactly the same'
    assert to_plain_signal(restored_message[1]) == to_plain_signal(expected_message[1])
Beispiel #4
0
def test_time_unit_prediction():
    unit = TimeUnit(get_conf(UNIT_INPUT_HEIGHT=2, UNIT_INPUT_WIDTH=4, UNIT_OUTPUT_WIDTH=4, TIME_UNIT_BUFFER_SIZE=1))

    # learning
    signals_to_learn = [from_plain_signal(i % 4, 4) for i in range(100)]
    for signal in signals_to_learn:
        unit.activate(signal)

    # set base signals for prediction
    signals = [from_plain_signal(0, 4)]
    unit.reset()
    for signal in signals:
        unit.activate(signal)

    # predict
    expected_prediction = from_plain_signal(1, 4)
    prediction = unit.get_prediction()

    assert to_plain_signal(prediction[0]) == to_plain_signal(expected_prediction)
Beispiel #5
0
def teach_unit(unit):
    with open(FILENAME, 'rb') as f:
        data = pickle.load(f)

    frames = data['audio']['frames']
    for i, byte in enumerate(frames):
        output = unit.activate(from_plain_signal(byte, total_length=256))

        if i % 100 == 0:
            print('%d:\t %s%%' % (i, (i * 100 / len(frames))))

        if i > 10000:
            return
Beispiel #6
0
def teach_unit(unit):
    with open(FILENAME, 'rb') as f:
        data = pickle.load(f)

    frames = data['audio']['frames']
    for i, byte in enumerate(frames):
        output = unit.activate(from_plain_signal(byte, total_length=256))

        if i % 100 == 0:
            print('%d:\t %s%%' % (i, (i * 100 / len(frames))))

        if i > 10000:
            return
Beispiel #7
0
def test_unit_activate_decode():
    unit = Unit(
        get_conf(UNIT_INPUT_HEIGHT=2, UNIT_INPUT_WIDTH=4, UNIT_OUTPUT_WIDTH=4))

    messages = [(
        from_plain_signal(i % 4, 4),
        from_plain_signal((i + 1) % 4, 4),
    ) for i in range(100)]

    for message in messages:
        unit.activate(message)

    message = (
        from_plain_signal(0, 4),
        from_plain_signal(1, 4),
    )
    output_signal = unit.activate(message)
    decoded_message = unit.decode(output_signal)

    plain_message = list(map(to_plain_signal, decoded_message))
    assert plain_message == [0, 1]

    assert len(output_signal) == 4
Beispiel #8
0
def test_unit_restore():
    unit = Unit(
        get_conf(UNIT_INPUT_HEIGHT=2, UNIT_INPUT_WIDTH=4, UNIT_OUTPUT_WIDTH=4))

    messages = [(
        from_plain_signal(i % 4, 4),
        from_plain_signal((i + 1) % 4, 4),
    ) for i in range(100)]

    for message in messages:
        unit.activate(message)

    message = (from_plain_signal(0, 4), None)
    expected_message = (
        from_plain_signal(0, 4),
        from_plain_signal(1, 4),
    )

    restored_message = unit.restore(message)
    assert restored_message[0] == expected_message[
        0], 'first signal should be exactly the same'
    assert to_plain_signal(restored_message[1]) == to_plain_signal(
        expected_message[1])