Esempio n. 1
0
    def test_input_continuous(self):

        t = np.array( [ 0, 1, 2, 3])
        y = np.array([[ 0, 0, 3, 3],
                      [-1, 0, 1, 2]])

        # extrapolate left (hold)
        v1, v2 = Input.interpolate(-1, t, y)
        self.assertEqual(v1,  0)
        self.assertEqual(v2, -1)

        # hit sample
        v1, v2 = Input.interpolate(1, t, y)
        self.assertEqual(v1, 0)
        self.assertEqual(v2, 0)

        # interpolate (linear)
        v1, v2 = Input.interpolate(1.5, t, y)
        self.assertAlmostEqual(v1, 1.5)
        self.assertAlmostEqual(v2, 0.5)

        # extrapolate right (hold)
        v1, v2 = Input.interpolate(4, t, y)
        self.assertEqual(v1, 3)
        self.assertEqual(v2, 2)
Esempio n. 2
0
    def test_single_sample(self):
        t = np.array([0])
        y = np.array([2])

        # "interpolate" input with only one sample
        v = Input.interpolate(1, t, y)

        self.assertEqual(v,  2)
Esempio n. 3
0
    def test_input_discrete(self):

        t = np.array([0, 1, 1, 2])
        y = np.array([[0, 0, 3, 3]])

        # extrapolate left
        v = Input.interpolate(-1, t, y)
        self.assertEqual(v, 0)

        # hit sample
        v = Input.interpolate(0, t, y)
        self.assertEqual(v, 0)

        # interpolate
        v = Input.interpolate(0.5, t, y)
        self.assertEqual(v, 0)

        # before event
        v = Input.interpolate(1, t, y)
        self.assertEqual(v, 0)

        # after event
        v = Input.interpolate(1, t, y, after_event=True)
        self.assertEqual(v, 3)

        # extrapolate right
        v = Input.interpolate(0, t, y)
        self.assertEqual(v, 0)
Esempio n. 4
0
    def test_input_discrete(self):

        t = np.array([0, 1, 1, 1, 2])
        y = np.array([[0, 0, 4, 3, 3]])

        # extrapolate left
        v = Input.interpolate(-1, t, y)
        self.assertEqual(v, 0, "Expecting first value")

        # hit sample
        v = Input.interpolate(0, t, y)
        self.assertEqual(v, 0, "Expecting value at sample")

        # interpolate
        v = Input.interpolate(0.5, t, y)
        self.assertEqual(v, 0, "Expecting to hold previous value")

        # before event
        v = Input.interpolate(1, t, y)
        self.assertEqual(v, 0, "Expecting value before event")

        # after event
        v = Input.interpolate(1, t, y, after_event=True)
        self.assertEqual(v, 3, "Expecting value after event")

        # extrapolate right
        v = Input.interpolate(3, t, y)
        self.assertEqual(v, 3, "Expecting last value")
Esempio n. 5
0
    def test_input_continuous(self):

        t = np.array([0, 1, 2, 3])
        y = np.array([[0, 0, 3, 3], [-1, 0, 1, 2]])

        # extrapolate left (hold)
        (u1, u2), (du1, du2) = Input.interpolate(-1, t, y)
        self.assertTrue((u1, u2) == (0, -1))
        self.assertTrue((du1, du2) == (0, 0))

        # hit sample
        (u1, u2), (du1, du2) = Input.interpolate(1, t, y)
        self.assertTrue((u1, u2) == (0, 0))
        self.assertTrue((du1, du2) == (0, 1))

        # interpolate (linear)
        (u1, u2), (du1, du2) = Input.interpolate(1.5, t, y)
        self.assertTrue((u1, u2) == (1.5, 0.5))
        self.assertTrue((du1, du2) == (3, 1))

        # extrapolate right (hold)
        (u1, u2), (du1, du2) = Input.interpolate(4, t, y)
        self.assertTrue((u1, u2) == (3, 2))
        self.assertTrue((du1, du2) == (0, 0))