net.sourceforge.cilib.util
Class MinkowskiMetric

java.lang.Object
  extended by net.sourceforge.cilib.util.MinkowskiMetric
All Implemented Interfaces:
DistanceMeasure
Direct Known Subclasses:
ChebyshevDistanceMeasure, EuclideanDistanceMeasure, ManhattanDistanceMeasure

public class MinkowskiMetric
extends Object
implements DistanceMeasure

The Minkowski Metric is a generic measure of distance. It is defined in:

 Article{ 331504, author = "A. K. Jain and M. N. Murty and P. J. Flynn", title = "Data
           Clustering: A Review", journal = "ACM Computing Surveys", volume = "31", number = "3",
           year = "1999", issn = "0360-0300", pages = "264--323", doi =
           "http://0-doi.acm.org.innopac.up.ac.za:80/10.1145/331499.331504", publisher = "ACM
           Press", address = "New York, NY, USA" }
 

Manhattan Distance is a special case of the Minkowski Metric with 'alpha' := 1.
Euclidean Distance is a special case of the Minkowski Metric with 'alpha' := 2.

NOTE: The default 'alpha' value is 0 when this class is instantiated.

Author:
Theuns Cloete

Field Summary
protected  int alpha
           
 
Constructor Summary
MinkowskiMetric()
          Instantiate the Minkowski Metric with 'alpha' value equal to zero.
MinkowskiMetric(int a)
          Instantiate the Minkowski Metric with the specified 'alpha' value.
 
Method Summary
<T extends Collection<? extends Number>>
double
distance(T x, T y)
          Calculate the distance between two vectors represented by Java Collection objects.
<T extends Type,U extends StructuredType<T>>
double
distance(U x, U y)
          Calculate the distance between two vectors.
 void setAlpha(int a)
          Set the 'alpha' value that will be used in the calculation of the Minkowski Metric.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

alpha

protected int alpha
Constructor Detail

MinkowskiMetric

public MinkowskiMetric()
Instantiate the Minkowski Metric with 'alpha' value equal to zero. This means that you have to call the setAlpha method right after calling this constructor.


MinkowskiMetric

public MinkowskiMetric(int a)
Instantiate the Minkowski Metric with the specified 'alpha' value.

Parameters:
a - the value to which 'alpha' should be set
Method Detail

distance

public <T extends Type,U extends StructuredType<T>> double distance(U x,
                                                                    U y)
Calculate the distance between two vectors.

Specified by:
distance in interface DistanceMeasure
Parameters:
x - the one vector.
y - the other vector.
Returns:
the distance (as a double) between the two vectors.
Throws:
IllegalArgumentException - when the two vectors' dimension differ.

distance

public <T extends Collection<? extends Number>> double distance(T x,
                                                                T y)
Calculate the distance between two vectors represented by Java Collection objects.

Specified by:
distance in interface DistanceMeasure
Type Parameters:
T - The Collection type.
Parameters:
x - the one Java Collection object.
y - the other Java Collection object.
Returns:
the distance (as a double) between the two vectors.
Throws:
IllegalArgumentException - when the two vectors' dimension differ.

setAlpha

public void setAlpha(int a)
Set the 'alpha' value that will be used in the calculation of the Minkowski Metric.

Parameters:
a - the new 'alpha' value
Throws:
IllegalArgumentException - when the given parameter is less than one.


Copyright © 2009 CIRG. All Rights Reserved.