Search in sources :

Example 51 with CyMatrix

use of edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix 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]);
    }
}
Also used : CyMatrix(edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix) Clusters(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters) Test(org.junit.Test)

Example 52 with CyMatrix

use of edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix 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]);
    }
}
Also used : CyMatrix(edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix) Clusters(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters) Test(org.junit.Test)

Example 53 with CyMatrix

use of edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix 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();
}
Also used : PrimitiveMeanSummarizer(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.numeric.PrimitiveMeanSummarizer) MeanSummarizer(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.numeric.MeanSummarizer) PrimitiveMeanSummarizer(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.numeric.PrimitiveMeanSummarizer) PrimitiveSummarizer(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.numeric.PrimitiveSummarizer) PrimitiveMedianSummarizer(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.numeric.PrimitiveMedianSummarizer) Clusters(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters) HopachablePAM(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.pam.HopachablePAM) PrimitiveMeanSummarizer(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.numeric.PrimitiveMeanSummarizer) MedianSummarizer(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.numeric.MedianSummarizer) PrimitiveSummarizer(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.numeric.PrimitiveSummarizer) MeanSummarizer(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.numeric.MeanSummarizer) PrimitiveMedianSummarizer(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.numeric.PrimitiveMedianSummarizer) Summarizer(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.numeric.Summarizer) MedianSummarizer(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.numeric.MedianSummarizer) PrimitiveMedianSummarizer(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.numeric.PrimitiveMedianSummarizer)

Aggregations

CyMatrix (edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix)47 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)13 CyNode (org.cytoscape.model.CyNode)13 Clusters (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters)11 NodeCluster (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster)10 Test (org.junit.Test)10 Matrix (edu.ucsf.rbvi.clusterMaker2.internal.api.Matrix)9 List (java.util.List)8 AbstractClusterResults (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults)6 NewNetworkView (edu.ucsf.rbvi.clusterMaker2.internal.ui.NewNetworkView)6 FuzzyNodeCluster (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.FuzzyNodeCluster)4 CyTable (org.cytoscape.model.CyTable)4 ColtMatrix (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.matrix.ColtMatrix)3 BiclusterView (edu.ucsf.rbvi.clusterMaker2.internal.ui.BiclusterView)3 Map (java.util.Map)3 CyNetwork (org.cytoscape.model.CyNetwork)3 MedianSummarizer (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.numeric.MedianSummarizer)2 ScatterPlotDialog (edu.ucsf.rbvi.clusterMaker2.internal.ui.ScatterPlotDialog)2 CyEdge (org.cytoscape.model.CyEdge)2