Search in sources :

Example 21 with DoubleMatrix2D

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

the class ColtOps method multiplyMatrix.

// For some reason, the parallelcolt version of zMult doesn't
// really take advantage of the available cores.  This version does, but
// it seems like it only works for multiplying matrices of the same
// size.
public Matrix multiplyMatrix(Matrix matrix2) {
    // return mult(matrix);
    // if (matrix2.nRows() != matrix.nRows() || matrix2.nColumns() != matrix.nColumns()())
    // return mult(matrix);
    DoubleMatrix2D A = getData();
    DoubleMatrix2D B = matrix2.getColtMatrix();
    int m = A.rows();
    int n = A.columns();
    int p = B.columns();
    // Create views into B
    final DoubleMatrix1D[] Brows = new DoubleMatrix1D[n];
    for (int i = n; --i >= 0; ) Brows[i] = B.viewRow(i);
    // Create a series of 1D vectors
    final DoubleMatrix1D[] Crows = new DoubleMatrix1D[m];
    for (int i = m; --i >= 0; ) Crows[i] = B.like1D(p);
    // Create the thread pools
    final ExecutorService[] threadPools = new ExecutorService[nThreads];
    for (int pool = 0; pool < threadPools.length; pool++) {
        threadPools[pool] = Executors.newFixedThreadPool(1);
    }
    A.forEachNonZero(new IntIntDoubleFunction() {

        public double apply(int row, int column, double value) {
            Runnable r = new ThreadedDotProduct(value, Brows[column], Crows[row]);
            threadPools[row % nThreads].submit(r);
            return value;
        }
    });
    for (int pool = 0; pool < threadPools.length; pool++) {
        threadPools[pool].shutdown();
        try {
            boolean result = threadPools[pool].awaitTermination(7, TimeUnit.DAYS);
        } catch (Exception e) {
        }
    }
    // Recreate C
    return new ColtMatrix(matrix, create2DMatrix(Crows));
}
Also used : IntIntDoubleFunction(cern.colt.function.tdouble.IntIntDoubleFunction) DoubleMatrix2D(cern.colt.matrix.tdouble.DoubleMatrix2D) DoubleMatrix1D(cern.colt.matrix.tdouble.DoubleMatrix1D) ExecutorService(java.util.concurrent.ExecutorService)

Example 22 with DoubleMatrix2D

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

the class ColtOps method addElement.

/**
 * add two matrices together
 *
 * @param addend the matrix to add to our matrix
 */
public void addElement(Matrix addend) {
    DoubleMatrix2D data = getData();
    data.forEachNonZero(new IntIntDoubleFunction() {

        public double apply(int row, int column, double v) {
            double addendValue = addend.doubleValue(row, column);
            if (!Double.isNaN(addendValue))
                return v + addendValue;
            else
                return v;
        }
    });
}
Also used : IntIntDoubleFunction(cern.colt.function.tdouble.IntIntDoubleFunction) DoubleMatrix2D(cern.colt.matrix.tdouble.DoubleMatrix2D)

Example 23 with DoubleMatrix2D

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

the class ColtOps method powScalar.

/**
 * raise all cells in the matrix by a power
 *
 * @param matrix our matrix
 * @param value power to raise to each cell
 */
public void powScalar(double value) {
    DoubleMatrix2D data = getData();
    data.forEachNonZero(new IntIntDoubleFunction() {

        public double apply(int row, int column, double v) {
            return Math.pow(v, value);
        }
    });
}
Also used : IntIntDoubleFunction(cern.colt.function.tdouble.IntIntDoubleFunction) DoubleMatrix2D(cern.colt.matrix.tdouble.DoubleMatrix2D)

Example 24 with DoubleMatrix2D

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

the class ColtOps method create2DMatrix.

private DoubleMatrix2D create2DMatrix(DoubleMatrix1D[] rows) {
    int columns = (int) rows[0].size();
    DoubleMatrix2D C = DoubleFactory2D.sparse.make(rows.length, columns);
    for (int row = 0; row < rows.length; row++) {
        for (int col = 0; col < columns; col++) {
            double value = rows[row].getQuick(col);
            if (value != 0.0)
                C.setQuick(row, col, value);
        }
    }
    return C;
}
Also used : DoubleMatrix2D(cern.colt.matrix.tdouble.DoubleMatrix2D)

Example 25 with DoubleMatrix2D

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

the class ColtOps method mult.

public Matrix mult(Matrix b) {
    /*
		DoubleMatrix2D aMat = data;
		DoubleMatrix2D bMat = b.getColtMatrix();
		DoubleMatrix2D cMat = DoubleFactory2D.sparse.make(nRows, nColumns);
		// System.out.println("aMat ("+aMat.rows()+", "+aMat.columns()+")");
		// System.out.println("bMat ("+bMat.rows()+", "+bMat.columns()+")");
		// System.out.println("cMat ("+cMat.rows()+", "+cMat.columns()+")");
		blas.dgemm(false, false, 1.0, aMat, bMat, 0.0, cMat);
		ColtMatrix c = new ColtMatrix(this, cMat);
		*/
    DoubleMatrix2D cMat;
    if (getData().getClass().getName().indexOf("Sparse") >= 0)
        cMat = DoubleFactory2D.sparse.make(matrix.nRows(), b.nColumns());
    else
        cMat = DoubleFactory2D.dense.make(matrix.nRows(), b.nColumns());
    getData().zMult(b.getColtMatrix(), cMat);
    ColtMatrix c = new ColtMatrix(matrix, cMat);
    return c;
}
Also used : DoubleMatrix2D(cern.colt.matrix.tdouble.DoubleMatrix2D)

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