Mobios v0.91

mobios.dist
Class LMetric

java.lang.Object
  extended by mobios.dist.LMetric
All Implemented Interfaces:
Serializable, Metric

public class LMetric
extends Object
implements Metric

This class computes the L family distance function on two vectors. Given two vectors x(x1,x2,...,xk), y(y1,y2,...,yk), the distance between x,y: Ls(x,y) = sum( |xi-yi|^s )^(1/s), i= 1,..,k where s=1,2,...,infinity. For infinite distance, L(x,y) = max( |xi-yi| ), i = 1,...,k. L1 is called Manhattan distance, L2 is called Euclidean distance. In this implementation, L0 is used to represent L infinity.

Version:
2005.10.31
Author:
Rui Mao, Wenguo Liu, Willard
See Also:
Serialized Form

Field Summary
static LMetric EuclideanDistanceMetric
          L2 distance (Euclidean distance) metric for two non-null double arrays of the same length.
static LMetric LInfinityDistanceMetric
          L infinity distance metric for two non-null double arrays of the same length.
static LMetric ManhattanDistanceMetric
          L1 distance (Manhattan distance) metric for two non-null double arrays of the same length.
 
Constructor Summary
LMetric(int dim)
          Constructor.
 
Method Summary
 int getDimension()
           
 double getDistance(double[] a1, double[] a2)
          Computes the distance between two double arrays with the same dimension.
 double getDistance(DoubleVector dv1, DoubleVector dv2)
          Computes the distance between two DoubleVectors with the same dimension.
 double getDistance(IndexObject o1, IndexObject o2)
          Computes the distance between two objects.
static void main(String[] args)
          main method, for test, 3 arguments argument 1: dimension of the metric argument 2,3: the two vectors, dimension by dimension, seperated by comma, no space.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ManhattanDistanceMetric

public static final LMetric ManhattanDistanceMetric
L1 distance (Manhattan distance) metric for two non-null double arrays of the same length. Given two vectors x(x1,x2,...,xk), y(y1,y2,...,yk), the distance between x,y: L1(x,y) = sum(|xi-yi| ), i= 1,..,k


EuclideanDistanceMetric

public static final LMetric EuclideanDistanceMetric
L2 distance (Euclidean distance) metric for two non-null double arrays of the same length. Given two vectors x(x1,x2,...,xk), y(y1,y2,...,yk), the distance between x,y: L2(x,y) = sum(|xi-yi|^2 )^(1/2), i= 1,..,k


LInfinityDistanceMetric

public static final LMetric LInfinityDistanceMetric
L infinity distance metric for two non-null double arrays of the same length. Given two vectors x(x1,x2,...,xk), y(y1,y2,...,yk), the distance between x,y: L infinity (x,y) = max( |xi-yi| ), i= 1,..,k

Constructor Detail

LMetric

public LMetric(int dim)
Constructor. Takes the dimension of the distance function as an argument. (The s, i.e., not the dimension of the vectors to compute distance on.) Use 0 to represent infinity.

Parameters:
dim - the dimension of the distance function
Method Detail

getDistance

public double getDistance(IndexObject o1,
                          IndexObject o2)
Description copied from interface: Metric
Computes the distance between two objects.

Specified by:
getDistance in interface Metric
Parameters:
o1 - the first IndexObject to compute distance on
o2 - the second IndexObject to compute distance on
Returns:
the distance between the two objects

getDistance

public double getDistance(DoubleVector dv1,
                          DoubleVector dv2)
Computes the distance between two DoubleVectors with the same dimension.

Parameters:
dv1 - the first DoubleVector to compute distance on.
dv2 - the second DoubleVector to compute distance on.
Returns:
the distance between the two DoubleVectors

getDistance

public double getDistance(double[] a1,
                          double[] a2)
Computes the distance between two double arrays with the same dimension.

Parameters:
a1 - the first double array
a2 - the second double array
Returns:
the distance between the two arrays

getDimension

public int getDimension()
Returns:
the dimension of the metric

main

public static void main(String[] args)
main method, for test, 3 arguments argument 1: dimension of the metric argument 2,3: the two vectors, dimension by dimension, seperated by comma, no space.


Mobios v0.91

(C) 2002 - 2006 The MoBIoS Group