de.unibi.techfak.jpredictor.clustering
Class MatrixDistance

java.lang.Object
  extended by de.unibi.techfak.jpredictor.clustering.RelationMeasure
      extended by de.unibi.techfak.jpredictor.clustering.MatrixRelationMeasure
          extended by de.unibi.techfak.jpredictor.clustering.MatrixSimilarity
              extended by de.unibi.techfak.jpredictor.clustering.MatrixDistance
All Implemented Interfaces:
Computable, java.lang.Comparable

public class MatrixDistance
extends MatrixSimilarity

Class for calculating the similarity between two matrices. The similarity is calculated by adding up the similarity between every two matrix arrays. Different vector similarity measures can be given. This class is used like this:

  MatrixSimilarity ms = new MatrixSimilarity( new EuclideanDistance() );
  ms.add( firstMatrix );
  ms.add( secondMatrix );
  ms.compute();
  // process result (first against second)
  ms.add( thirdMatrix );
  ms.compute();
  // process result (second against third)
  ...
 
.

See Also:
VectorRelationMeasure, MinkowskiDistance, LikelihoodMeasure

Field Summary
 
Fields inherited from class de.unibi.techfak.jpredictor.clustering.MatrixSimilarity
vrm
 
Fields inherited from class de.unibi.techfak.jpredictor.clustering.MatrixRelationMeasure
matrixList
 
Fields inherited from class de.unibi.techfak.jpredictor.clustering.RelationMeasure
computationResult
 
Fields inherited from interface de.unibi.techfak.jpredictor.clustering.Computable
COMPUTATION_FAILED, COMPUTATION_PENDING, COMPUTATION_SUCCESS, COMPUTATION_WAITING
 
Constructor Summary
MatrixDistance(VectorRelationMeasure vrm)
          Constructs this class with the relation measure.
 
Method Summary
 double atomicCombine(double rel0, double rel1)
           Two relations measures are combined to one result, which is not stored but returned.
 double atomicNormalize(double rel, double norm)
           A relations measures is normalized by a certain amount.
 RelationMeasure newInstance()
          Creates a copy of this relation measure as if it was newly instantiated through a call to the constructor.
 java.lang.String toString()
          Creates a short string of this relation measure and maybe some results if available.
(package private)  double vectorResultsCombine(double resultSoFar, double nextResult)
          Operation to combine a result calculated so far and a next result.
(package private)  double vectorResultsInit()
          The neutral/initial value for combining the vectorial results.
 
Methods inherited from class de.unibi.techfak.jpredictor.clustering.MatrixSimilarity
compute, optimum
 
Methods inherited from class de.unibi.techfak.jpredictor.clustering.MatrixRelationMeasure
add, add, clear, length, lengthRow
 
Methods inherited from class de.unibi.techfak.jpredictor.clustering.RelationMeasure
atomicCombine, compareTo, optimum, result
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MatrixDistance

public MatrixDistance(VectorRelationMeasure vrm)
               throws java.lang.NullPointerException
Constructs this class with the relation measure.

Parameters:
vrm - The relation measure between two vectors of the matrix.
Throws:
java.lang.NullPointerException - if vrm is null.
Method Detail

vectorResultsInit

double vectorResultsInit()
Description copied from class: MatrixSimilarity
The neutral/initial value for combining the vectorial results. For sums it would be zero, for products one.

Specified by:
vectorResultsInit in class MatrixSimilarity
Returns:
The init value/neutral element.

vectorResultsCombine

double vectorResultsCombine(double resultSoFar,
                            double nextResult)
Description copied from class: MatrixSimilarity
Operation to combine a result calculated so far and a next result. Might be an addition or a multiplication or a log.

Specified by:
vectorResultsCombine in class MatrixSimilarity
Returns:
The new result.

atomicCombine

public double atomicCombine(double rel0,
                            double rel1)
Description copied from class: RelationMeasure

Two relations measures are combined to one result, which is not stored but returned. This method provides a way to calculate the combined result, when the way how to do this is not known. For instance, distance relation measures normally sum up over single results while likelihood/probabilities are multiplied.

Note, that it is possible to mix up optimization of different relation measures, e.g. distances and likelihoods, since this method works on any numbers.

Specified by:
atomicCombine in class RelationMeasure
Parameters:
rel0 - The first relation measure to be compared to the second.
rel1 - The second relation measure to be compared to the first.
Returns:
The result of combining two relation measures, e.g. through adding them up, or multiplying them or such.

atomicNormalize

public double atomicNormalize(double rel,
                              double norm)
Description copied from class: RelationMeasure

A relations measures is normalized by a certain amount. This method provides a way to normalize a relation measure after numbers of them were combined. For instance, distance relation measures normally are normalized by dividing through the count, while likelihoods are rooted.

Note, that it is possible to mix up optimization of different relation measures, e.g. distances and likelihoods, since this method works on any numbers.

Specified by:
atomicNormalize in class RelationMeasure
Parameters:
rel - The relation measure to be normalized.
norm - The normalization value.
Returns:
The result of normalizing a relation measures. Or Double.NaN in case of error.

newInstance

public RelationMeasure newInstance()
Description copied from class: RelationMeasure
Creates a copy of this relation measure as if it was newly instantiated through a call to the constructor. Note: if a class relies on really unique relation measures that are never shared with other instances it should call this method in the constructor. This might be the case, if a class uses a relation measures to store results of partially results.

Specified by:
newInstance in class RelationMeasure
Returns:
A copy of the relation measure as if it was newly instantiated.

toString

public java.lang.String toString()
Description copied from class: RelationMeasure
Creates a short string of this relation measure and maybe some results if available.

Overrides:
toString in class MatrixSimilarity
Returns:
A string with a short description of the class.