at.tuwien.ifs.feature.extraction.audio.distance
Class AbstractMetric

java.lang.Object
  extended by at.tuwien.ifs.feature.extraction.audio.distance.AbstractMetric
All Implemented Interfaces:
DistanceMetric
Direct Known Subclasses:
L1Metric, L2Metric

public abstract class AbstractMetric
extends java.lang.Object
implements DistanceMetric

Implements a static method for metric instantiation and a method for mean vector calculation. Furthermore, implements the convenience methods to call the abstract method having two double arrays as arguments (see distance(double[], double[])). This method has to be implemented by classes actually implementing a certain metric.

Version:
$Id: AbstractMetric.java 167 2010-06-17 10:12:01Z frank $
Author:
mbach

Constructor Summary
AbstractMetric()
           
 
Method Summary
protected  void checkDimensions(double[] vector1, double[] vector2)
          Performs a check on wether the given vectors have the same dimension.
abstract  double distance(double[] vector1, double[] vector2)
          Calculates the distance between two vectors provided by argument vector1 and vector2.
static DistanceMetric instantiate(java.lang.String mName)
          Instantiates a certain distance metric class specified by argument mName.
static double[] meanVector(double[] vector1, double[] vector2)
          Calculates the mean vector of two double array vectors.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractMetric

public AbstractMetric()
Method Detail

instantiate

public static DistanceMetric instantiate(java.lang.String mName)
                                  throws java.lang.ClassNotFoundException,
                                         java.lang.InstantiationException,
                                         java.lang.IllegalAccessException
Instantiates a certain distance metric class specified by argument mName.

Parameters:
mName - the name of the metric.
Returns:
a distance metric object of class mName.
Throws:
java.lang.ClassNotFoundException - if class denoted by argument mName is not found.
java.lang.InstantiationException - if if this Class represents an abstract class, an interface, an array class, a primitive type, or void; or if the class has no nullary constructor; or if the instantiation fails for some other reason.
java.lang.IllegalAccessException - if the class or its nullary constructor is not accessible.

meanVector

public static double[] meanVector(double[] vector1,
                                  double[] vector2)
                           throws MetricException
Calculates the mean vector of two double array vectors.

Parameters:
vector1 - first vector.
vector2 - second vector.
Returns:
the mean vector.
Throws:
MetricException - if the dimensionalities of the two vectors differ.

distance

public abstract double distance(double[] vector1,
                                double[] vector2)
                         throws MetricException
Description copied from interface: DistanceMetric
Calculates the distance between two vectors provided by argument vector1 and vector2. A MetricException is thrown, if the dimensionalities of the two vectors differ.

Specified by:
distance in interface DistanceMetric
Parameters:
vector1 - first vector.
vector2 - second vector.
Returns:
the distance between vector1 and vector2.
Throws:
MetricException - if the dimensionalities of the two vectors differ.
See Also:
DistanceMetric.distance(double[], double[])

checkDimensions

protected void checkDimensions(double[] vector1,
                               double[] vector2)
                        throws MetricException
Performs a check on wether the given vectors have the same dimension.

Throws:
MetricException - If the given vectors have different dimensions.