Example usage for weka.clusterers Canopy nonEmptyCanopySetIntersection

List of usage examples for weka.clusterers Canopy nonEmptyCanopySetIntersection

Introduction

In this page you can find the example usage for weka.clusterers Canopy nonEmptyCanopySetIntersection.

Prototype

public static boolean nonEmptyCanopySetIntersection(long[] first, long[] second) throws Exception 

Source Link

Document

Tests if two sets of canopies have a non-empty intersection

Usage

From source file:clusterer.SimpleKMeansWithSilhouette.java

License:Open Source License

/**
 * clusters an instance that has been through the filters.
 * //from   w  w  w.  j  a v  a 2s  .c o  m
 * @param instance the instance to assign a cluster to
 * @param updateErrors if true, update the within clusters sum of errors
 * @param useFastDistCalc whether to use the fast distance calculation or not
 * @param instanceCanopies the canopies covering the instance to be clustered,
 *          or null if not using the option to reduce the number of distance
 *          computations via canopies
 * @return a cluster number
 */
private int clusterProcessedInstance(Instance instance, boolean updateErrors, boolean useFastDistCalc,
        long[] instanceCanopies) {
    double minDist = Integer.MAX_VALUE;
    int bestCluster = 0;
    for (int i = 0; i < m_NumClusters; i++) {
        double dist;
        if (useFastDistCalc) {
            if (m_speedUpDistanceCompWithCanopies && instanceCanopies != null && instanceCanopies.length > 0) {
                try {
                    if (!Canopy.nonEmptyCanopySetIntersection(m_centroidCanopyAssignments.get(i),
                            instanceCanopies)) {
                        continue;
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                dist = m_DistanceFunction.distance(instance, m_ClusterCentroids.instance(i), minDist);
            } else {
                dist = m_DistanceFunction.distance(instance, m_ClusterCentroids.instance(i), minDist);
            }
        } else {
            dist = m_DistanceFunction.distance(instance, m_ClusterCentroids.instance(i));
        }
        if (dist < minDist) {
            minDist = dist;
            bestCluster = i;
        }
    }
    if (updateErrors) {
        if (m_DistanceFunction instanceof EuclideanDistance) {
            // Euclidean distance to Squared Euclidean distance
            minDist *= minDist * instance.weight();
        }
        m_squaredErrors[bestCluster] += minDist;
    }
    return bestCluster;
}