示例#1
0
    def test_zero_delay_derivative(self):
        m1 = Monomial(0, 1, [], [0], [], [2])

        m = [m1]
        p = Polynomial(m)

        y = [[]]
        u = [[1]]
        params = [2]

        dy, du, dparams = p.derivatives(y, u, params)

        assert_array_almost_equal(du, [[[4]]])
        assert_array_almost_equal(dy, np.reshape([], (1, 0, 1)))
        assert_array_almost_equal(dparams, [[1]])
示例#2
0
    def test_fir_derivative(self):
        m1 = Monomial(0, 1, [], [1], [], [1])
        m2 = Monomial(0, 1, [], [1], [], [2])

        m = [m1, m2]
        p = Polynomial(m)

        y = [[]]
        u = [[1]]
        params = [1, -2]

        dy, du, dparams = p.derivatives(y, u, params)

        assert_array_almost_equal(du, [[[-3]]])
        assert_array_almost_equal(dy, np.reshape([], (1, 0, 1)))
        assert_array_almost_equal(dparams, [[1, 1]])
示例#3
0
    def test_zero_delay_numeric_derivative(self):
        m1 = Monomial(0, 1, [], [0], [], [2])

        m = [m1]
        p = Polynomial(m)

        y = [[]]
        u = [[1]]
        params = [2]

        dy, du, dparams = p.derivatives(y, u, params)
        dy_numeric, du_numeric, \
            dparams_numeric = p._numeric_derivatives(y, u, params)

        assert_array_almost_equal(dy, dy_numeric)
        assert_array_almost_equal(du, du_numeric)
        assert_array_almost_equal(dparams, dparams_numeric)
示例#4
0
    def test_noinput_numeric_derivative(self):
        m1 = Monomial(1, 0, [1], [], [1], [])
        m2 = Monomial(1, 0, [1], [], [2], [])

        m = [m1, m2]
        p = Polynomial(m)

        y = [[1]]
        u = [[]]
        params = [1, -2]

        dy, du, dparams = p.derivatives(y, u, params)
        dy_numeric, du_numeric, \
            dparams_numeric = p._numeric_derivatives(y, u, params)

        assert_array_almost_equal(dy, dy_numeric)
        assert_array_almost_equal(du, du_numeric)
        assert_array_almost_equal(dparams, dparams_numeric)
示例#5
0
    def test_siso_derivatives(TestCase):
        m1 = Monomial(2, 2, [1, 2], [1, 2],
                      [1, 2], [1, 1])
        m2 = Monomial(1, 0, [1], [], [1], [])
        m3 = Monomial(2, 1, [2, 3], [2], [1, 2], [3])

        m = [m1, m2, m3]

        p = Polynomial(m)

        y = [[1], [2], [3]]
        u = [[3], [4]]
        params = [1, 2, 3]

        dy, du, dparams = p.derivatives(y, u, params)

        assert_array_almost_equal(dy, [[[50], [1776], [2304]]])
        assert_array_almost_equal(du, [[[16], [2604]]])
        assert_array_almost_equal(dparams, [[48, 1, 1152]])
示例#6
0
    def test_mimo_polynomial(TestCase):
        m1 = Monomial(2, 2, [1, 2], [1, 2],
                      [1, 2], [1, 1],
                      [0, 1], [0, 1])
        m2 = Monomial(1, 0, [1], [], [1], [], [1])
        m3 = Monomial(2, 1, [2, 3], [2], [1, 2], [3], [0, 0], [1])

        m = [[m1, m2], [m3]]

        p = Polynomial(m)

        y = [[1, 2], [2, 3], [3, 4]]
        u = [[3, 5], [4, 7]]
        params = [1, 2, 3]

        dy, du, dparams = p.derivatives(y, u, params)

        assert_array_almost_equal(dy, [[[189, 2], [0, 126], [0, 0]],
                                       [[0, 0], [9261, 0], [12348, 0]]])
        assert_array_almost_equal(du, [[[63, 0], [0, 27]],
                                       [[0, 0], [0, 7938]]])
        assert_array_almost_equal(dparams, [[189, 2, 0],
                                            [0, 0, 6174]])
示例#7
0
    def test_siso_numeric_derivatives(TestCase):
        m1 = Monomial(2, 2, [1, 2], [1, 2],
                      [1, 2], [1, 1])
        m2 = Monomial(1, 0, [1], [], [1], [])
        m3 = Monomial(2, 1, [2, 3], [2], [1, 2], [3])
        m4 = Monomial(3, 1, [2, 3, 5], [3], [1, 2, 2], [2])
        m5 = Monomial(0, 1, [], [3], [], [2])

        m = [m1, m2, m3, m4, m5]

        p = Polynomial(m)

        y = [[12], [2.23], [4.51], [2.1], [3.24]]
        u = [[3.3], [4.45], [3.4]]
        params = [1.8, 2.2, 3.232, 32.3, 3.34]

        dy, du, dparams = p.derivatives(y, u, params)
        dy_numeric, du_numeric, \
            dparams_numeric = p._numeric_derivatives(y, u, params)

        assert_array_almost_equal(dy, dy_numeric)
        assert_array_almost_equal(du, du_numeric)
        assert_array_almost_equal(dparams, dparams_numeric)
示例#8
0
    def test_mimo_numeric_derivatives(TestCase):
        m1 = Monomial(2, 2, [1, 2], [1, 2],
                      [1, 2], [1, 1], [1, 0])
        m2 = Monomial(1, 0, [1], [], [1], [], [1])
        m3 = Monomial(2, 1, [2, 3], [2], [1, 2], [3], [0, 0], [2])
        m4 = Monomial(3, 1, [2, 3, 5], [3], [1, 2, 2], [2], [0, 1, 0], [0])
        m5 = Monomial(0, 1, [], [3], [], [2], [], [2])

        m = [[m1, m2, m3, m4, m5], [m1, m2]]

        p = Polynomial(m)

        y = [[12, 1.23], [2.23, 23.3], [4.51, 3.4],
             [2.1, 34.54], [3.24, 324.23]]
        u = [[3.3, 132, 1.2], [4.45, 32.32, 2.23], [3.4, 1.3214, 2.132]]
        params = [1.8, 2.2, 3.232, 32.3, 3.34, 3.3425, 13]

        dy, du, dparams = p.derivatives(y, u, params)
        dy_numeric, du_numeric, \
            dparams_numeric = p._numeric_derivatives(y, u, params)

        assert_array_almost_equal(dy, dy_numeric)
        assert_array_almost_equal(du, du_numeric)
        assert_array_almost_equal(dparams, dparams_numeric)