private double[] noNans(double[] values) { DoubleArrayList vs = new DoubleArrayList(); for (double v : values) { if (!Double.isNaN(v)) vs.add(v); } vs.trimToSize(); return vs.elements(); }
public static DoubleArrayList standardizeData(DoubleArrayList data) { DoubleArrayList data2 = new DoubleArrayList(data.size()); double sum = 0.0; for (int i = 0; i < data.size(); i++) { sum += data.get(i); } double mean = sum / data.size(); for (int i = 0; i < data.size(); i++) { data2.add(data.get(i) - mean); } double norm = 0.0; for (int i = 0; i < data2.size(); i++) { double v = data2.get(i); norm += v * v; } norm = Math.sqrt(norm / (data2.size() - 1)); for (int i = 0; i < data2.size(); i++) { data2.set(i, data2.get(i) / norm); } return data2; }
/** * Clears the receiver. */ public void clear() { values.clear(); } /**
/** * Convenience method that computes phi's for equi-depth histograms. * This is simply a list of numbers with <tt>i / (double)quantiles</tt> for <tt>i={1,2,...,quantiles-1}</tt>. * @return the equi-depth phi's */ public static cern.colt.list.DoubleArrayList newEquiDepthPhis(int quantiles) { cern.colt.list.DoubleArrayList phis = new cern.colt.list.DoubleArrayList(quantiles-1); for (int i=1; i<=quantiles-1; i++) phis.add(i / (double)quantiles); return phis; } /**
/** * Modifies a data sequence to be standardized. * Changes each element <tt>data[i]</tt> as follows: <tt>data[i] = (data[i]-mean)/standardDeviation</tt>. */ public static void standardize(DoubleArrayList data, double mean, double standardDeviation) { double[] elements = data.elements(); for (int i=data.size(); --i >= 0;) elements[i] = (elements[i]-mean)/standardDeviation; } /**
/** * Returns the observations stored in this probe. * * @return the array of observations associated with this object * */ public double[] getArray() { array.trimToSize(); return array.elements(); }
provider, stopEntry); DoubleArrayList ys = new DoubleArrayList(); DoubleArrayList xs = new DoubleArrayList(); double x = Math.cos(orientation); double y = Math.sin(orientation); xs.add(x); ys.add(y); if (ys.isEmpty()) return null; if (ys.size() == 1) { double theta = Math.atan2(ys.get(0), xs.get(0)); return getAngleAsDirection(theta); double yStdDev = Descriptive.sampleStandardDeviation(ys.size(), yVariance); double xStdDev = Descriptive.sampleStandardDeviation(xs.size(), xVariance); DoubleArrayList normalizedThetas = new DoubleArrayList(); delta = normalizeDelta(delta); orientation = thetaMu + delta; normalizedThetas.add(orientation); normalizedThetas.sort(); double thetaMedian = Descriptive.median(normalizedThetas);
protected double normQuick(SparseDoubleMatrix1D v) { IntArrayList indexList = new IntArrayList(); DoubleArrayList valueList = new DoubleArrayList(); v.getNonZeros(indexList, valueList); double norm = 0.0; for (int i = 0; i < valueList.size(); ++i) { norm += valueList.get(i) * valueList.get(i); } return norm; }
/** * Returns a string representation of the receiver, containing the String * representation of each key-value pair, sorted ascending by key. */ public String toString() { DoubleArrayList theKeys = keys(); theKeys.sort(); StringBuffer buf = new StringBuffer(); buf.append("["); int maxIndex = theKeys.size() - 1; for (int i = 0; i <= maxIndex; i++) { double key = theKeys.get(i); buf.append(String.valueOf(key)); buf.append("->"); buf.append(String.valueOf(get(key))); if (i < maxIndex) buf.append(", "); } buf.append("]"); return buf.toString(); }
/** * Observed epsilon */ public static double epsilon(DoubleArrayList sortedList, DoubleQuantileFinder finder, double phi) { double element = finder.quantileElements(new DoubleArrayList(new double[] {phi})).get(0); return epsilon(sortedList, phi, element); } public static void main(String[] args) {
public static double expScore(double[] _f) { // _f = DataUtils.standardizeData(_f); DoubleArrayList f = new DoubleArrayList(_f); for (int k = 0; k < _f.length; k++) { f.set(k, Math.exp(f.get(k))); } double expected = Descriptive.mean(f); return Math.log(expected); // double diff = logExpected - 0.5; // return Math.abs(diff); }
/** * Returns the Euclid norm which is sum(x[i]^2) * @return */ public double getEuclidNorm() { DoubleArrayList dbls = new DoubleArrayList(this.cardinality()); this.getNonZeros(null, dbls); double norm = 0; for (int i = 0; i < dbls.size(); i++) { norm += Math.pow(dbls.getQuick(i), 2); } return Math.sqrt(norm); }
/** * Not yet commented. */ public static void testRank() { DoubleArrayList list = new DoubleArrayList(new double[] {1.0f, 5.0f, 5.0f, 5.0f, 7.0f, 10.f}); //System.out.println(rankOfWithin(5.0f, list)); } }
private int pruneOutlierValues(DoubleArrayList rawValues, double mu, double sigma) { int goodValueCount = 0; for (int i = 0; i < rawValues.size(); i++) { double value = rawValues.get(i); if (Double.isNaN(value)) continue; if (Math.abs(value - mu) > _outlierRatio * sigma) rawValues.set(i, Double.NaN); else goodValueCount++; } return goodValueCount; }
/** * Constructs a list from the given matrix. * The values are copied. So subsequent changes in <tt>values</tt> are not reflected in the list, and vice-versa. * * @param values The values to be filled into the new list. * @return a new list. */ public cern.colt.list.DoubleArrayList toList(DoubleMatrix1D values) { int size = values.size(); cern.colt.list.DoubleArrayList list = new cern.colt.list.DoubleArrayList(size); list.setSize(size); for (int i=size; --i >= 0; ) list.set(i, values.get(i)); return list; } }
DoubleArrayList valueList = values[i]; indexList.remove(k); valueList.remove(k); int s = indexList.size(); if (s>2 && s*3 < indexList.elements().length) { indexList.setSize(s); valueList.setSize(s*3/2); valueList.trimToSize(); valueList.setSize(s); values[i].setQuick(k,value); values[i] = new DoubleArrayList(3); values[i].beforeInsert(k,value);