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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations