distance: Distance

View source: R/deepUtils.r

distanceR Documentation

Distance

Description

Distance

Usage

distance(
  x,
  y,
  type = c("euclidean", "squared euclidean", "manhattan", "minkowski", "chebyshev",
    "jaccard", "soergel", "geographical"),
  ...
)

Arguments

x

A numeric vector.

y

A numeric vector.

type

The type of the distance measure.

...

Optional arguments.

Details

The following types of distance measures are implemented:

  • Euclidean: \sqrt(\sum(x_i - y_i)^2)

  • Squared Euclidean: \sum(x_i - y_i)^2

  • Manhattan: \sum |x_i - y_i|

  • Minkowski: (\sum |x_i - y_i|^p)^(1/p)

  • Chebyshev: max |x_i - y_i|

  • Jaccard: 1 - Jaccard similarity

  • Soergel: 1 - Ruzicka similarity

  • Geographical distance based on longitude and latitude values expected for both x and y. Usually longitude and latitude values are given in degree, an automatically conversion to radian is made.

Value

The distance between x and y.

See Also

Other Utils: as_ANN_matrix(), degree(), list_as_numeric(), probability(), radian(), random_seed(), re.factor(), sd_pop(), similarity(), var_pop(), vector_as_ANN_matrix(), vector_as_numeric()

Examples

  # Euclidean distance
  x <- c(20, 1, 41, 13, 5, 69)
  y <- c(11, 2, 23, 4, 10, 67)
  distance(x, y)

  # Geographical distance
  geo_coord <- c("longitude", "latitude")
  regensburg <- setNames(c(49.013432, 12.101624), geo_coord)
  kiel <- setNames(c(54.323292, 10.122765), geo_coord)
  distance(regensburg, kiel, type = "geographical")

stschn/deepANN documentation built on June 25, 2024, 7:27 a.m.