use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters 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;
}
use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters in project clusterMaker2 by RBVI.
the class HopachPAMTest method testRun.
@Test
public void testRun() {
Double[] data = { 100.9, 100.9, 100.85, 100.85, 100.8, 100.8, .15, .15, .2, .2, .12, .12, .05, .05, .04, .04, .0, .0, .02, .02 };
int[] ans = { 0, 0, 0, 1, 1, 1, 2, 2, 2, 2 };
CyMatrix mat = CyMatrixFactory.makeSmallMatrix(10, 2, data);
HopachPAM h = new HopachPAM(mat, DistanceMetric.CITYBLOCK);
Clusters c = h.run();
// check that the clustering results match
for (int i = 0; i < c.size(); ++i) {
assertEquals(c.getClusterIndex(i), ans[i]);
}
}
use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters in project clusterMaker2 by RBVI.
the class HopachPAMTest method testInitLevel.
@Test
public void testInitLevel() {
Double[] data = { 100.9, 100.9, 100.85, 100.85, 100.8, 100.8, .15, .15, .2, .2, .12, .12, .05, .05, .04, .04, .0, .0, .02, .02 };
// median
// int[] ans = {0, 0, 0, 1, 1, 1, 1, 1, 1, 1};
// mean
int[] ans = { 0, 0, 0, 1, 1, 1, 2, 2, 2, 2 };
CyMatrix mat = CyMatrixFactory.makeSmallMatrix(10, 2, data);
HopachPAM h = new HopachPAM(mat, DistanceMetric.CITYBLOCK);
Clusters c = h.initLevel();
// check that the clustering results match
for (int i = 0; i < c.size(); ++i) {
assertEquals(c.getClusterIndex(i), ans[i]);
}
}
use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters in project clusterMaker2 by RBVI.
the class HopachPAMTest method testCollapse.
@Test
public void testCollapse() {
// TODO Create a test case that results in a chain of collapses...
Double[] data = { .15, .15, .2, .2, .12, .12, .05, .05, .0, .0, .06, .06, .015, .015, .01, .01, .03, .03, .04, .04, .02, .02 };
int[] initMedoids = { 0, 0, 0, 3, 3, 3, 3, 5, 5, 5, 5 };
int[] ans = { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 };
CyMatrix mat = CyMatrixFactory.makeSmallMatrix(11, 2, data);
HopachPAM h = new HopachPAM(mat, DistanceMetric.CITYBLOCK);
Clusters b = new Clusters(initMedoids);
// b.setCost( MSplitSilhouetteCalculator.medianSplitSilhouette(h.partitioner, b, 9) );
b.setCost(1.0);
h.splits.set(0, b);
Clusters c = h.collapse(0);
// check that the clustering results match
for (int i = 0; i < c.size(); ++i) {
assertEquals(c.getClusterIndex(i), ans[i]);
}
}
use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters in project clusterMaker2 by RBVI.
the class RunHopachPAM method kcluster.
@Override
public int kcluster(int nClusters, int nIterations, CyMatrix matrix, DistanceMetric metric, int[] clusterId) {
monitor.setProgress(0);
Summarizer summarizer;
PrimitiveSummarizer psummarizer;
switch(summaryMethod) {
case MEDIAN:
summarizer = new MedianSummarizer();
psummarizer = new PrimitiveMedianSummarizer();
break;
case MEAN:
default:
summarizer = new MeanSummarizer();
psummarizer = new PrimitiveMeanSummarizer();
break;
}
HopachablePAM partitioner = new HopachablePAM(network, matrix, metric);
partitioner.setParameters(K, L, splitCost, summarizer);
HopachPAM hopachPam = new HopachPAM(partitioner);
hopachPam.setParameters(maxLevel, minCostReduction, forceInitSplit, psummarizer);
Clusters c = hopachPam.run();
// copy results into clusterId
for (int i = 0; i < c.size(); ++i) {
clusterId[i] = c.getClusterIndex(i);
}
return c.getNumberOfClusters();
}
Aggregations