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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations