ClusterEvaluator (Apache Commons Math 3.3 API)

org.apache.commons.math3.ml.clustering.evaluation

## Class ClusterEvaluator<T extends Clusterable>

- java.lang.Object
- - org.apache.commons.math3.ml.clustering.evaluation.ClusterEvaluator<T>

- Type Parameters:
    `T` - type of the clustered points
  Direct Known Subclasses:
    SumOfClusterVariances

      public abstract class ClusterEvaluator<T extends Clusterable>
      extends Object

  Base class for cluster evaluation methods.
  Since:
    3.3
  Version:
    $Id: ClusterEvaluator.java 1542545 2013-11-16 18:48:48Z tn $

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ClusterEvaluator()` Creates a new cluster evaluator with an `EuclideanDistance` as distance measure.
    `ClusterEvaluator(DistanceMeasure measure)` Creates a new cluster evaluator with the given distance measure.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected Clusterable` | `centroidOf(Cluster<T> cluster)` Computes the centroid for a cluster.
    `protected double` | `distance(Clusterable p1, Clusterable p2)` Calculates the distance between two `Clusterable` instances with the configured `DistanceMeasure`.
    `boolean` | `isBetterScore(double score1, double score2)` Returns whether the first evaluation score is considered to be better than the second one by this evaluator.
    `abstract double` | `score(List<? extends Cluster<T>> clusters)` Computes the evaluation score for the given list of clusters.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ClusterEvaluator

          public ClusterEvaluator()

      Creates a new cluster evaluator with an `EuclideanDistance` as distance measure.

    - #### ClusterEvaluator

          public ClusterEvaluator(DistanceMeasure measure)

      Creates a new cluster evaluator with the given distance measure.
      Parameters:
        `measure` - the distance measure to use

  - ### Method Detail

    - #### score

          public abstract double score(List<? extends Cluster<T>> clusters)

      Computes the evaluation score for the given list of clusters.
      Parameters:
        `clusters` - the clusters to evaluate
      Returns:
        the computed score

    - #### isBetterScore

          public boolean isBetterScore(double score1,
                              double score2)

      Returns whether the first evaluation score is considered to be better than the second one by this evaluator.

      Specific implementations shall override this method if the returned scores do not follow the same ordering, i.e. smaller score is better.

      Parameters:
        `score1` - the first score
        `score2` - the second score
      Returns:
        `true` if the first score is considered to be better, `false` otherwise

    - #### distance

          protected double distance(Clusterable p1,
                        Clusterable p2)

      Calculates the distance between two `Clusterable` instances with the configured `DistanceMeasure`.
      Parameters:
        `p1` - the first clusterable
        `p2` - the second clusterable
      Returns:
        the distance between the two clusterables

    - #### centroidOf

          protected Clusterable centroidOf(Cluster<T> cluster)

      Computes the centroid for a cluster.
      Parameters:
        `cluster` - the cluster
      Returns:
        the computed centroid for the cluster, or `null` if the cluster does not contain any points

Copyright © 2003–2014 The Apache Software Foundation. All rights reserved.