Search in sources :

Example 46 with DoubleMatrix2D

use of cern.colt.matrix.DoubleMatrix2D in project tdq-studio-se by Talend.

the class Statistic method demo3.

/**
 * Demonstrates usage of this class.
 */
public static void demo3(VectorVectorFunction norm) {
    double[][] values = { { -0.9611052, -0.25421095 }, { 0.4308269, -0.69932648 }, { -1.2071029, 0.62030596 }, { 1.5345166, 0.02135884 }, { -1.1341542, 0.20388430 } };
    System.out.println("\n\ninitializing...");
    DoubleFactory2D factory = DoubleFactory2D.dense;
    DoubleMatrix2D A = factory.make(values).viewDice();
    System.out.println("\nA=" + A.viewDice());
    System.out.println("\ndist=" + distance(A, norm).viewDice());
}
Also used : DoubleMatrix2D(cern.colt.matrix.DoubleMatrix2D) DoubleFactory2D(cern.colt.matrix.DoubleFactory2D)

Example 47 with DoubleMatrix2D

use of cern.colt.matrix.DoubleMatrix2D in project tdq-studio-se by Talend.

the class Stencil method stencil9.

/**
 *9 point stencil operation.
 *Applies a function to a moving <tt>3 x 3</tt> window.
 *@param A the matrix to operate on.
 *@param function the function to be applied to each window.
 *@param maxIterations the maximum number of times the stencil shall be applied to the matrix.
 *	Should be a multiple of 2 because two iterations are always done in one atomic step.
 *@param hasConverged Convergence condition; will return before maxIterations are done when <tt>hasConverged.apply(A)==true</tt>.
 *	Set this parameter to <tt>null</tt> to indicate that no convergence checks shall be made.
 *@param convergenceIterations the number of iterations to pass between each convergence check.
 *	(Since a convergence may be expensive, you may want to do it only every 2,4 or 8 iterations.)
 *@return the number of iterations actually executed.
 */
public static int stencil9(DoubleMatrix2D A, cern.colt.function.Double9Function function, int maxIterations, DoubleMatrix2DProcedure hasConverged, int convergenceIterations) {
    DoubleMatrix2D B = A.copy();
    if (convergenceIterations <= 1)
        convergenceIterations = 2;
    // odd -> make it even
    if (convergenceIterations % 2 != 0)
        convergenceIterations++;
    int i = 0;
    while (i < maxIterations) {
        // do two steps at a time for efficiency
        A.zAssign8Neighbors(B, function);
        B.zAssign8Neighbors(A, function);
        i = i + 2;
        if (i % convergenceIterations == 0 && hasConverged != null) {
            if (hasConverged.apply(A))
                return i;
        }
    }
    return i;
}
Also used : DoubleMatrix2D(cern.colt.matrix.DoubleMatrix2D)

Example 48 with DoubleMatrix2D

use of cern.colt.matrix.DoubleMatrix2D in project Gemma by PavlidisLab.

the class MeanVarianceServiceImpl method calculateMeanVariance.

/**
 * @param matrix on which mean variance relation is computed with
 * @param mvr    object, if null, a new object is created
 * @return MeanVarianceRelation object
 */
private MeanVarianceRelation calculateMeanVariance(ExpressionDataDoubleMatrix matrix, MeanVarianceRelation mvr) {
    if (matrix == null) {
        log.warn("Experiment matrix is null");
        return null;
    }
    DoubleMatrix2D mat = new DenseDoubleMatrix2D(matrix.rows(), matrix.columns());
    for (int row = 0; row < mat.rows(); row++) {
        mat.viewRow(row).assign(matrix.getRawRow(row));
    }
    MeanVarianceEstimator mve = new MeanVarianceEstimator(mat);
    if (mvr == null) {
        mvr = MeanVarianceRelation.Factory.newInstance();
    }
    if (mve.getMeanVariance() != null) {
        mvr.setMeans(bac.doubleArrayToBytes(mve.getMeanVariance().viewColumn(0).toArray()));
        mvr.setVariances(bac.doubleArrayToBytes(mve.getMeanVariance().viewColumn(1).toArray()));
    }
    return mvr;
}
Also used : MeanVarianceEstimator(ubic.basecode.math.linearmodels.MeanVarianceEstimator) DoubleMatrix2D(cern.colt.matrix.DoubleMatrix2D) DenseDoubleMatrix2D(cern.colt.matrix.impl.DenseDoubleMatrix2D) DenseDoubleMatrix2D(cern.colt.matrix.impl.DenseDoubleMatrix2D)

Example 49 with DoubleMatrix2D

use of cern.colt.matrix.DoubleMatrix2D in project Gemma by PavlidisLab.

the class ExpressionDataSVD method equalize.

/**
 * Implements the method described in the SPELL paper, alternative interpretation as related by Q. Morris. Set all
 * components to have equal weight (set all singular values to 1)
 *
 * @return the reconstructed matrix; values that were missing before are re-masked.
 */
public ExpressionDataDoubleMatrix equalize() {
    DoubleMatrix<Integer, Integer> copy = svd.getS().copy();
    for (int i = 0; i < copy.columns(); i++) {
        copy.set(i, i, 1.0);
    }
    double[][] rawU = svd.getU().getRawMatrix();
    double[][] rawS = copy.getRawMatrix();
    double[][] rawV = svd.getV().getRawMatrix();
    DoubleMatrix2D u = new DenseDoubleMatrix2D(rawU);
    DoubleMatrix2D s = new DenseDoubleMatrix2D(rawS);
    DoubleMatrix2D v = new DenseDoubleMatrix2D(rawV);
    Algebra a = new Algebra();
    DoubleMatrix<CompositeSequence, BioMaterial> reconstructed = new DenseDoubleMatrix<>(a.mult(a.mult(u, s), a.transpose(v)).toArray());
    reconstructed.setRowNames(this.expressionData.getMatrix().getRowNames());
    reconstructed.setColumnNames(this.expressionData.getMatrix().getColNames());
    // re-mask the missing values.
    for (int i = 0; i < reconstructed.rows(); i++) {
        for (int j = 0; j < reconstructed.columns(); j++) {
            if (Double.isNaN(this.missingValueInfo.get(i, j))) {
                reconstructed.set(i, j, Double.NaN);
            }
        }
    }
    return new ExpressionDataDoubleMatrix(this.expressionData, reconstructed);
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) Algebra(cern.colt.matrix.linalg.Algebra) DoubleMatrix2D(cern.colt.matrix.DoubleMatrix2D) DenseDoubleMatrix2D(cern.colt.matrix.impl.DenseDoubleMatrix2D) ExpressionDataDoubleMatrix(ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix) DenseDoubleMatrix(ubic.basecode.dataStructure.matrix.DenseDoubleMatrix) DenseDoubleMatrix2D(cern.colt.matrix.impl.DenseDoubleMatrix2D) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence)

Example 50 with DoubleMatrix2D

use of cern.colt.matrix.DoubleMatrix2D in project Gemma by PavlidisLab.

the class ComBat method getBatchData.

/**
 * @param sdata   data to be sliced
 * @param batchId which batch
 */
private DoubleMatrix2D getBatchData(DoubleMatrix2D sdata, String batchId) {
    Collection<C> sampleNames = batches.get(batchId);
    DoubleMatrix2D result = new DenseDoubleMatrix2D(sdata.rows(), sampleNames.size());
    int i = 0;
    for (C sname : sampleNames) {
        DoubleMatrix1D colInBatch = sdata.viewColumn(data.getColIndexByName(sname));
        for (int k = 0; k < colInBatch.size(); k++) {
            result.set(k, i, colInBatch.get(k));
        }
        i++;
    }
    // log.info( result );
    return result;
}
Also used : DoubleMatrix2D(cern.colt.matrix.DoubleMatrix2D) DenseDoubleMatrix2D(cern.colt.matrix.impl.DenseDoubleMatrix2D) DoubleMatrix1D(cern.colt.matrix.DoubleMatrix1D) DenseDoubleMatrix1D(cern.colt.matrix.impl.DenseDoubleMatrix1D) DenseDoubleMatrix2D(cern.colt.matrix.impl.DenseDoubleMatrix2D)

Aggregations

DoubleMatrix2D (cern.colt.matrix.DoubleMatrix2D)136 DenseDoubleMatrix2D (cern.colt.matrix.impl.DenseDoubleMatrix2D)38 DoubleMatrix1D (cern.colt.matrix.DoubleMatrix1D)36 Algebra (cern.colt.matrix.linalg.Algebra)16 DoubleFactory2D (cern.colt.matrix.DoubleFactory2D)13 DenseDoubleMatrix1D (cern.colt.matrix.impl.DenseDoubleMatrix1D)13 Node (edu.cmu.tetrad.graph.Node)11 Graph (edu.cmu.tetrad.graph.Graph)8 Test (org.junit.Test)6 DoubleMatrixReader (ubic.basecode.io.reader.DoubleMatrixReader)6 StringMatrixReader (ubic.basecode.io.reader.StringMatrixReader)6 DataSet (edu.cmu.tetrad.data.DataSet)5 DoubleArrayList (cern.colt.list.DoubleArrayList)4 TetradMatrix (edu.cmu.tetrad.util.TetradMatrix)4 DenseDoubleMatrix (ubic.basecode.dataStructure.matrix.DenseDoubleMatrix)4 AbstractFormatter (cern.colt.matrix.impl.AbstractFormatter)3 Endpoint (edu.cmu.tetrad.graph.Endpoint)3 ExpressionDataDoubleMatrix (ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix)3 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)3 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)3