Beispiel #1
0
    def test_compare_sp_with_brute_force(self):
        delay = np.random.uniform(0.0, 2.0)
        end = spline[-1][0]
        start = end - delay

        # Very blunt numerical quadrature
        N = 100000
        factor = (end - start) / N
        bf_sp_sq = 0
        for t in np.linspace(start, end, N):
            anchors = self.spline.get_anchors(t)
            bf_sp_sq += (interpolate(t, 0, anchors) *
                         interpolate(t, 2, anchors) * factor)
            bf_sp_sq += (interpolate(t, 1, anchors) *
                         interpolate(t, 3, anchors) * factor)

        sp = self.spline.scalar_product(delay, [0, 1], [2, 3])

        self.assertAlmostEqual(sp, bf_sp_sq, 4)
Beispiel #2
0
    def test_truncation(self):
        truncation_time = np.random.uniform(spline[-2][0], spline[-1][0])
        truncated_spline = spline.copy()
        truncated_spline.truncate(truncation_time)

        assert truncated_spline[-1][0] == truncation_time

        anchors = (spline[-2], spline[-1])
        anchors_trunc = (truncated_spline[-2], truncated_spline[-1])
        for t in np.linspace(spline[-2][0], truncation_time, 30):
            for j in range(m):
                self.assertAlmostEqual(
                    interpolate(t, j, anchors),
                    interpolate(t, j, anchors_trunc),
                )
                self.assertAlmostEqual(
                    interpolate_diff(t, j, anchors),
                    interpolate_diff(t, j, anchors_trunc),
                )
Beispiel #3
0
 def test_interpolation(self):
     anchors = (spline[0], spline[1])
     for t in np.linspace(spline[0][0], spline[1][0], 100):
         for j in range(m):
             self.assertAlmostEqual(
                 poly[j](t),
                 interpolate(t, j, anchors),
             )
             self.assertAlmostEqual(
                 diff[j](t),
                 interpolate_diff(t, j, anchors),
             )
Beispiel #4
0
 def test_anchors(self):
     for s in range(len(spline) - 1):
         t = spline[s][0]
         anchors = (spline[s], spline[s + 1])
         for j in range(m):
             self.assertAlmostEqual(
                 spline[s][1][j],
                 interpolate(t, j, anchors),
             )
             self.assertAlmostEqual(
                 spline[s][2][j],
                 interpolate_diff(t, j, anchors),
             )
Beispiel #5
0
    def test_compare_norm_with_brute_force(self):
        delay = np.random.uniform(0.0, 2.0)
        end = spline[-1][0]
        start = end - delay

        # Very blunt numerical integration
        N = 100000
        factor = (end - start) / N
        bf_norm_sq = 0
        for t in np.linspace(start, end, N):
            anchors = self.spline.get_anchors(t)
            for j in range(m):
                bf_norm_sq += interpolate(t, j, anchors)**2 * factor

        norm = self.spline.norm(delay, np.array(range(m)))

        self.assertAlmostEqual(norm, np.sqrt(bf_norm_sq), 4)