use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.numeric.MedianSummarizer in project clusterMaker2 by RBVI.
the class HopachablePAMTest method testSplit.
@Test
public void testSplit() {
Double[] data = { .2, .2, .8, .8, .82, .82, .4, .5, .5, .4, .15, .15, .81, .81, .14, .14, .45, .45 };
int k = 3;
int[] ans = { 0, 1, 1, 2, 2, 0, 1, 0, 2 };
CyMatrix mat = CyMatrixFactory.makeSmallMatrix(9, 2, data);
HopachablePAM pam = new HopachablePAM(null, mat, DistanceMetric.CITYBLOCK);
pam.setParameters(9, 9, SplitCost.AVERAGE_SPLIT_SILHOUETTE, new MedianSummarizer());
Clusters c = pam.split(false);
// check that data are split into expected number of clusters
assertEquals(c.getNumberOfClusters(), k);
// check cluster assignments
for (int i = 0; i < c.size(); ++i) {
assertEquals(c.getClusterIndex(i), ans[i]);
}
}
use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.numeric.MedianSummarizer 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