Пример #1
0
def test_frame_halving():
    '''
    Many halvings and particle challenges happen here.
    '''
    rng = np.random.RandomState(0)
    salmon = Salmon(buffer_size=10, controller=PIDController(Kp=0.02, Td=0.4),
                    n_samples=5, top_k=7, closeness_bonus=0, rng=rng)
    for _ in range(1000):
        salmon.camera_input(random_im(rng))
        salmon.learn(random_nonwriteable_correction(rng))
Пример #2
0
def test_nonwriteable_correction():
    '''
    This used to fail because PID corrections were applied
    in-place to teacher signal
    '''
    rng = np.random.RandomState(0)
    salmon = Salmon(buffer_size=500, controller=PIDController(Kp=0.02, Td=0.4),
                    n_samples=40, top_k=7, closeness_bonus=0, rng=rng)

    for _ in range(5):
        salmon.camera_input(random_im(rng))
        salmon.learn(random_nonwriteable_correction(rng))
Пример #3
0
def test_smoke():
    # Note that this is not a joke about smoked salmon
    img1 = np.random.randn(40, 40, 3)
    img2 = np.roll(img1, shift = 3, axis = 1)
    # Add noise to the second image
    img2 += np.random.randn(40, 40, 3) * 0.1
    motor_cmd = [np.random.randn(), np.random.randn()]

    salmon = Salmon()
    salmon.camera_input(img1)
    salmon.learn(motor_cmd)
    
    result = salmon.camera_input(img2)

    # No PID controller involved here, so we expect exactly the same motor command out
    # as we provided as a teaching signal
    assert np.array_equal(motor_cmd, result)
    
    # We rolled the test image by 3 pixels compared with the training image,
    # so we are expecting the phase shift in the horizontal direction
    # to be very close to 3.0
    best_frame = salmon._leader.frame
    phase_x = best_frame.phase_x
    print "phase_x", phase_x
    assert 2.9 < phase_x < 3.1
    
    # Now add a PID controller
    Kp = 0.1
    salmon.controller = PIDController(Kp = Kp, Td = 0.0)
    result = salmon.camera_input(img2)
    
    # The first array in the list should be the first motor cmd entry given,
    # with an addition of the correction from the PID controller
    assert motor_cmd[0] + phase_x * Kp == result[0]
    
    # The second array in the list should be untouched
    assert np.array_equal(motor_cmd[1], result[1])