de.unibi.techfak.jpredictor.clustering
Class MatrixLikelihood

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.MatrixLikelihood
All Implemented Interfaces:
Computable, java.lang.Comparable

public class MatrixLikelihood
extends MatrixSimilarity

Calculates the likelihood between two matrices. Both matrices must consist of the same number of rows and columns. The difference to MatrixSimilarity is, that the vector results are not added but multipied.

Note: when dealing with likelihoods results can become very small very fast. Maybe to fast for double values to hold the value. It is strongly recommended to use MatrixLoglikelihood instead.

See Also:
MatrixLoglikelihood

Field Summary
(package private)  double zero
          Replacement multiplier for vector results that are zero.
 
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
MatrixLikelihood(VectorRelationMeasure vrm, double zero)
          Constructs this class with a vector relation measure and a replacement for zero vector computation results.
 
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
 

Field Detail

zero

double zero
Replacement multiplier for vector results that are zero. Since the vector results are multipied over the whole matrix one zero would zero the result as well. Thus, this "pseudo count" value is introduced.

Constructor Detail

MatrixLikelihood

public MatrixLikelihood(VectorRelationMeasure vrm,
                        double zero)
                 throws java.lang.NullPointerException
Constructs this class with a vector relation measure and a replacement for zero vector computation results.

Parameters:
vrm - The relation measure between two vectors of the matrix.
zero - The "pseudo count" value if one vector result is zero. Should not, but can be 0. When dealing with probabilities a value of 0.01 is recommended.
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.