at.tuwien.ifs.somtoolbox.layers.metrics
Class CosineMetric

java.lang.Object
  extended by at.tuwien.ifs.somtoolbox.layers.metrics.AbstractMetric
      extended by at.tuwien.ifs.somtoolbox.layers.metrics.CosineMetric
All Implemented Interfaces:
DistanceMetric, Comparable<DistanceMetric>

public class CosineMetric
extends AbstractMetric

Implements the cosine metric, defined for two vectors d1 and d2 as d1xd2 / (|d1|*|d2|).

Version:
$Id: CosineMetric.java 3358 2010-02-11 14:35:07Z mayer $
Author:
Rudolf Mayer

Nested Class Summary
 
Nested classes/interfaces inherited from interface at.tuwien.ifs.somtoolbox.layers.metrics.DistanceMetric
DistanceMetric.SparcseMetricModes
 
Field Summary
 
Fields inherited from class at.tuwien.ifs.somtoolbox.layers.metrics.AbstractMetric
PACKAGE_NAME
 
Constructor Summary
CosineMetric()
           
 
Method Summary
 double distance(double[] vector1, double[] vector2)
          Calculates the distance between two vectors provided by argument vector1 and vector2.
 double distance(cern.colt.matrix.DoubleMatrix1D vector1, cern.colt.matrix.DoubleMatrix1D vector2)
          Calculates the distance between two vectors provided by argument vector1 and vector2.
static void main(String[] args)
          Main method to test the metric.
 String toString()
           
 
Methods inherited from class at.tuwien.ifs.somtoolbox.layers.metrics.AbstractMetric
checkDimensions, checkDimensions, compareTo, distance, distance, distance, distance, distance, distance, distance, instantiate, instantiateNice, meanVector, performanceTest, setMetricParams, transformValue, transformVector
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CosineMetric

public CosineMetric()
Method Detail

distance

public 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
Specified by:
distance in class AbstractMetric
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[])

distance

public double distance(cern.colt.matrix.DoubleMatrix1D vector1,
                       cern.colt.matrix.DoubleMatrix1D 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
Overrides:
distance in class AbstractMetric
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(cern.colt.matrix.DoubleMatrix1D, cern.colt.matrix.DoubleMatrix1D)

toString

public String toString()
Overrides:
toString in class Object

main

public static void main(String[] args)
                 throws MetricException
Main method to test the metric.

Throws:
MetricException