コード例 #1
0
ファイル: test_lyapunov.py プロジェクト: arvoelke/nengolib
def test_l1_norm_known():
    # Check that Lowpass has a norm of exactly 1
    l1, rtol = l1_norm(Lowpass(0.1))
    assert np.allclose(l1, 1)
    assert np.allclose(rtol, 0)

    # Check that passthrough is handled properly
    assert np.allclose(l1_norm(Lowpass(0.1) + 5)[0], 6)

    # Check that Alpha scaled by a has a norm of approximately abs(a)
    for a in (-2, 3):
        for desired_rtol in (1e-1, 1e-2, 1e-4, 1e-8):
            l1, rtol = l1_norm(a*Alpha(0.1), rtol=desired_rtol)
            assert np.allclose(l1, abs(a), rtol=rtol)
            assert rtol <= desired_rtol
コード例 #2
0
def test_l1_norm_known():
    # Check that Lowpass has a norm of exactly 1
    l1, rtol = l1_norm(Lowpass(0.1))
    assert np.allclose(l1, 1)
    assert np.allclose(rtol, 0)

    # Check that passthrough is handled properly
    assert np.allclose(l1_norm(Lowpass(0.1) + 5)[0], 6)
    assert np.allclose(l1_norm(Lowpass(0.1) - 5)[0], 6)

    # Check that Alpha scaled by a has a norm of approximately abs(a)
    for a in (-2, 3):
        for desired_rtol in (1e-1, 1e-2, 1e-4, 1e-8):
            l1, rtol = l1_norm(a * Alpha(0.1), rtol=desired_rtol)
            assert np.allclose(l1, abs(a), rtol=rtol)
            assert rtol <= desired_rtol
コード例 #3
0
 def __call__(self, sys, radii=1):
     """Produces a :class:`.RealizerResult` scaled by the ``radii``."""
     # TODO: this also recomputes many subcalculations in l1_norm
     sys = LinearSystem(sys)
     T = np.diag(
         np.atleast_1d(
             np.squeeze([
                 l1_norm(sub, rtol=self.rtol, max_length=self.max_length)[0]
                 for sub in sys
             ])))
     return _realize(sys, radii, T)
コード例 #4
0
ファイル: test_lyapunov.py プロジェクト: arvoelke/nengolib
def test_l1_norm_unknown(sys):
    # These impulse responses have zero-crossings which makes computing their
    # exact L1-norm infeasible without simulation.
    dt = 0.0001
    length = 500000
    response = impulse(sys, dt=dt, length=length)
    assert np.allclose(response[-10:], 0)
    l1_est = np.sum(abs(response) * dt)

    desired_rtol = 1e-6
    l1, rtol = l1_norm(sys, rtol=desired_rtol, max_length=2*length)
    assert np.allclose(l1, l1_est, rtol=1e-3)
    assert rtol <= desired_rtol
コード例 #5
0
def test_l1_norm_unknown(sys):
    # These impulse responses have zero-crossings which makes computing their
    # exact L1-norm infeasible without simulation.
    dt = 0.0001
    length = 500000
    response = sys.impulse(length, dt)
    assert np.allclose(response[-10:], 0)
    l1_est = np.sum(abs(response) * dt)

    desired_rtol = 1e-6
    l1, rtol = l1_norm(sys, rtol=desired_rtol, max_length=2 * length)
    assert np.allclose(l1, l1_est, rtol=1e-3)
    assert rtol <= desired_rtol
コード例 #6
0
ファイル: normalization.py プロジェクト: arvoelke/nengolib
 def radii(self, sys):
     # TODO: this also recomputes many subcalculations in l1_norm
     return np.squeeze(
         [l1_norm(sub, rtol=self.rtol, max_length=self.max_length)[0] for sub in decompose_states(sys)]
     )
コード例 #7
0
ファイル: test_lyapunov.py プロジェクト: arvoelke/nengolib
def test_l1_norm_bad():
    with pytest.raises(ValueError):
        l1_norm(~z)

    with pytest.raises(ValueError):
        l1_norm(~s)
コード例 #8
0
def test_l1_norm_bad():
    with pytest.raises(ValueError):
        l1_norm(~z)

    with pytest.raises(ValueError):
        l1_norm(~s)