de.unibi.techfak.jpredictor.clustering
Class LikelihoodMeasure

java.lang.Object
  extended by de.unibi.techfak.jpredictor.clustering.RelationMeasure
      extended by de.unibi.techfak.jpredictor.clustering.VectorRelationMeasure
          extended by de.unibi.techfak.jpredictor.clustering.LikelihoodMeasure
All Implemented Interfaces:
Computable, java.lang.Comparable

public class LikelihoodMeasure
extends VectorRelationMeasure

Calculates the likelyhood between two vectors. The formula behind is: sum_{i=1}^{n}{x_i*y_i}. Its actually a measure on how well one vector explains the other one.

This class computes the distance for only two vectors. If more than two arrays were added the latest ones added are used for computation.


Field Summary
 
Fields inherited from class de.unibi.techfak.jpredictor.clustering.VectorRelationMeasure
vectorList
 
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
LikelihoodMeasure()
          Inits the Likelyhood measure between two vectors.
 
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.
static double calculate(double[] x, double[] y)
          Calculates the Likelyhood measure between two given arrays.
 int compute()
          Uses all internal informations available and starts and controlls the computational process.
 RelationMeasure newInstance()
          Creates a copy of this relation measure as if it was newly instantiated through a call to the constructor.
 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.
 
Methods inherited from class de.unibi.techfak.jpredictor.clustering.VectorRelationMeasure
add, add, add, clear, length
 
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

LikelihoodMeasure

public LikelihoodMeasure()
Inits the Likelyhood measure between two vectors.

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

calculate

public static double calculate(double[] x,
                               double[] y)
Calculates the Likelyhood measure between two given arrays. Returns Double.NaN in case of any error, e.g. x or y are null or of inequal length.

Parameters:
x - The first array.
y - The second array
Returns:
The Likelyhood measure between two arrays.

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.

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.

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