Search in sources :

Example 16 with DoubleMatrix2D

use of cern.colt.matrix.tdouble.DoubleMatrix2D in project clusterMaker2 by RBVI.

the class RunSCPS method getSMat.

// Get Connected Components, cluster all components <= |5|, and connect the remaining components with random lowscoring edges
public DoubleMatrix2D getSMat(CyMatrix distanceMatrix) {
    // Matrix prior to filtration modification
    DoubleMatrix2D unfiltered_mat = distanceMatrix.getColtMatrix();
    // Size of newly created Umat after filtering of small components
    int sMat_rows = 0;
    HashMap<Integer, List<CyNode>> filtered_cmap = new HashMap<Integer, List<CyNode>>();
    // Connected Componets
    Map<Integer, List<CyNode>> cMap = MatrixUtils.findConnectedComponents(distanceMatrix);
    IntArrayList rowList = new IntArrayList();
    IntArrayList columnList = new IntArrayList();
    DoubleArrayList valueList = new DoubleArrayList();
    // Iterate through connected components
    int component_size_sum = 0;
    for (List<CyNode> component : cMap.values()) {
        numComponents += 1;
        // Size <= 5. Automatically create cluster and increment clusterCount.
        if (component.size() <= 5) {
            NodeCluster iCluster = new NodeCluster(component);
            iCluster.setClusterNumber(this.clusterCount);
            // iCluster.add(component,this.clusterCount);
            this.clusterMap.put(new Integer(clusterCount), iCluster);
            this.clusterCount++;
        } else {
            // iterate through components and assign them index mappings in new uMatrix
            component_size_sum += component.size();
            System.out.println("Normal Component size " + component.size() + " Total Sum " + component_size_sum);
            for (int i = 0; i < component.size(); i++) {
                CyNode n = component.get(i);
                int node_id = this.nodes.indexOf(n);
                // set mapping of new matrix index to old index
                setMap(node_id, sMat_rows);
                sMat_rows++;
            }
        }
    }
    DoubleMatrix2D sMat = DoubleFactory2D.sparse.make(sMat_rows, sMat_rows);
    // set diagnols of sMat to one
    for (int i = 0; i < sMat_rows; i++) sMat.set(i, i, 1);
    // iterate through nonzero edges. If both nodes in new index map, transfer the edge to new matrix
    unfiltered_mat.getNonZeros(rowList, columnList, valueList);
    for (int i = 0; i < rowList.size(); i++) {
        int row_id = rowList.get(i);
        int column_id = columnList.get(i);
        int new_row_id = getMap_new(row_id);
        int new_column_id = getMap_new(column_id);
        double value = valueList.get(i);
        // Set symmetrically the values in new matrix
        if (new_row_id > -1 && new_column_id > -1) {
            sMat.set(new_row_id, new_column_id, value);
            sMat.set(new_column_id, new_row_id, value);
        }
    }
    return sMat;
}
Also used : HashMap(java.util.HashMap) DoubleArrayList(cern.colt.list.tdouble.DoubleArrayList) NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster) DoubleMatrix2D(cern.colt.matrix.tdouble.DoubleMatrix2D) DoubleArrayList(cern.colt.list.tdouble.DoubleArrayList) IntArrayList(cern.colt.list.tint.IntArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CyNode(org.cytoscape.model.CyNode) IntArrayList(cern.colt.list.tint.IntArrayList)

Example 17 with DoubleMatrix2D

use of cern.colt.matrix.tdouble.DoubleMatrix2D in project clusterMaker2 by RBVI.

the class OjAlgoMatrix method getColtMatrix.

public DoubleMatrix2D getColtMatrix() {
    DoubleMatrix2D mat = DoubleFactory2D.dense.make(nRows, nColumns);
    mat.assign(toArray());
    return mat;
}
Also used : DoubleMatrix2D(cern.colt.matrix.tdouble.DoubleMatrix2D)

Example 18 with DoubleMatrix2D

use of cern.colt.matrix.tdouble.DoubleMatrix2D in project clusterMaker2 by RBVI.

the class SimpleMatrix method getColtMatrix.

public DoubleMatrix2D getColtMatrix() {
    DoubleMatrix2D mat = DoubleFactory2D.dense.make(nRows, nColumns);
    mat.assign(toArray());
    return mat;
}
Also used : DoubleMatrix2D(cern.colt.matrix.tdouble.DoubleMatrix2D)

Example 19 with DoubleMatrix2D

use of cern.colt.matrix.tdouble.DoubleMatrix2D in project IR_Base by Linda-sunshine.

the class GaussianFields method test.

// Test the data set.
@Override
public double test() {
    _Node node;
    /**
     *Construct the nearest neighbor graph***
     */
    constructGraph(true);
    /**
     *Perform matrix inverse.***
     */
    DenseDoubleAlgebra alg = new DenseDoubleAlgebra();
    DoubleMatrix2D result = alg.inverse(m_graph);
    /**
     *setting up the corresponding weight for the true labels**
     */
    for (int i = m_U; i < m_L + m_U; i++) m_nodeList[i].m_classifierPred *= m_M;
    /**
     *get some statistics**
     */
    for (int i = 0; i < m_U; i++) {
        node = m_nodeList[i];
        double pred = 0;
        for (int j = 0; j < m_U + m_L; j++) pred += result.getQuick(i, j) * m_nodeList[j].m_label;
        // prediction for the unlabeled based on the labeled data and pseudo labels
        node.m_pred = pred;
        for (int j = 0; j < m_classNo; j++) m_pYSum[j] += Math.exp(-Math.abs(j - node.m_pred));
    }
    /**
     *evaluate the performance**
     */
    double acc = 0;
    int pred, ans;
    for (int i = 0; i < m_U; i++) {
        pred = getLabel(m_nodeList[i].m_pred);
        ans = m_testSet.get(i).getYLabel();
        m_TPTable[pred][ans] += 1;
        if (pred != ans) {
            if (m_debugOutput != null)
                debug(m_testSet.get(i));
        } else
            acc++;
    }
    m_precisionsRecalls.add(calculatePreRec(m_TPTable));
    return acc / m_U;
}
Also used : DenseDoubleAlgebra(cern.colt.matrix.tdouble.algo.DenseDoubleAlgebra) DoubleMatrix2D(cern.colt.matrix.tdouble.DoubleMatrix2D) SparseDoubleMatrix2D(cern.colt.matrix.tdouble.impl.SparseDoubleMatrix2D) structures._Node(structures._Node)

Example 20 with DoubleMatrix2D

use of cern.colt.matrix.tdouble.DoubleMatrix2D in project clusterMaker2 by RBVI.

the class RunSCPS method run.

public List<NodeCluster> run(CyNetwork network, TaskMonitor monitor) {
    int k;
    monitor.showMessage(TaskMonitor.Level.INFO, "Formatting Matrix Data");
    DoubleMatrix2D sMat = getSMat(this.distanceMatrix);
    DoubleMatrix2D LMat = getLMat(sMat);
    monitor.showMessage(TaskMonitor.Level.INFO, "Calculating Eigenvalues");
    DenseDoubleEigenvalueDecomposition decomp = new DenseDoubleEigenvalueDecomposition(LMat);
    DoubleMatrix2D eigenVect = decomp.getV();
    DoubleMatrix1D eigenVal = decomp.getRealEigenvalues();
    monitor.showMessage(TaskMonitor.Level.INFO, "Calculating K value");
    if (this.kvalue > -1)
        k = this.kvalue;
    else
        k = getK(eigenVal, .3);
    System.out.println("K is " + k);
    if (numComponents > k) {
        doComponentClustering();
        return new ArrayList<NodeCluster>(this.clusterMap.values());
    }
    monitor.showMessage(TaskMonitor.Level.INFO, "Creating uMatrix for kMeans");
    DoubleMatrix2D uMat = getUMat(eigenVect, k);
    monitor.showMessage(TaskMonitor.Level.INFO, "Running kmeans clustering");
    doKMeansClustering(uMat, sMat);
    // clusterMap calculated in getSMat and doKMeansClustering steps. Simply return the results
    return new ArrayList<NodeCluster>(this.clusterMap.values());
}
Also used : DoubleMatrix2D(cern.colt.matrix.tdouble.DoubleMatrix2D) DenseDoubleEigenvalueDecomposition(cern.colt.matrix.tdouble.algo.decomposition.DenseDoubleEigenvalueDecomposition) DoubleMatrix1D(cern.colt.matrix.tdouble.DoubleMatrix1D) DoubleArrayList(cern.colt.list.tdouble.DoubleArrayList) IntArrayList(cern.colt.list.tint.IntArrayList) ArrayList(java.util.ArrayList)

Aggregations

DoubleMatrix2D (cern.colt.matrix.tdouble.DoubleMatrix2D)30 IntIntDoubleFunction (cern.colt.function.tdouble.IntIntDoubleFunction)8 DenseDoubleAlgebra (cern.colt.matrix.tdouble.algo.DenseDoubleAlgebra)5 DoubleArrayList (cern.colt.list.tdouble.DoubleArrayList)3 IntArrayList (cern.colt.list.tint.IntArrayList)3 DoubleMatrix1D (cern.colt.matrix.tdouble.DoubleMatrix1D)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 CyNode (org.cytoscape.model.CyNode)3 DenseDoubleEigenvalueDecomposition (cern.colt.matrix.tdouble.algo.decomposition.DenseDoubleEigenvalueDecomposition)2 NodeCluster (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster)2 DenseDoubleSingularValueDecomposition (cern.colt.matrix.tdouble.algo.decomposition.DenseDoubleSingularValueDecomposition)1 SparseDoubleMatrix2D (cern.colt.matrix.tdouble.impl.SparseDoubleMatrix2D)1 Edges (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.costmatrixcreation.dataTypes.Edges)1 IteratorThread (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.iterativeclustering.IteratorThread)1 List (java.util.List)1 ExecutorService (java.util.concurrent.ExecutorService)1 Semaphore (java.util.concurrent.Semaphore)1 structures._Node (structures._Node)1