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;
}
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);
}
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;
}
use of cern.colt.list.DoubleArrayList in project Gemma by PavlidisLab.
the class SpearmanMetricsTest method testCorrel.
/**
* Value from R; this has ties.
* <pre>
* > a<-c(49.0, 43.0, 310.0, 20.0, 20.0, 688.0, 498.0, 533.0, 723.0, 1409.0,279.0);
* > b<-c(1545.0, 1287.0, 2072.0, 1113.0, 676.0, 2648.0, 2478.0, 2574.0, 3554.0,5155.0, 1624.0);
* > cor(a,b, method="spearman");
* [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);
}
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);
}
Aggregations