ms-0.2.1: metric spaces

Copyright(C) 2015 Ricky Elrod, Tony Morris
LicenseBSD2 (see LICENSE file)
MaintainerRicky Elrod <ricky@elrod.me>
Stabilityprovisional
Portabilitylens
Safe HaskellNone
LanguageHaskell2010

Math.MetricSpace

Description

A MetricSpace is a set together with a notion of distance between elements. Distance is computed by a function dist which has the following four laws:

  1. non-negative: forall x y. dist x y >= 0
  2. identity of indiscernibles: forall x y. dist x y == 0 <=> x == y
  3. symmetry: forall x y. dist x y == dist y x
  4. triangle inequality: forall x y z. dist x z <= dist x y + dist y z

See the Wikipedia article on metric spaces for more details.

Synopsis

Documentation

>>> import qualified Data.Vector as V

(<->) :: MetricSpace a b -> a -> a -> b infixl 8 Source

class SwappedMetricSpace m where Source

Minimal complete definition

Nothing

Methods

_SwappedMetricSpace :: Iso (m a b) (m x y) (m a b) (m x y) Source

levenshtein :: Integral b => MetricSpace String b Source

Levenshtein distance between Strings.

>>> dist levenshtein "foo" "bar"
3
>>> dist levenshtein "hi" "ha"
1
>>> dist levenshtein "ff" "ff"
0

discrete :: (Eq a, Integral b) => MetricSpace (Vector a) b Source

Discrete distance over n-dimensional Vectors.

>>> dist discrete (V.fromList [3,4]) (V.fromList [3,4])
0
>>> dist discrete (V.fromList [1,49]) (V.fromList [3,-94])
1

euclidean :: RealFloat a => MetricSpace (Vector a) a Source

Euclidean distance over n-dimensional Vectors.

>>> dist euclidean (V.fromList [3,4]) (V.fromList [3,4])
0.0
>>> dist euclidean (V.fromList [1,49]) (V.fromList [3,-94])
143.01398533010678

taxicab :: RealFloat a => MetricSpace (Vector a) a Source

Taxicab distance over n-dimensional Vectors.

>>> dist taxicab (V.fromList [3,4]) (V.fromList [3,4])
0.0
>>> dist taxicab (V.fromList [1,49]) (V.fromList [3,-94])
145.0

hamming :: (Eq a, Integral b) => MetricSpace (Vector a) b Source

Hamming distance over n-dimensional Vectors.