Пример #1
0
def test_modred(rng):
    dt = 0.001
    isys = Lowpass(0.05)
    noise = 0.5 * Lowpass(0.01) + 0.5 * Alpha(0.005)
    p = 0.999
    sys = p * isys + (1 - p) * noise

    T, Tinv, S = balanced_transformation(sys)
    balsys = sys.transform(T, Tinv)

    # Keeping just the best state should remove the 3 noise dimensions
    # Discarding the lowest state should do at least as well
    for keep_states in (S.argmax(),
                        list(set(range(len(sys))) - set((S.argmin(), )))):
        delsys = modred(balsys, keep_states)
        assert delsys.order_den == np.asarray(keep_states).size

        u = rng.normal(size=2000)

        expected = sys.filt(u, dt)
        actual = delsys.filt(u, dt)
        assert rmse(expected, actual) < 1e-4

        step = np.zeros(2000)
        step[50:] = 1.0
        dcsys = modred(balsys, keep_states, method='dc')
        assert np.allclose(dcsys.dcgain, balsys.dcgain)

        # use of shift related to nengo issue #938
        assert not sys.has_passthrough
        assert dcsys.has_passthrough
        expected = shift(sys.filt(step, dt))
        actual = dcsys.filt(step, dt)
        assert rmse(expected, actual) < 1e-4
Пример #2
0
def test_modred(rng):
    dt = 0.001
    isys = Lowpass(0.05)
    noise = 0.5*Lowpass(0.01) + 0.5*Alpha(0.005)
    p = 0.999
    sys = p*isys + (1-p)*noise

    balsys, S = balreal(sys)
    delsys = modred(balsys, S.argmax())
    assert delsys.order_den == 1

    u = rng.normal(size=2000)
    expected = apply_filter(sys, dt, u)
    actual = apply_filter(delsys, dt, u)

    assert rmse(expected, actual) < 1e-4

    step = np.zeros(2000)
    step[50:] = 1.0
    dcsys = modred(balsys, S.argmax(), method='dc')
    expected = apply_filter(sys, dt, step)
    actual = apply_filter(dcsys, dt, step)

    assert rmse(expected, actual) < 1e-4
Пример #3
0
def test_invalid_modred():
    with pytest.raises(ValueError):
        modred(Lowpass(0.1), 0, method='zoh')
Пример #4
0
def test_invalid_modred():
    with pytest.raises(ValueError):
        modred(Lowpass(0.1), 0, method='zoh')