Search in sources :

Example 46 with DoubleArrayList

use of cern.colt.list.DoubleArrayList in project Gemma by PavlidisLab.

the class DoubleVectorValueObject method standardize.

/**
 * @return data adjusted to mean 0, variance 1.
 */
public double[] standardize() {
    /*
         * FIXME If the values are all equal, variance == 0 and we get nothing back. So we should fill in zeros instead.
         */
    /*
         * DoubleArrayList constructor does not make a copy, so we have to make one.
         */
    double[] copy = new double[this.data.length];
    System.arraycopy(data, 0, copy, 0, data.length);
    DescriptiveWithMissing.standardize(new DoubleArrayList(copy));
    return copy;
}
Also used : DoubleArrayList(cern.colt.list.DoubleArrayList)

Example 47 with DoubleArrayList

use of cern.colt.list.DoubleArrayList in project Gemma by PavlidisLab.

the class GeneCoexpressionNodeDegreeValueObject method asDoubleArray.

private double[] asDoubleArray(TreeMap<Integer, Double> map) {
    DoubleArrayList list = new DoubleArrayList();
    if (map.isEmpty())
        return this.toPrimitive(list);
    list.setSize(Math.max(list.size(), map.lastKey() + 1));
    for (Integer s : map.keySet()) {
        list.set(s, map.get(s));
    }
    return this.toPrimitive(list);
}
Also used : DoubleArrayList(cern.colt.list.DoubleArrayList)

Example 48 with DoubleArrayList

use of cern.colt.list.DoubleArrayList in project Gemma by PavlidisLab.

the class ExpressionDataMatrixServiceImpl method getRankMatrix.

@Override
public DoubleMatrix<Gene, ExpressionExperiment> getRankMatrix(Collection<Gene> genes, Collection<ExpressionExperiment> ees, ProcessedExpressionDataVectorDao.RankMethod method) {
    DoubleMatrix<Gene, ExpressionExperiment> matrix = new DenseDoubleMatrix<>(genes.size(), ees.size());
    Map<ExpressionExperiment, Map<Gene, Collection<Double>>> ranks = processedExpressionDataVectorService.getRanks(ees, genes, method);
    matrix.setRowNames(new ArrayList<>(genes));
    matrix.setColumnNames(new ArrayList<>(ees));
    for (int i = 0; i < matrix.rows(); i++) {
        for (int j = 0; j < matrix.columns(); j++) {
            matrix.setByKeys(matrix.getRowName(i), matrix.getColName(j), Double.NaN);
        }
    }
    for (Gene g : matrix.getRowNames()) {
        for (ExpressionExperiment e : matrix.getColNames()) {
            if (ranks.containsKey(e)) {
                Collection<Double> r = ranks.get(e).get(g);
                if (r == null) {
                    continue;
                }
                Double[] ar = r.toArray(new Double[r.size()]);
                // compute median of collection.
                double[] dar = ArrayUtils.toPrimitive(ar);
                double medianRank = DescriptiveWithMissing.median(new DoubleArrayList(dar));
                matrix.setByKeys(g, e, medianRank);
            }
        }
    }
    return matrix;
}
Also used : DoubleArrayList(cern.colt.list.DoubleArrayList) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) Gene(ubic.gemma.model.genome.Gene) DenseDoubleMatrix(ubic.basecode.dataStructure.matrix.DenseDoubleMatrix) Map(java.util.Map)

Example 49 with DoubleArrayList

use of cern.colt.list.DoubleArrayList in project Gemma by PavlidisLab.

the class SpearmanMetricsTest method testCorrel.

/**
 * Value from R; this has ties.
 * <pre>
 * &gt; a&lt;-c(49.0, 43.0, 310.0, 20.0, 20.0, 688.0, 498.0, 533.0, 723.0, 1409.0,279.0);
 * &gt; b&lt;-c(1545.0, 1287.0, 2072.0, 1113.0, 676.0, 2648.0, 2478.0, 2574.0, 3554.0,5155.0, 1624.0);
 * &gt; cor(a,b, method=&quot;spearman&quot;);
 * [1] 0.9977247
 * </pre>
 */
@Test
public void testCorrel() {
    // note the nominal tie in one (20)
    double[] a = new double[] { 49.0, 43.0, 310.0, 20.0, 20.0, 688.0, 498.0, 533.0, 723.0, 1409.0, 279.0 };
    double[] b = new double[] { 1545.0, 1287.0, 2072.0, 1113.0, 676.0, 2648.0, 2478.0, 2574.0, 3554.0, 5155.0, 1624.0 };
    boolean[] usedA = new boolean[] { true, true, true, true, true, true, true, true, true, true, true };
    boolean[] usedB = new boolean[] { true, true, true, true, true, true, true, true, true, true, true };
    assertEquals(a.length, usedA.length);
    assertEquals(b.length, usedB.length);
    DoubleArrayList ranksIA = Rank.rankTransform(new DoubleArrayList(a));
    DoubleArrayList ranksIB = Rank.rankTransform(new DoubleArrayList(b));
    SpearmanMetrics test = new SpearmanMetrics(10);
    double actualValue = test.spearman(ranksIA.elements(), ranksIB.elements(), usedA, usedB, 0, 1);
    double expectedValue = 0.9977247;
    assertEquals(expectedValue, actualValue, 0.0001);
}
Also used : DoubleArrayList(cern.colt.list.DoubleArrayList) Test(org.junit.Test)

Example 50 with DoubleArrayList

use of cern.colt.list.DoubleArrayList in project Gemma by PavlidisLab.

the class SpearmanMetricsTest method testCorrelC.

/**
 * Without missing values, fast method (same data as testCorrelB)
 */
@Test
public void testCorrelC() {
    double[] a = new double[] { 400, 310, 20, 20, 688, 498, 533, 1409, 1500 };
    double[] b = new double[] { 1545, 2072, 1113, 676, 2648, 2478, 2574, 5155, 1624 };
    assertEquals(a.length, b.length);
    DoubleArrayList ranksIA = Rank.rankTransform(new DoubleArrayList(a));
    DoubleArrayList ranksIB = Rank.rankTransform(new DoubleArrayList(b));
    SpearmanMetrics test = new SpearmanMetrics(10);
    double actualValue = test.correlFast(ranksIA.elements(), ranksIB.elements(), 7.713624, 7.745967, 5, 5);
    double expectedValue = 0.7113033;
    assertEquals(expectedValue, actualValue, 0.0001);
}
Also used : DoubleArrayList(cern.colt.list.DoubleArrayList) Test(org.junit.Test)

Aggregations

DoubleArrayList (cern.colt.list.DoubleArrayList)82 RegressionResult (edu.cmu.tetrad.regression.RegressionResult)11 ArrayList (java.util.ArrayList)9 AndersonDarlingTest (edu.cmu.tetrad.data.AndersonDarlingTest)8 IntArrayList (cern.colt.list.IntArrayList)6 DenseDoubleMatrix2D (cern.colt.matrix.impl.DenseDoubleMatrix2D)5 TetradVector (edu.cmu.tetrad.util.TetradVector)5 Test (org.junit.Test)5 DoubleMatrix2D (cern.colt.matrix.DoubleMatrix2D)4 TetradMatrix (edu.cmu.tetrad.util.TetradMatrix)4 DoubleMatrix1D (cern.colt.matrix.DoubleMatrix1D)3 DenseDoubleMatrix1D (cern.colt.matrix.impl.DenseDoubleMatrix1D)3 Regression (edu.cmu.tetrad.regression.Regression)3 RegressionDataset (edu.cmu.tetrad.regression.RegressionDataset)3 StopWatch (org.apache.commons.lang3.time.StopWatch)2 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)2 Record (org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record)2 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)2 BlockLocation (org.onebusaway.transit_data_federation.services.realtime.BlockLocation)2 ByteArrayConverter (ubic.basecode.io.ByteArrayConverter)2