de.unibi.techfak.jpredictor.clustering
Class MatrixSimilarity

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
All Implemented Interfaces:
Computable, java.lang.Comparable
Direct Known Subclasses:
MatrixDistance, MatrixLikelihood, MatrixLoglikelihood

public abstract class MatrixSimilarity
extends MatrixRelationMeasure

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
(package private)  VectorRelationMeasure vrm
          Defines how the single columns of two matrices are to be computed.
 
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
MatrixSimilarity(VectorRelationMeasure vrm)
          Constructs this class with the relation measure.
 
Method Summary
 int compute()
          Uses all internal informations available and starts and controlls the computational process.
 int optimum(double rel0, double rel1)
           Compares two relation measure results.
 java.lang.String toString()
          Creates a short string of this relation measure and maybe some results if available.
(package private) abstract  double vectorResultsCombine(double resultSoFar, double nextResult)
          Operation to combine a result calculated so far and a next result.
(package private) abstract  double vectorResultsInit()
          The neutral/initial value for combining the vectorial results.
 
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, atomicCombine, atomicNormalize, compareTo, newInstance, optimum, result
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

vrm

VectorRelationMeasure vrm
Defines how the single columns of two matrices are to be computed. Set in the constructor.

See Also:
MinkowskiDistance, ManhattanDistance
Constructor Detail

MatrixSimilarity

public MatrixSimilarity(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

compute

public int compute()
Description copied from interface: Computable
Uses all internal informations available and starts and controlls the computational process. In its simplest case it is a method to calculate a formula, a more complicate way would be to run e.g. a whole clustering through this method.

Returns:
A status code about the process, e.g. COMPUTATION_SUCCESS.
See Also:
Computable.COMPUTATION_SUCCESS, Computable.COMPUTATION_FAILED

vectorResultsInit

abstract double vectorResultsInit()
The neutral/initial value for combining the vectorial results. For sums it would be zero, for products one.

Returns:
The init value/neutral element.

vectorResultsCombine

abstract double vectorResultsCombine(double resultSoFar,
                                     double nextResult)
Operation to combine a result calculated so far and a next result. Might be an addition or a multiplication or a log.

Parameters:
resultSoFar -
nextResult -
Returns:
The new result.

optimum

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

Compares two relation measure results. Returns -1, zero or 1, if the first (rel0) measure is worse, equal, or better than the second one (rel1). The terms worse and better depend on the implementation of the RelationMeasure inheriting this method. Usually, when dealing with distances, the lower the better. On the other side, when dealing with likelihoods the higher the better.

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:
optimum 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:
-1, zero or 1 in case the first result is worse, equal or better than the second one.

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.

Specified by:
toString in class RelationMeasure
Returns:
A string with a short description of the class.