Title: | Trajectory Similarity Measures |
---|---|
Description: | Functions to run and assist four different similarity measures. The similarity measures included are: longest common subsequence (LCSS), Frechet distance, edit distance and dynamic time warping (DTW). Each of these similarity measures can be calculated from two n-dimensional trajectories, both in matrix form. |
Authors: | Kevin Toohey |
Maintainer: | Kevin Toohey <[email protected]> |
License: | GPL-3 |
Version: | 1.4 |
Built: | 2025-02-26 04:44:45 UTC |
Source: | https://github.com/cran/SimilarityMeasures |
This package contains functions to run and assist four different similarity measures. The similarity measures included are: longest common subsequence (LCSS), Frechet distance, edit distance and dynamic time warping (DTW). Each of these similarity measures can be calculated from two n-dimensional trajectories, both in matrix form.
Package: | SimilarityMeasures |
Type: | Package |
Version: | 1.4 |
Date: | 2014-02-06 |
License: | GPL-3 |
Kevin Toohey
Maintainer: Kevin Toohey <[email protected]>
Alt, H. and Godau, M. (1995) Computing the Frechet distance between two polygonal curves. International Journal of Computational Geometry & Applications, 5(01n02), 75–91.
Berndt, D. and Clifford, J. (1994) Using Dynamic Time Warping to Find Patterns in Time Series. Paper presented at the KDD workshop.
Chen, L., Ozsu, M. T. and Oria, V. (2005) Robust and fast similarity search for moving object trajectories. Paper presented at the Proceedings of the 2005 ACM SIGMOD international conference on Management of data, Baltimore, Maryland.
Vlachos, M., Kollios, G. and Gunopulos, D. (2002) Discovering similar multidimensional trajectories. Paper presented at the Data Engineering, 2002. Proceedings. 18th International Conference on.
A function to calculate a translation vector for trajectory2 using the average of the two trajectories. The vector created can be used to translate the average of trajectory2's points to that of trajectory1.
AveTranslate(traj1, traj2)
AveTranslate(traj1, traj2)
traj1 |
An m x n matrix containing trajectory1. Here m is the number of points and n is the dimension of the points. |
traj2 |
A k x n matrix containing trajectory2. Here k is the number of points and n is the dimension of the points. The two trajectories are not required to have the same number of points. |
The average of each dimension of both trajectories is calculated. The required translation is then calculated from the difference between them.
A vector of length n is returned containing the translation in each dimension. If there is a problem this returns a string of information instead.
Kevin Toohey
LCSSTranslation
, StartEndTranslate
# Creating two trajectories. path1 <- matrix(c(0, 1, 2, 3, 0, 1, 2, 3), 4) path2 <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7), 4) # Running the translation. AveTranslate(path1, path2)
# Creating two trajectories. path1 <- matrix(c(0, 1, 2, 3, 0, 1, 2, 3), 4) path2 <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7), 4) # Running the translation. AveTranslate(path1, path2)
A function to check whether two points lie within some distance in every dimension.
DistanceCheck(point1, point2, dist, dimensions=length(point1))
DistanceCheck(point1, point2, dist, dimensions=length(point1))
point1 |
An n dimensional vector representing point1. |
point2 |
An n dimensional vector representing point2. |
dist |
A floating point number representing the maximum distance in each dimension allowed for points to be considered equivalent. |
dimensions |
An integer representing the number of dimensions being checked. This defaults to the length of the first vector. |
A boolean value is returned. The value is true if the points are within the distance in every dimension and false if not.
Kevin Toohey
# Creating two points. point1 <- c(0, 2, 4, 6) point2 <- c(0, 1, 2, 3) # Running the check with distances 1 and 3 in 4 dimensions. DistanceCheck(point1, point2, 1, 4) DistanceCheck(point1, point2, 3, 4)
# Creating two points. point1 <- c(0, 2, 4, 6) point2 <- c(0, 1, 2, 3) # Running the check with distances 1 and 3 in 4 dimensions. DistanceCheck(point1, point2, 1, 4) DistanceCheck(point1, point2, 3, 4)
A function to calculate the square of the distance between two points.
DistanceSq(point1, point2, dimensions=length(point1))
DistanceSq(point1, point2, dimensions=length(point1))
point1 |
An n dimensional vector representing point1. |
point2 |
An n dimensional vector representing point2. |
dimensions |
An integer representing the number of dimensions being used for the distance square calculation. This defaults to the length of the first vector. |
A floating point value is returned, representing the square of the distance between the two points.
Kevin Toohey
# Creating two points. point1 <- c(0, 2, 4, 6) point2 <- c(0, 1, 2, 3) # Calculating the square distance between the two points # in 4 dimensions. DistanceSq(point1, point2, 4)
# Creating two points. point1 <- c(0, 2, 4, 6) point2 <- c(0, 1, 2, 3) # Calculating the square distance between the two points # in 4 dimensions. DistanceSq(point1, point2, 4)
A function to calculate the dot product between two vectors. This is used in the Frechet algorithm and does not need to be called directly.
Dot(vect1, vect2, dimensions=length(vect1))
Dot(vect1, vect2, dimensions=length(vect1))
vect1 |
An n dimensional vector representing the first vector. |
vect2 |
An n dimensional vector representing the second vector. |
dimensions |
An integer representing the number of dimensions being used for the dot product calculation. This defaults to the length of the first vector. |
This function is called by the Frechet
function.
A floating point value is returned, representing the dot product between the two vectors.
Kevin Toohey
A function to calculate the dynamic time warping value between two trajectories.
DTW(traj1, traj2, pointSpacing=-1)
DTW(traj1, traj2, pointSpacing=-1)
traj1 |
An m x n matrix containing trajectory1. Here m is the number of points and n is the dimension of the points. |
traj2 |
A k x n matrix containing trajectory2. Here k is the number of points and n is the dimension of the points. The two trajectories are not required to have the same number of points. |
pointSpacing |
An integer value of the maximum index difference between trajectory1 and trajectory2 allowed in the calculation. A negative value sets the point spacing to unlimited. |
The dynamic time warping algorithm (DTW) calculates the smallest warp path for the two trajectories. This is the DTW version discussed by Berndt & Clifford (1994). Several variations of calculating the warping cost exist. In this version, the warping path is equal to the sum of the distances at each point along the path. Please see the references for more information.
A floating point value representing the smallest warp path is returned. If a problem occurs, then a string containing information about the problem is returned.
Kevin Toohey
Berndt, D. and Clifford, J. (1994) Using Dynamic Time Warping to Find Patterns in Time Series. Paper presented at the KDD workshop.
# Creating two trajectories. path1 <- matrix(c(0, 1, 2, 3, 0, 1, 2, 3), 4) path2 <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7), 4) # Running the dynamic time warping algorithm with point spacing # set to 4. DTW(path1, path2, 4)
# Creating two trajectories. path1 <- matrix(c(0, 1, 2, 3, 0, 1, 2, 3), 4) path2 <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7), 4) # Running the dynamic time warping algorithm with point spacing # set to 4. DTW(path1, path2, 4)
A function to calculate the edit distance between two trajectories.
EditDist(traj1, traj2, pointDistance=20)
EditDist(traj1, traj2, pointDistance=20)
traj1 |
An m x n matrix containing trajectory1. Here m is the number of points and n is the dimension of the points. |
traj2 |
A k x n matrix containing trajectory2. Here k is the number of points and n is the dimension of the points. The two trajectories are not required to have the same number of points. |
pointDistance |
A floating point number representing the maximum distance in each dimension allowed for points to be considered equivalent. |
The edit distance algorithm calculates the minimum number of edits required to allow the two trajectories to be considered equivalent. This function uses Edit Distance on Real sequence (EDR) as described by Chen et al. (2005). Please see the references for more information.
An integer representing the minimum number of edits required is returned. If a problem occurs, then a string containing information about the problem is returned.
Kevin Toohey
Chen, L., Ozsu, M. T. and Oria, V. (2005) Robust and fast similarity search for moving object trajectories. Paper presented at the Proceedings of the 2005 ACM SIGMOD international conference on Management of data, Baltimore, Maryland.
# Creating two trajectories. path1 <- matrix(c(0, 1, 2, 3, 0, 1, 2, 3), 4) path2 <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7), 4) # Running the edit distance algorithm with point distance # set to 2. EditDist(path1, path2, 2)
# Creating two trajectories. path1 <- matrix(c(0, 1, 2, 3, 0, 1, 2, 3), 4) path2 <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7), 4) # Running the edit distance algorithm with point distance # set to 2. EditDist(path1, path2, 2)
A function to calculate the Frechet distance between two trajectories. The function can also be used to test leash values.
Frechet(traj1, traj2, testLeash=-1)
Frechet(traj1, traj2, testLeash=-1)
traj1 |
An m x n matrix containing trajectory1. Here m is the number of points and n is the dimension of the points. |
traj2 |
A k x n matrix containing trajectory2. Here k is the number of points and n is the dimension of the points. The two trajectories are not required to have the same number of points. |
testLeash |
A numeric leash value, which if positive, checks whether the leash can be used between the two trajectories. If this value is negative, then it is not used and the standard calculation is performed. |
This algorithm calculates the Frechet distance. The Frechet metric (or distance) is generally described in the following way: A man is walking a dog on a leash, the man walks on one curve while the dog walks on the other (Alt & Godau, 1995). The dog and the man are able to vary their speeds, or even stop, but not go backwards. The Frechet metric is the minimum leash length required to complete the traversal of both curves. Please see the references for more information.
A floating point value representing the Frechet distance is returned. If a test leash is given, then a boolean value is returned as true if the leash was successful and false if not. If a problem occurs, then a string containing information about the problem is returned.
Kevin Toohey
Alt, H. and Godau, M. (1995) Computing the Frechet distance between two polygonal curves. International Journal of Computational Geometry & Applications, 5(01n02), 75–91.
# Creating two trajectories. path1 <- matrix(c(0, 1, 2, 3, 0, 1, 2, 3), 4) path2 <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7), 4) # Running the Frechet distance algorithm. Frechet(path1, path2)
# Creating two trajectories. path1 <- matrix(c(0, 1, 2, 3, 0, 1, 2, 3), 4) path2 <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7), 4) # Running the Frechet distance algorithm. Frechet(path1, path2)
A function to check whether a Frechet leash distance is successful or not. This is used by the Frechet calculation and does not need to be called directly.
FrechetCheck(traj1, traj2, leash, dist1, dist2, distSq12)
FrechetCheck(traj1, traj2, leash, dist1, dist2, distSq12)
traj1 |
An m x n matrix containing trajectory1. Here m is the number of points and n is the dimension of the points. |
traj2 |
A k x n matrix containing trajectory2. Here k is the number of points and n is the dimension of the points. The two trajectories are not required to have the same number of points. |
leash |
A numeric leash value to be checked by the function. |
dist1 |
A vector containing the distance between each successive two points in trajectory1. |
dist2 |
A vector containing the distance between each successive two points in trajectory2. |
distSq12 |
A matrix containing the distance between each pair of two points where 1 point lies in trajectory1 and the other in trajectory2. |
This function is required by Frechet
and in general does not need to be called directly.
A boolean value is returned. A value of true is returned if the leash is successful and false if not.
Kevin Toohey
Alt, H. and Godau, M. (1995) Computing the Frechet distance between two polygonal curves. International Journal of Computational Geometry & Applications, 5(01n02), 75–91.
# Creating two trajectories. path1 <- matrix(c(0, 1, 2, 3, 0, 1, 2, 3), 4) path2 <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7), 4) # Running the Frechet distance algorithm with a test leash of 2. Frechet(path1, path2, 2)
# Creating two trajectories. path1 <- matrix(c(0, 1, 2, 3, 0, 1, 2, 3), 4) path2 <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7), 4) # Running the Frechet distance algorithm with a test leash of 2. Frechet(path1, path2, 2)
A function to calculate the longest common subsequence between two trajectories. This calculation automatically uses translations to find the largest value.
LCSS(traj1, traj2, pointSpacing=-1, pointDistance=20, errorMarg=2, returnTrans=FALSE)
LCSS(traj1, traj2, pointSpacing=-1, pointDistance=20, errorMarg=2, returnTrans=FALSE)
traj1 |
An m x n matrix containing trajectory1. Here m is the number of points and n is the dimension of the points. |
traj2 |
A k x n matrix containing trajectory2. Here k is the number of points and n is the dimension of the points. The two trajectories are not required to have the same number of points. |
pointSpacing |
An integer value of the maximum index difference between trajectory1 and trajectory2 allowed in the calculation. A negative value sets the point spacing to unlimited. |
pointDistance |
A floating point number representing the maximum distance in each dimension allowed for points to be considered equivalent. |
errorMarg |
A floating point error margin used to scale the accuracy and speed of the calculation. |
returnTrans |
A boolean value to allow the best translation found to be returned as well as the LCSS value if set to true. |
The LCSS algorithm calculates the largest number of equivalent points between the two trajectories when traversed in a monotone way. Possible translations are calculated in each dimension and used to provide the maximum LCSS. The accuracy of the algorithm can be varied to provide faster or slower calculations. Please see the references for more information.
An integer value is returned. This represents the maximum LCSS value obtained using the variables provided. If returnTrans is set to TRUE, then the LCSS value and the translations are returned as a vector. The first value of this vector is the LCSS value and the translations follow directly afterwards. If a problem occurs, then a string containing information about the problem is returned.
Kevin Toohey
Vlachos, M., Kollios, G. and Gunopulos, D. (2002) Discovering similar multidimensional trajectories. Paper presented at the Data Engineering, 2002. Proceedings. 18th International Conference on.
LCSSCalc
, LCSSRatio
, LCSSRatioCalc
, LCSSTranslation
# Creating two trajectories. path1 <- matrix(c(0, 1, 2, 3, 0, 1, 2, 3), 4) path2 <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7), 4) # Running the LCSS algorithm on the trajectories. LCSS(path1, path2, 2, 2, 0.5) # Running the LCSS algorithm on the trajectories # and returning the translation as well. LCSS(path1, path2, 2, 2, 0.5, TRUE)
# Creating two trajectories. path1 <- matrix(c(0, 1, 2, 3, 0, 1, 2, 3), 4) path2 <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7), 4) # Running the LCSS algorithm on the trajectories. LCSS(path1, path2, 2, 2, 0.5) # Running the LCSS algorithm on the trajectories # and returning the translation as well. LCSS(path1, path2, 2, 2, 0.5, TRUE)
A function to calculate the longest common subsequence between two trajectories. This function does not calculate translations and only uses the given trajectories and optional translation.
LCSSCalc(traj1, traj2, pointSpacing=-1, pointDistance=20, trans=rep(0, (dim(traj1)[2])))
LCSSCalc(traj1, traj2, pointSpacing=-1, pointDistance=20, trans=rep(0, (dim(traj1)[2])))
traj1 |
An m x n matrix containing trajectory1. Here m is the number of points and n is the dimension of the points. |
traj2 |
A k x n matrix containing trajectory2. Here k is the number of points and n is the dimension of the points. The two trajectories are not required to have the same number of points. |
pointSpacing |
An integer value of the maximum index difference between trajectory1 and trajectory2 allowed in the calculation. A negative value sets the point spacing to unlimited. |
pointDistance |
A floating point number representing the maximum distance in each dimension allowed for points to be considered equivalent. |
trans |
A vector containing translations in each dimension to be applied to trajectory2 in this calculation. |
The LCSS algorithm calculates the largest number of equivalent points between the two trajectories when traversed in a monotone way. If a translation is given then this is applied before the calculation is done. This function is used by all of the the LCSS functions. Please see the references for more information.
An integer value is returned. This represents the maximum LCSS value obtained using the variables provided. If a problem occurs, then a string containing information about the problem is returned.
Kevin Toohey
Vlachos, M., Kollios, G. and Gunopulos, D. (2002) Discovering similar multidimensional trajectories. Paper presented at the Data Engineering, 2002. Proceedings. 18th International Conference on.
LCSS
, LCSSRatio
, LCSSRatioCalc
, LCSSTranslation
# Creating two trajectories. path1 <- matrix(c(0, 1, 2, 3, 0, 1, 2, 3), 4) path2 <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7), 4) # Running the LCSS algorithm on the trajectories. LCSSCalc(path1, path2, 2, 2, c(0, 3))
# Creating two trajectories. path1 <- matrix(c(0, 1, 2, 3, 0, 1, 2, 3), 4) path2 <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7), 4) # Running the LCSS algorithm on the trajectories. LCSSCalc(path1, path2, 2, 2, c(0, 3))
A function to calculate the longest common subsequence ratio using two trajectories. This calculation automatically uses translations to find the largest value.
LCSSRatio(traj1, traj2, pointSpacing=-1, pointDistance=20, errorMarg=2, returnTrans=FALSE)
LCSSRatio(traj1, traj2, pointSpacing=-1, pointDistance=20, errorMarg=2, returnTrans=FALSE)
traj1 |
An m x n matrix containing trajectory1. Here m is the number of points and n is the dimension of the points. |
traj2 |
A k x n matrix containing trajectory2. Here k is the number of points and n is the dimension of the points. The two trajectories are not required to have the same number of points. |
pointSpacing |
An integer value of the maximum index difference between trajectory1 and trajectory2 allowed in the calculation. A negative value sets the point spacing to unlimited. |
pointDistance |
A floating point number representing the maximum distance in each dimension allowed for points to be considered equivalent. |
errorMarg |
A floating point error margin used to scale the accuracy and speed of the calculation. |
returnTrans |
A boolean value to allow the best translation found to be returned as well as the LCSS value if set to true. |
The LCSS algorithm calculates the largest number of equivalent points between the two trajectories when traversed in a monotone way. The ratio of this value to the smallest number of points out of the two trajectories is then calculated. Possible translations are calculated in each dimension and used to provide the maximum LCSS. The accuracy of the algorithm can be varied to provide faster or slower calculations. Please see the references for more information.
A floating point value is returned. This represents the maximum LCSS ratio obtained using the variables provided. If returnTrans is set to TRUE, then the LCSS ratio and the translations are returned as a vector. The first value of this vector is the LCSS ratio and the translations follow directly afterwards. If a problem occurs, then a string containing information about the problem is returned.
Kevin Toohey
Vlachos, M., Kollios, G. and Gunopulos, D. (2002) Discovering similar multidimensional trajectories. Paper presented at the Data Engineering, 2002. Proceedings. 18th International Conference on.
LCSSCalc
, LCSS
, LCSSRatioCalc
, LCSSTranslation
# Creating two trajectories. path1 <- matrix(c(0, 1, 2, 3, 0, 1, 2, 3), 4) path2 <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7), 4) # Running the LCSS ratio algorithm on the trajectories. LCSSRatio(path1, path2, 2, 2, 0.5) # Running the LCSS ratio algorithm on the trajectories # and returning the translation as well. LCSSRatio(path1, path2, 2, 2, 0.5, TRUE)
# Creating two trajectories. path1 <- matrix(c(0, 1, 2, 3, 0, 1, 2, 3), 4) path2 <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7), 4) # Running the LCSS ratio algorithm on the trajectories. LCSSRatio(path1, path2, 2, 2, 0.5) # Running the LCSS ratio algorithm on the trajectories # and returning the translation as well. LCSSRatio(path1, path2, 2, 2, 0.5, TRUE)
A function to calculate the longest common subsequence ratio using two trajectories. This function does not calculate translations and only uses the given trajectories and optional translation.
LCSSRatioCalc(traj1, traj2, pointSpacing=-1, pointDistance=20, trans=rep(0.0, (dim(traj1)[2])))
LCSSRatioCalc(traj1, traj2, pointSpacing=-1, pointDistance=20, trans=rep(0.0, (dim(traj1)[2])))
traj1 |
An m x n matrix containing trajectory1. Here m is the number of points and n is the dimension of the points. |
traj2 |
A k x n matrix containing trajectory2. Here k is the number of points and n is the dimension of the points. The two trajectories are not required to have the same number of points. |
pointSpacing |
An integer value of the maximum index difference between trajectory1 and trajectory2 allowed in the calculation. A negative value sets the point spacing to unlimited. |
pointDistance |
A floating point number representing the maximum distance in each dimension allowed for points to be considered equivalent. |
trans |
A vector containing translations in each dimension to be applied to trajectory2 in this calculation. |
The LCSS algorithm calculates the largest number of equivalent points between the two trajectories when traversed in a monotone way. The ratio of this value to the smallest number of points out of the two trajectories is then calculated. If a translation is given then this is applied before the calculation is done. Please see the references for more information.
A floating point value is returned. This represents the maximum LCSS ratio obtained using the variables provided. If a problem occurs, then a string containing information about the problem is returned.
Kevin Toohey
Vlachos, M., Kollios, G. and Gunopulos, D. (2002) Discovering similar multidimensional trajectories. Paper presented at the Data Engineering, 2002. Proceedings. 18th International Conference on.
LCSS
, LCSSRatio
, LCSSCalc
, LCSSTranslation
# Creating two trajectories. path1 <- matrix(c(0, 1, 2, 3, 0, 1, 2, 3), 4) path2 <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7), 4) # Running the LCSS ratio algorithm on the trajectories. LCSSRatioCalc(path1, path2, 2, 2, c(0, 3))
# Creating two trajectories. path1 <- matrix(c(0, 1, 2, 3, 0, 1, 2, 3), 4) path2 <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7), 4) # Running the LCSS ratio algorithm on the trajectories. LCSSRatioCalc(path1, path2, 2, 2, c(0, 3))
A function to return the best translation calculated using the LCSS method. The vector created can be used to translate trajectory2's points to the position of the maximum LCSS found with trajectory1.
LCSSTranslation(traj1, traj2, pointSpacing=-1, pointDistance=20, errorMarg=2)
LCSSTranslation(traj1, traj2, pointSpacing=-1, pointDistance=20, errorMarg=2)
traj1 |
An m x n matrix containing trajectory1. Here m is the number of points and n is the dimension of the points. |
traj2 |
A k x n matrix containing trajectory2. Here k is the number of points and n is the dimension of the points. The two trajectories are not required to have the same number of points. |
pointSpacing |
An integer value of the maximum index difference between trajectory1 and trajectory2 allowed in the calculation. A negative value sets the point spacing to unlimited. |
pointDistance |
A floating point number representing the maximum distance in each dimension allowed for points to be considered equivalent. |
errorMarg |
A floating point error margin used to scale the accuracy and speed of the calculation. |
The LCSS function is called using the two trajectories along with the given variables. The optimal translation vector is then returned from this result. Please see the references for more information.
A vector of length n is returned containing the translation in each dimension. If a problem occurs, then a string containing information about the problem is returned.
Kevin Toohey
Vlachos, M., Kollios, G. and Gunopulos, D. (2002) Discovering similar multidimensional trajectories. Paper presented at the Data Engineering, 2002. Proceedings. 18th International Conference on.
AveTranslate
, StartEndTranslate
# Creating two trajectories. path1 <- matrix(c(0, 1, 2, 3, 0, 1, 2, 3), 4) path2 <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7), 4) # Running the translation. LCSSTranslation(path1, path2, 1, 1, 0.5)
# Creating two trajectories. path1 <- matrix(c(0, 1, 2, 3, 0, 1, 2, 3), 4) path2 <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7), 4) # Running the translation. LCSSTranslation(path1, path2, 1, 1, 0.5)
Function to loop over and test the trajectories using the different translations in each dimension. This is used by the LCSS function to test all of the n dimensional translations. Do not call this function directly.
SimLoop(traj1, traj2, pointSpacing, pointDistance, spacing, similarity, translations, dimensions, dimLeft=dimensions, currentTrans=rep(0, dimensions))
SimLoop(traj1, traj2, pointSpacing, pointDistance, spacing, similarity, translations, dimensions, dimLeft=dimensions, currentTrans=rep(0, dimensions))
traj1 |
An m x n matrix containing trajectory1. Here m is the number of points and n is the dimension of the points. |
traj2 |
A k x n matrix containing trajectory2. Here k is the number of points and n is the dimension of the points. The two trajectories are not required to have the same number of points. |
pointSpacing |
An integer value of the maximum index difference between trajectory1 and trajectory2 allowed in the calculation. |
pointDistance |
A floating point number representing the maximum distance in each dimension allowed for points to be considered equivalent. |
spacing |
The integer spacing between each translation that will be tested. |
similarity |
A vector containing the current best similarity and translations calculated. |
translations |
A list of vectors containing the translations in each dimension. |
dimensions |
An integer representing the number of dimensions being used for the calculation. |
dimLeft |
An integer number of dimensions which have not been looped over yet. |
currentTrans |
A vector containing the current translation being tested. |
This function is used to loop over the n dimensions for the LCSS
function. This function should not be called directly.
Returns the current best LCSS value and the translations that created this as a vector.
Kevin Toohey
LCSS
, LCSSRatio
, LCSSRatioCalc
, LCSSTranslation
, LCSSCalc
# Creating two trajectories. path1 <- matrix(c(0, 1, 2, 3, 0, 1, 2, 3), 4) path2 <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7), 4) # Running the LCSS algorithm on the trajectories. LCSS(path1, path2, 2, 2, 0.5)
# Creating two trajectories. path1 <- matrix(c(0, 1, 2, 3, 0, 1, 2, 3), 4) path2 <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7), 4) # Running the LCSS algorithm on the trajectories. LCSS(path1, path2, 2, 2, 0.5)
A function to calculate the Frechet distance between two trajectories. This function is called by the frechet function when one trajectory consists of a single point. This function does not need to be directly called.
SinglePointCalc(traj1, traj2)
SinglePointCalc(traj1, traj2)
traj1 |
An m x n matrix containing trajectory1. Here m is the number of points and n is the dimension of the points. |
traj2 |
A k x n matrix containing trajectory2. Here k is the number of points and n is the dimension of the points. The two trajectories are not required to have the same number of points. |
This calculates the longest distance to the single point trajectory. This is the Frechet distance for such a pair of trajectories. This function is automatically called if required by the Frechet
function, therefore it does not need to be called directly.
A floating point value representing the Frechet distance is returned.
Kevin Toohey
# Creating two trajectories. path1 <- matrix(c(0, 1), 1) path2 <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7), 4) # Running the Frechet distance algorithm which will # automatically call this function. Frechet(path1, path2)
# Creating two trajectories. path1 <- matrix(c(0, 1), 1) path2 <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7), 4) # Running the Frechet distance algorithm which will # automatically call this function. Frechet(path1, path2)
A function to translate, rotate and scale the points of trajectory2 using trajectory1. The new trajectory will have the same start and end points as trajectory1.
StartEndTranslate(traj1, traj2)
StartEndTranslate(traj1, traj2)
traj1 |
An m x n matrix containing trajectory1. Here m is the number of points and n is the dimension of the points. |
traj2 |
A k x n matrix containing trajectory2. Here k is the number of points and n is the dimension of the points. The two trajectories are not required to have the same number of points. |
Every point of trajectory2 is rotated, scaled and translated so that the start and end points of the two trajectories match. The new variation of trajectory2 is returned as a matrix.
An m x n matrix containing the new variation of trajectory2 is returned. Here m is the number of points and n is the dimension of the points.
Kevin Toohey
# Creating two trajectories. path1 <- matrix(c(0, 1, 2, 3, 0, 1, 2, 3), 4) path2 <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7), 4) # Running the translation. StartEndTranslate(path1, path2)
# Creating two trajectories. path1 <- matrix(c(0, 1, 2, 3, 0, 1, 2, 3), 4) path2 <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7), 4) # Running the translation. StartEndTranslate(path1, path2)
This function checks whether two trajectories are compatible with the functions provided. They are first checked if they are represented as matrices. They are then checked to ensure that points in both trajectories have the same dimensions.
TrajCheck(traj1, traj2)
TrajCheck(traj1, traj2)
traj1 |
An m x n matrix containing trajectory1. Here m is the number of points and n is the dimension of the points. |
traj2 |
A k x n matrix containing trajectory2. Here k is the number of points and n is the dimension of the points. The two trajectories are not required to have the same number of points. |
This function is useful for determining if the trajectories are compatible with the many functions provided. This function is performed at the start of most other functions to ensure that no major errors can occur and that the results make sense.
If there is a problem with one of the checks then a string containing information is returned. If all of the checks pass then -1 is returned.
Kevin Toohey
# Creating two trajectories. path1 <- matrix(c(0, 1, 2, 3, 0, 1, 2, 3), 4) path2 <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7), 4) path3 <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7), 2) # Running the trajectory check on the trajectories. TrajCheck(path1, path2) TrajCheck(path1, path3)
# Creating two trajectories. path1 <- matrix(c(0, 1, 2, 3, 0, 1, 2, 3), 4) path2 <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7), 4) path3 <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7), 2) # Running the trajectory check on the trajectories. TrajCheck(path1, path2) TrajCheck(path1, path3)
A function for calculating the subsets of translations to be tested using the LCSS methods.
TranslationSubset(traj1, traj2, pointSpacing, pointDistance)
TranslationSubset(traj1, traj2, pointSpacing, pointDistance)
traj1 |
A vector containing one dimension of trajectory1. |
traj2 |
A vector containing one dimension of trajectory2. |
pointSpacing |
An integer value of the maximum index difference between trajectory1 and trajectory2 allowed in the calculation. |
pointDistance |
A floating point number representing the maximum distance in each dimension allowed for points to be considered equivalent. |
This function is called by the LCSS
method to calculate the translations required.
A vector of floating point numbers is returned containing the translations calculated. This vector is sorted in ascending order.
Kevin Toohey