LPDistance: Lp distances.

View source: R/lp_distances.R

LPDistanceR Documentation

Lp distances.

Description

Computes the distance based on the chosen Lp norm between a pair of numeric vectors.

Usage

LPDistance(x, y, method="euclidean", ...)

Arguments

x

Numeric vector containing the first time series.

y

Numeric vector containing the second time series.

method

A value in "euclidean", "manhattan", "infnorm", "minkowski".

...

If method="minkowski" a positive integer value must be specified for p.

Details

The distances based on Lp norms are computed between two numeric vectors using the following formulas:

Euclidean distance: √{(x_i-y_i)^2)}

Manhattan distance: ∑{|x_i-y_i|}

Infinite norm distance: \max{|x_i-y_i|}

Minkowski distance: √[p]{(x_i-y_i)^p)}

The two series must have the same length. Furthermore, in the case of the Minkowski distance, p must be specified as a positive integer value.

Value

d

The computed distance between the pair of series.

Author(s)

Usue Mori, Alexander Mendiburu, Jose A. Lozano.

See Also

These distances are also implemeted in separate functions. For more information see EuclideanDistance, ManhattanDistance, MinkowskiDistance and InfNormDistance

To calculate this distance measure using ts, zoo or xts objects see TSDistances. To calculate distance matrices of time series databases using this measure see TSDatabaseDistances.

Examples


# The objects example.series1 and example.series2 are two 
# numeric series of length 100 contained in the TSdist package. 

data(example.series1)
data(example.series2)

# For information on their generation and shape see help 
# page of example.series.

help(example.series)

# Compute the different Lp distances

# Euclidean distance

LPDistance(example.series1, example.series2, method="euclidean")

# Manhattan distance

LPDistance(example.series1, example.series2, method="manhattan")

# Infinite norm distance

LPDistance(example.series1, example.series2, method="infnorm")

# Minkowski distance with p=3.

LPDistance(example.series1, example.series2, method="minkowski", p=3)


TSdist documentation built on Aug. 31, 2022, 5:09 p.m.