Search in sources :

Example 51 with DoubleArrayList

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

the class SpearmanMetricsTest method testCorrelWithMissing.

/**
 * See testCorrelB for the same numbers tested a different way (with no missing values)
 */
@Test
public void testCorrelWithMissing() {
    // note the nominal tie in one (20)
    double[] a = new double[] { 400, 43, 310, 20, 20, 688, 498, 533, 723, 1409, 1500 };
    double[] b = new double[] { 1545, 1287, 2072, 1113, 676, 2648, 2478, 2574, 3554, 5155, 1624 };
    boolean[] usedA = new boolean[] { true, false, true, true, true, true, true, true, false, true, true };
    boolean[] usedB = new boolean[] { true, true, true, true, true, true, true, true, false, true, true };
    assertEquals(a.length, b.length);
    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.7113033;
    assertEquals(expectedValue, actualValue, 0.0001);
}
Also used : DoubleArrayList(cern.colt.list.DoubleArrayList) Test(org.junit.Test)

Example 52 with DoubleArrayList

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

the class CoexpressionServiceImpl method computeRelativeRanks.

private Map<Long, List<Double>> computeRelativeRanks(TreeMap<Integer, Map<Long, Integer>> forRanks) {
    Map<Long, List<Double>> relRanks = new HashMap<>();
    for (Integer support : forRanks.keySet()) {
        // low ranks = low node degree = good.
        Map<Long, Double> rt = Rank.rankTransform(forRanks.get(support));
        double max = DescriptiveWithMissing.max(new DoubleArrayList(ArrayUtils.toPrimitive(new ArrayList<>(rt.values()).toArray(new Double[] {}))));
        for (Long g : rt.keySet()) {
            double relRank = rt.get(g) / max;
            if (!relRanks.containsKey(g)) {
                relRanks.put(g, new ArrayList<Double>());
            }
            // the ranks are in order.
            relRanks.get(g).add(relRank);
        }
    }
    return relRanks;
}
Also used : DoubleArrayList(cern.colt.list.DoubleArrayList) DoubleArrayList(cern.colt.list.DoubleArrayList) DoubleArrayList(cern.colt.list.DoubleArrayList)

Example 53 with DoubleArrayList

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

the class ExpressionExperimentQCController method removeMVOutliers.

/**
 * Remove outliers from the MeanVarianceRelation by removing those points which have: (zscore(mean) > zscoreMax ||
 * zscore(variance) > zscoreMax)
 */
@SuppressWarnings("unused")
private MeanVarianceRelation removeMVOutliers(MeanVarianceRelation mvr, double zscoreMax) {
    MeanVarianceRelation ret = MeanVarianceRelation.Factory.newInstance();
    ByteArrayConverter bac = new ByteArrayConverter();
    DoubleArrayList vars = new DoubleArrayList(bac.byteArrayToDoubles(mvr.getVariances()));
    DoubleArrayList means = new DoubleArrayList(bac.byteArrayToDoubles(mvr.getMeans()));
    DoubleArrayList filteredMeans = new DoubleArrayList();
    DoubleArrayList filteredVars = new DoubleArrayList();
    DoubleArrayList zVars = this.zscore(vars);
    DoubleArrayList zMeans = this.zscore(means);
    // clip outliers
    for (int i = 0; i < zMeans.size(); i++) {
        if (Math.abs(zMeans.getQuick(i)) > zscoreMax || Math.abs(zVars.getQuick(i)) > zscoreMax) {
            continue;
        }
        filteredMeans.add(means.getQuick(i));
        filteredVars.add(vars.getQuick(i));
    }
    log.debug(filteredMeans.size() + " (out of " + means.size() + ") MV points had mean or variance zscore < " + zscoreMax + ". Max mean,variance is ( " + Descriptive.max(filteredMeans) + "," + Descriptive.max(filteredVars) + ").");
    ret.setVariances(bac.doubleArrayToBytes(filteredVars));
    ret.setMeans(bac.doubleArrayToBytes(filteredMeans));
    return ret;
}
Also used : ByteArrayConverter(ubic.basecode.io.ByteArrayConverter) MeanVarianceRelation(ubic.gemma.model.expression.bioAssayData.MeanVarianceRelation) DoubleArrayList(cern.colt.list.DoubleArrayList)

Example 54 with DoubleArrayList

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

the class ExpressionExperimentQCController method zscore.

/**
 * @return zscores
 */
private DoubleArrayList zscore(DoubleArrayList d) {
    DoubleArrayList z = new DoubleArrayList();
    double mean = Descriptive.mean(d);
    double sd = Descriptive.standardDeviation(Descriptive.variance(d.size(), Descriptive.sum(d), Descriptive.sumOfSquares(d)));
    for (int i = 0; i < d.size(); i++) {
        z.add(Math.abs(d.getQuick(i) - mean) / sd);
    }
    assert z.size() == d.size();
    return z;
}
Also used : DoubleArrayList(cern.colt.list.DoubleArrayList)

Example 55 with DoubleArrayList

use of cern.colt.list.DoubleArrayList in project tdq-studio-se by Talend.

the class AbstractDoubleIntMap method keys.

/**
 * Returns a list filled with all keys contained in the receiver.
 * The returned list has a size that equals <tt>this.size()</tt>.
 * Note: Keys are filled into the list in no particular order.
 * However, the order is <i>identical</i> to the order used by method {@link #forEachKey(DoubleProcedure)}.
 * <p>
 * This method can be used to iterate over the keys of the receiver.
 *
 * @return the keys.
 */
public DoubleArrayList keys() {
    DoubleArrayList list = new DoubleArrayList(size());
    keys(list);
    return list;
}
Also used : DoubleArrayList(cern.colt.list.DoubleArrayList)

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