package jsat.clustering.evaluation;
import java.util.List;
import jsat.DataSet;
import jsat.classifiers.DataPoint;
import jsat.clustering.ClustererBase;
import jsat.clustering.dissimilarity.ClusterDissimilarity;
import jsat.clustering.evaluation.intra.IntraClusterEvaluation;
/**
* Computes the Dunn Index (DI) using a customizable manner. Normally, a higher
* DI value indicates a better value. In order to conform to the interface
* contract of a lower value indicating a better result, the value of 1/(1+DI)
* is returned.
*
* @author Edward Raff
*/
public class DunnIndex implements ClusterEvaluation
{
private IntraClusterEvaluation ice;
private ClusterDissimilarity cd;
/**
* Creates a new DunnIndex
* @param ice the metric to measure the quality of a single cluster
* @param cd the metric to measure the distance between two clusters
*/
public DunnIndex(IntraClusterEvaluation ice, ClusterDissimilarity cd)
{
this.ice = ice;
this.cd = cd;
}
/**
* Copy constructor
* @param toCopy the object to copy
*/
public DunnIndex(DunnIndex toCopy)
{
this(toCopy.ice.clone(), toCopy.cd.clone());
}
@Override
public double evaluate(int[] designations, DataSet dataSet)
{
return evaluate(ClustererBase.createClusterListFromAssignmentArray(designations, dataSet));
}
@Override
public double evaluate(List> dataSets)
{
double minVal = Double.POSITIVE_INFINITY;
double maxIntra = Double.NEGATIVE_INFINITY;
for(int i = 0; i < dataSets.size(); i++)
{
for(int j = i+1; j
Ads help maintain this website.