Exemplo n.º 1
0
 def testdiscretefrechet(self):
     L1 = [Point([1, 1]), Point([2, 1]), Point([2, 2])]
     L2 = [Point([2, 2]), Point([0, 1]), Point([2, 4])]
     P = Trajectory(L1)
     Q = Trajectory(L1)
     R = Trajectory(L2)
     self.assertEqual(frechetDist(P, Q), 0.0)
     self.assertEqual(frechetDist(P, R), 2.0)
Exemplo n.º 2
0
 def test_average_distance(self):
     start_time = datetime.strptime('2016-01-13 15:26:0.0', "%Y-%m-%d %H:%M:%S.%f")
     x_array = range(0, 10)
     y_array = range(0, 10)
     t_array = [start_time + timedelta(0,x) for x in range(0, 10)]
     eps_array = [0 for x in range(0, 10)]
     idd = 0
     traj = Trajectory(idd, x_array, y_array, t_array, eps_array)
     self.assertAlmostEqual(traj.average_distance(), math.sqrt(3), delta=0.01)
Exemplo n.º 3
0
 def test_ITWD(self):
     p1 = Point([-7, -4])
     p2 = Point([5, 6])
     p3 = Point([3, 4])
     p4 = Point([-3, 5])
     t1 = Trajectory([p1, p2])
     t2 = Trajectory([p3, p4])
     self.assertEqual(45, dtwD(t1, t2))
     t1 = Trajectory([p1, p2, p3, p4])
     self.assertEqual(0, dtwD(t1, t1))
Exemplo n.º 4
0
 def test_featurizer(self):
     start_time = datetime.strptime('2016-01-13 15:26:0.0', "%Y-%m-%d %H:%M:%S.%f")
     x_array = range(0, 10)
     y_array = range(0, 10)
     t_array = [start_time + timedelta(0,x) for x in range(0, 10)]
     eps_array = [0 for x in range(0, 10)]
     idd = 0
     traj = Trajectory(idd, x_array, y_array, t_array, eps_array)
     features = traj.featurizer()
     optimal_features = [[x, x, x] for x in x_array]
     self.assertEqual(features, optimal_features)
Exemplo n.º 5
0
 def test_featurizer(self):
     start_time = datetime.strptime('2016-01-13 15:26:0.0',
                                    "%Y-%m-%d %H:%M:%S.%f")
     x_array = range(0, 10)
     y_array = range(0, 10)
     t_array = [start_time + timedelta(0, x) for x in range(0, 10)]
     eps_array = [0 for x in range(0, 10)]
     idd = 0
     traj = Trajectory(idd, x_array, y_array, t_array, eps_array)
     features = traj.featurizer()
     optimal_features = [[x, x, x] for x in x_array]
     self.assertEqual(features, optimal_features)
Exemplo n.º 6
0
 def test_average_distance(self):
     start_time = datetime.strptime('2016-01-13 15:26:0.0',
                                    "%Y-%m-%d %H:%M:%S.%f")
     x_array = range(0, 10)
     y_array = range(0, 10)
     t_array = [start_time + timedelta(0, x) for x in range(0, 10)]
     eps_array = [0 for x in range(0, 10)]
     idd = 0
     traj = Trajectory(idd, x_array, y_array, t_array, eps_array)
     self.assertAlmostEqual(traj.average_distance(),
                            math.sqrt(3),
                            delta=0.01)
Exemplo n.º 7
0
 def testcontinuousLp1(self):
     t1 = Trajectory([
         Point([10, 3], 0),
         Point([9, 3], 1),
         Point([1, 3], 3),
         Point([0, 3], 4)
     ])
     t2 = Trajectory([
         Point([10, 5], 1),
         Point([4, 5], 2),
         Point([2, 5], 5),
         Point([0, 5], 6)
     ])
     self.assertEqual(contL_p(t1, t2, 1), 19.5)
Exemplo n.º 8
0
 def testcontinuousLp3(self):
     t5 = Trajectory([
         Point([0, 1]),
         Point([1, 1]),
         Point([2, 1]),
         Point([3, 1]),
         Point([4, 1])
     ])
     t6 = Trajectory(
         [Point([0, 2]),
          Point([2, 2]),
          Point([4, 2]),
          Point([5, 2])])
     self.assertEqual(contL_p(t5, t6, 1), 11.0 / 6.0)
Exemplo n.º 9
0
 def testcontinuousLp4(self):
     t5 = Trajectory([
         Point([0, 1], 0),
         Point([1, 1], 1),
         Point([2, 1], 2),
         Point([3, 1], 3),
         Point([4, 1], 4)
     ])
     t6 = Trajectory([
         Point([0, 2], 0),
         Point([2, 2], 2),
         Point([4, 2], 4),
         Point([5, 2], 5)
     ])
     self.assertEqual(contL_p(t5, t6, 1), 5.5)
Exemplo n.º 10
0
 def test_t_trajectory(self):
     start_time = datetime.strptime('2016-01-13 15:26:0.0',
                                    "%Y-%m-%d %H:%M:%S.%f")
     x_array = range(0, 10)
     y_array = range(0, 10)
     t_array = [start_time + timedelta(0, x) for x in range(0, 10)]
     eps_array = [0 for x in range(0, 10)]
     idd = 0
     traj = Trajectory(idd, x_array, y_array, t_array, eps_array)
     self.assertEqual(x_array, traj.t_traj)
Exemplo n.º 11
0
 def test_1D_DTW(self):
     t1 = [1, 2, 2, 10, 2, 1]
     t2 = [3, 3, 5, 5, 2]
     self.assertEqual(45, dtw(t1, t2, -1, metricI))
     self.assertEqual(0, dtw(t1, t1, -1, metricI))
     t1 = Trajectory([
         Point([1]),
         Point([2]),
         Point([2]),
         Point([10]),
         Point([2]),
         Point([1])
     ])
     t2 = Trajectory(
         [Point([3]),
          Point([3]),
          Point([5]),
          Point([5]),
          Point([2])])
     self.assertEqual(45, dtw(t1, t2, -1, metricD))
     self.assertEqual(0, dtw(t1, t1, -1, metricD))
Exemplo n.º 12
0
def doubleTrajResample(t1, t2):
    if len(t1) > 0 and len(t2) > 0 and t1.dim() == t2.dim():
        n1 = Trajectory(t1.pts)
        n2 = Trajectory(t2.pts)
        # Ensuring start elements are the same
        if n1[0].t > n2[0].t:
            if sub1(n1, n2) is None:
                raise ValueError("Trajectories Do Not Overlap")
        elif n1[0].t < n2[0].t:
            if sub1(n2, n1) is None:
                raise ValueError("Trajectories Do Not Overlap")

        # Ensuring end times are the same
        if n1[len(n1) - 1].t < n2[len(n2) - 1].t:
            sub2(n1, n2)
        elif n1[len(n1) - 1].t > n2[len(n2) - 1].t:
            sub2(n2, n1)

        # Now cycle over next elements
        l1 = len(n1)
        l2 = len(n2)
        i = j = 1
        while i < l1 - 1 and j < l2 - 1:
            if n1[i].t < n2[j].t:
                n2.pts.insert(
                    j, interpolateBetweenPoints(n2[j - 1], n2[j], n1[i].t))
                l2 += 1
            elif n2[j].t < n1[i].t:
                n1.pts.insert(
                    i, interpolateBetweenPoints(n1[i - 1], n1[i], n2[j].t))
                l1 += 1
            i += 1
            j += 1
        return n1, n2
    else:
        raise TypeError("Trajectories Not Valid")
Exemplo n.º 13
0
    def __init__(self, number_samples, number_samples_in_pause, x_spacing,
                 t_spacing):
        t_traj = time_spacing(number_samples, t_spacing)
        y_traj = [1 for i in range(0, number_samples)]
        eps_traj = [0 for i in range(0, number_samples)]
        pause_position = number_samples - number_samples_in_pause
        if pause_position % 2 == 0:
            pause_position /= 2
            end_position = 2 * pause_position + 1
        else:
            pause_position = (pause_position - 1) / 2
            end_position = 2 * pause_position + 2

        before = [x * x_spacing for x in range(0, pause_position)]
        pause = [
            pause_position * x_spacing
            for x in range(0, number_samples_in_pause - 1)
        ]
        after = [x * x_spacing for x in range(pause_position, end_position)]
        x_traj = before + pause + after
        self.trajectory = Trajectory(2, x_traj, y_traj, t_traj, eps_traj)
Exemplo n.º 14
0
def snipTrajectory(t1, t2):
    maxLen = max(len(t1), len(t1))
    return [
        Trajectory([t1[i] for i in range(maxLen)]),
        Trajectory([t2[i] for i in range(maxLen)])
    ]
Exemplo n.º 15
0
 def testcontinuousLp2(self):
     t3 = Trajectory([Point([0, 3], 0), Point([1, 3], 1), Point([4, 3], 4)])
     t4 = Trajectory([Point([0, 1], 0), Point([2, 1], 2), Point([4, 1], 4)])
     self.assertEqual(contL_p(t3, t4, 1), 8.0)
Exemplo n.º 16
0
 def __init__(self, n, x_spacing, t_spacing):
     x_traj = [i * x_spacing for i in range(0, n)]
     y_traj = [1 for i in range(0, n)]
     eps_traj = [0 for i in range(0, n)]
     t_traj = time_spacing(n, t_spacing)
     self.trajectory = Trajectory(1, x_traj, y_traj, t_traj, eps_traj)
Exemplo n.º 17
0
 def testL_one_simple(self):
     a = Trajectory([Point((1, 2))])
     b = Trajectory([Point((5, 5))])