Search in sources :

Example 1 with Summarizer

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.numeric.Summarizer in project clusterMaker2 by RBVI.

the class MSplitSilhouetteCalculator method splitByAverageSilhouette.

public static Clusters splitByAverageSilhouette(Segregatable seg, int K, boolean forceSplit, Summarizer summarizer) {
    Clusters split = segregateByAverageSilhouette(seg, K, summarizer);
    if (!forceSplit) {
        // consider no split (k = 1)
        if (split.getCost() >= 1) {
            // cost >= 1  =>  average silhouette < 0  =>  no splitting is warranted
            split = seg.cluster(1);
            split.setCost(1.0);
        }
    }
    return split;
}
Also used : Clusters(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters)

Example 2 with Summarizer

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.numeric.Summarizer in project clusterMaker2 by RBVI.

the class MSplitSilhouetteCalculator method averageSilhouettes.

public static ArrayList<Double> averageSilhouettes(Subsegregatable sseg, Clusters clusters, int L, Summarizer summarizer) {
    int K = clusters.getNumberOfClusters();
    ArrayList<Double> splitSilhouettes = new ArrayList<Double>();
    int[][] partitions = clusters.getPartitions();
    // calculate the split silhouette of each cluster
    for (int kk = 0; kk < K; ++kk) {
        Clusters subclusters = segregateByAverageSilhouette(sseg.subset(partitions[kk]), L, summarizer);
        if (subclusters != null) {
            // cluster could be split further into subclusters
            splitSilhouettes.add(1 - subclusters.getCost());
        }
    }
    return splitSilhouettes;
}
Also used : ArrayList(java.util.ArrayList) Clusters(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters)

Example 3 with Summarizer

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.numeric.Summarizer in project clusterMaker2 by RBVI.

the class HopachablePAM method collapse.

public Clusters collapse(int i, int j, Clusters clusters) {
    // NB    In Pollard's implementation, the choice of the new medoid probably does not change downstream results...
    Clusters c = new Clusters(clusters);
    c.merge(i, j);
    // set new cost
    switch(splitCost) {
        case AVERAGE_SILHOUETTE:
            c.setCost(1 - SilhouetteCalculator.silhouettes(this.segregations(c), c).getAverage(summarizer));
            break;
        case AVERAGE_SPLIT_SILHOUETTE:
        default:
            c.setCost(MSplitSilhouetteCalculator.averageSplitSilhouette(this, c, maxL, summarizer));
            break;
    }
    return c;
}
Also used : Clusters(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters)

Example 4 with Summarizer

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.numeric.Summarizer in project clusterMaker2 by RBVI.

the class MSplitSilhouetteCalculator method segregateByAverageSilhouette.

public static Clusters segregateByAverageSilhouette(Segregatable seg, int K, Summarizer summarizer) {
    Clusters split = null;
    int m = seg.size();
    // bound K
    if (K > m - 1) {
        K = m - 1;
    }
    // maximize average silhouette
    double avgSil = Double.NEGATIVE_INFINITY;
    for (int k = 2; k <= K; ++k) {
        Clusters clusters = seg.cluster(k);
        Silhouettes sils = SilhouetteCalculator.silhouettes(seg.segregations(clusters), clusters);
        double t = sils.getAverage(summarizer);
        if (t > avgSil) {
            avgSil = t;
            split = clusters;
        }
    }
    if (split != null) {
        // replace classification cost by (1 - average silhouette)
        split.setCost(1 - avgSil);
    }
    return split;
}
Also used : Clusters(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters)

Example 5 with Summarizer

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.numeric.Summarizer in project clusterMaker2 by RBVI.

the class MSplitSilhouetteCalculator method splitByAverageSplitSilhouette.

public static Clusters splitByAverageSplitSilhouette(Subsegregatable sseg, int K, int L, boolean forceSplit, Summarizer summarizer) {
    Clusters split = null;
    int m = sseg.size();
    // bound K
    if (K > m / 3) {
        K = m / 3;
    }
    int minK = (forceSplit ? 2 : 1);
    // minimize the mean split silhouette
    double avgSplitSil = Double.POSITIVE_INFINITY;
    for (int k = minK; k <= K; k++) {
        Clusters clusters = sseg.cluster(k);
        double t = averageSplitSilhouette(sseg, clusters, L, summarizer);
        if (t < avgSplitSil) {
            avgSplitSil = t;
            split = clusters;
        }
    }
    if (split == null) {
        split = sseg.cluster(minK);
    }
    split.setCost(avgSplitSil);
    return split;
}
Also used : Clusters(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters)

Aggregations

Clusters (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters)6 HopachablePAM (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.pam.HopachablePAM)1 MeanSummarizer (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.numeric.MeanSummarizer)1 MedianSummarizer (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.numeric.MedianSummarizer)1 PrimitiveMeanSummarizer (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.numeric.PrimitiveMeanSummarizer)1 PrimitiveMedianSummarizer (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.numeric.PrimitiveMedianSummarizer)1 PrimitiveSummarizer (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.numeric.PrimitiveSummarizer)1 Summarizer (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.numeric.Summarizer)1 ArrayList (java.util.ArrayList)1