Search in sources :

Example 66 with Clusters

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;
}
Also used : Clusters(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters)

Example 67 with Clusters

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

Example 68 with Clusters

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

Example 69 with Clusters

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

Example 70 with Clusters

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();
}
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

ArrayList (java.util.ArrayList)30 NodeCluster (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster)27 CyMatrix (edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix)22 Clusters (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters)21 AbstractClusterResults (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults)16 HashMap (java.util.HashMap)16 List (java.util.List)15 CyNode (org.cytoscape.model.CyNode)13 NewNetworkView (edu.ucsf.rbvi.clusterMaker2.internal.ui.NewNetworkView)10 Test (org.junit.Test)9 FuzzyNodeCluster (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.FuzzyNodeCluster)8 ConnectedComponent (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.datastructure.ConnectedComponent)6 Random (java.util.Random)5 Vector (java.util.Vector)5 Semaphore (java.util.concurrent.Semaphore)5 Edges (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.costmatrixcreation.dataTypes.Edges)3 ICCEdges (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.datastructure.ICCEdges)3 IParameters (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.layout.IParameters)3 ClusteringManager (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.ClusteringManager)3 PREdge (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.ranking.units.PREdge)3