Get the discrete Fréchet distance between two temporal values
frechetDistance({tnumber, tgeo}, {tnumber, tgeo}): float
This function has a linear space complexity since only two rows of the distance matrix are allocated in memory. Nevertheless, its time complexity is quadratic in the number of instants of the temporal values. Therefore, the function will require considerable time for temporal values with large number of instants.
SELECT frechetDistance(tfloat '[1@2012-01-01, 3@2012-01-03, 1@2012-01-06]', tfloat '[1@2012-01-01, 1.5@2012-01-02, 2.5@2012-01-03, 1.5@2012-01-04, 1.5@2012-01-05]'); -- 0.5 SELECT round(frechetDistance(tgeompoint '[Point(1 1)@2012-01-01, Point(3 3)@2012-01-03, Point(1 1)@2012-01-05]', tgeompoint '[Point(1.1 1.1)@2012-01-01, Point(2.5 2.5)@2012-01-02, Point(4 4)@2012-01-03, Point(3 3)@2012-01-04, Point(1.5 2)@2012-01-05]')::numeric, 6); -- 1.414214
Get the correspondences between two temporal values with respect to the discrete Fréchet distance
frechetDistancePath({tnumber, tgeo}, {tnumber, tgeo}): pairs
This function requires to allocate in memory a distance matrix whose size is quadratic in the number of instants of the temporal values. Therefore, the function will fail for temporal values with large number of instants depending on the available memory.
SELECT frechetDistancePath(tfloat '[1@2012-01-01, 3@2012-01-03, 1@2012-01-06]', tfloat '[1@2012-01-01, 1.5@2012-01-02, 2.5@2012-01-03, 1.5@2012-01-04, 1.5@2012-01-05]'); -- (0,0) (1,0) (2,1) (3,2) (4,2) SELECT frechetDistancePath(tgeompoint '[Point(1 1)@2012-01-01, Point(3 3)@2012-01-03, Point(1 1)@2012-01-05]', tgeompoint '[Point(1.1 1.1)@2012-01-01, Point(2.5 2.5)@2012-01-02, Point(4 4)@2012-01-03, Point(3 3)@2012-01-04, Point(1.5 2)@2012-01-05]'); -- (0,0) (1,1) (2,1) (3,1) (4,2)
Get the Dynamic Time Warp (DTW) distance between two temporal values
dynamicTimeWarp({tnumber, tgeo}, {tnumber, tgeo}): float
This function has a linear space complexity since only two rows of the distance matrix are allocated in memory. Nevertheless, its time complexity is quadratic in the number of instants of the temporal values. Therefore, the function will require considerable time for temporal values with large number of instants.
SELECT dynamicTimeWarp(tfloat '[1@2012-01-01, 3@2012-01-03, 1@2012-01-06]', tfloat '[1@2012-01-01, 1.5@2012-01-02, 2.5@2012-01-03, 1.5@2012-01-04, 1.5@2012-01-05]'); -- 2 SELECT round(dynamicTimeWarp(tgeompoint '[Point(1 1)@2012-01-01, Point(3 3)@2012-01-03, Point(1 1)@2012-01-05]', tgeompoint '[Point(1.1 1.1)@2012-01-01, Point(2.5 2.5)@2012-01-02, Point(4 4)@2012-01-03, Point(3 3)@2012-01-04, Point(1.5 2)@2012-01-05]')::numeric, 6); -- 3.380776
Get the correspondences between two temporal values with respect to the discrete Fréchet distance
dynamicTimeWarpPath({tnumber, tgeo}, {tnumber, tgeo}): pairs
This function requires to allocate a distance matrix which is quadratic in the size of the number of instants of the temporal values. Therefore, memory allocation will fail for temporal values with large number of instants.
SELECT dynamicTimeWarpPath(tfloat '[1@2012-01-01, 3@2012-01-03, 1@2012-01-06]', tfloat '[1@2012-01-01, 1.5@2012-01-02, 2.5@2012-01-03, 1.5@2012-01-04, 1.5@2012-01-05]'); -- (0,0) (1,0) (2,1) (3,2) (4,2) SELECT dynamicTimeWarpPath(tgeompoint '[Point(1 1)@2012-01-01, Point(3 3)@2012-01-03, Point(1 1)@2012-01-05]', tgeompoint '[Point(1.1 1.1)@2012-01-01, Point(2.5 2.5)@2012-01-02, Point(4 4)@2012-01-03, Point(3 3)@2012-01-04, Point(1.5 2)@2012-01-05]'); -- (0,0) (1,1) (2,1) (3,1) (4,2)