Search in sources :

Example 56 with DoubleArrayList

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

the class AbstractIntDoubleMap method values.

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

Example 57 with DoubleArrayList

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

the class QuantileFinderTest method testQuantileCalculation.

/**
 */
public static void testQuantileCalculation(String[] args) {
    int size = Integer.parseInt(args[0]);
    int b = Integer.parseInt(args[1]);
    int k = Integer.parseInt(args[2]);
    // cern.it.util.Log.enableLogging(args[3].equals("log"));
    int chunks = Integer.parseInt(args[4]);
    boolean computeExactQuantilesAlso = args[5].equals("exact");
    boolean doShuffle = args[6].equals("shuffle");
    double epsilon = new Double(args[7]).doubleValue();
    double delta = new Double(args[8]).doubleValue();
    int quantiles = Integer.parseInt(args[9]);
    long max_N = Long.parseLong(args[10]);
    System.out.println("free=" + Runtime.getRuntime().freeMemory());
    System.out.println("total=" + Runtime.getRuntime().totalMemory());
    double[] phis = { 0.001, 0.01, 0.1, 0.5, 0.9, 0.99, 0.999, 1.0 };
    // int quantiles = phis.length;
    Timer timer = new Timer();
    Timer timer2 = new Timer();
    DoubleQuantileFinder approxFinder;
    approxFinder = QuantileFinderFactory.newDoubleQuantileFinder(false, max_N, epsilon, delta, quantiles, null);
    System.out.println(approxFinder);
    // new UnknownApproximateDoubleQuantileFinder(b,k);
    // approxFinder = new ApproximateDoubleQuantileFinder(b,k);
    /*
	double[] returnSamplingRate = new double[1];
	long[] result = ApproximateQuantileFinder.computeBestBandK(size*chunks, epsilon, delta, quantiles, returnSamplingRate);
	approxFinder = new ApproximateQuantileFinder((int) result[0], (int) result[1]);
	System.out.println("epsilon="+epsilon);
	System.out.println("delta="+delta);
	System.out.println("samplingRate="+returnSamplingRate[0]);
	*/
    DoubleQuantileFinder exactFinder = QuantileFinderFactory.newDoubleQuantileFinder(false, -1, 0.0, delta, quantiles, null);
    System.out.println(exactFinder);
    DoubleArrayList list = new DoubleArrayList(size);
    for (int chunk = 0; chunk < chunks; chunk++) {
        list.setSize(0);
        int d = chunk * size;
        timer2.start();
        for (int i = 0; i < size; i++) {
            list.add((double) (i + d));
        }
        timer2.stop();
        // System.out.println("unshuffled="+list);
        if (doShuffle) {
            Timer timer3 = new Timer().start();
            list.shuffle();
            System.out.println("shuffling took ");
            timer3.stop().display();
        }
        // System.out.println("shuffled="+list);
        // list.sort();
        // System.out.println("sorted="+list);
        timer.start();
        approxFinder.addAllOf(list);
        timer.stop();
        if (computeExactQuantilesAlso) {
            exactFinder.addAllOf(list);
        }
    }
    System.out.println("list.add() took" + timer2);
    System.out.println("approxFinder.add() took" + timer);
    // System.out.println("free="+Runtime.getRuntime().freeMemory());
    // System.out.println("total="+Runtime.getRuntime().totalMemory());
    timer.reset().start();
    // approxFinder.close();
    DoubleArrayList approxQuantiles = approxFinder.quantileElements(new DoubleArrayList(phis));
    timer.stop().display();
    System.out.println("Phis=" + new DoubleArrayList(phis));
    System.out.println("ApproxQuantiles=" + approxQuantiles);
    if (computeExactQuantilesAlso) {
        System.out.println("Comparing with exact quantile computation...");
        timer.reset().start();
        // exactFinder.close();
        DoubleArrayList exactQuantiles = exactFinder.quantileElements(new DoubleArrayList(phis));
        timer.stop().display();
        System.out.println("ExactQuantiles=" + exactQuantiles);
        // double[] errors1 = errors1(exactQuantiles.elements(), approxQuantiles.elements());
        // System.out.println("Error1="+new DoubleArrayList(errors1));
        /*
		final DoubleArrayList buffer = new DoubleArrayList((int)exactFinder.size());
		exactFinder.forEach(
			new cern.colt.function.DoubleFunction() {
				public void apply(double element) {
					buffer.add(element);
				}
			}
		);
		*/
        DoubleArrayList observedEpsilons = observedEpsilonsAtPhis(new DoubleArrayList(phis), (ExactDoubleQuantileFinder) exactFinder, approxFinder, epsilon);
        System.out.println("observedEpsilons=" + observedEpsilons);
        double element = 1000.0f;
        System.out.println("exact phi(" + element + ")=" + exactFinder.phi(element));
        System.out.println("apprx phi(" + element + ")=" + approxFinder.phi(element));
        System.out.println("exact elem(phi(" + element + "))=" + exactFinder.quantileElements(new DoubleArrayList(new double[] { exactFinder.phi(element) })));
        System.out.println("apprx elem(phi(" + element + "))=" + approxFinder.quantileElements(new DoubleArrayList(new double[] { approxFinder.phi(element) })));
    }
}
Also used : Timer(cern.colt.Timer) DoubleArrayList(cern.colt.list.DoubleArrayList)

Example 58 with DoubleArrayList

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

the class QuantileFinderTest method observedEpsilonAtPhi.

/**
 * This method was created in VisualAge.
 * @return double[]
 * @param values cern.it.hepodbms.primitivearray.DoubleArrayList
 * @param phis double[]
 */
public static double observedEpsilonAtPhi(double phi, ExactDoubleQuantileFinder exactFinder, DoubleQuantileFinder approxFinder) {
    int N = (int) exactFinder.size();
    int exactRank = (int) Utils.epsilonCeiling(phi * N) - 1;
    // System.out.println("exactRank="+exactRank);
    // just to ensure exactFinder is sorted
    exactFinder.quantileElements(new DoubleArrayList(new double[] { phi })).get(0);
    double approxElement = approxFinder.quantileElements(new DoubleArrayList(new double[] { phi })).get(0);
    // System.out.println("approxElem="+approxElement);
    IntArrayList approxRanks = binaryMultiSearch(exactFinder.buffer, approxElement);
    int from = approxRanks.get(0);
    int to = approxRanks.get(1);
    int distance;
    if (from <= exactRank && exactRank <= to)
        distance = 0;
    else {
        if (from > exactRank)
            distance = Math.abs(from - exactRank);
        else
            distance = Math.abs(exactRank - to);
    }
    double epsilon = (double) distance / (double) N;
    return epsilon;
}
Also used : DoubleArrayList(cern.colt.list.DoubleArrayList) IntArrayList(cern.colt.list.IntArrayList)

Example 59 with DoubleArrayList

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

the class DynamicBin1D method trim.

/**
 * Removes the <tt>s</tt> smallest and <tt>l</tt> largest elements from the receiver.
 * The receivers size will be reduced by <tt>s + l</tt> elements.
 *
 * @param s the number of smallest elements to trim away (<tt>s >= 0</tt>).
 * @param l the number of largest elements to trim away (<tt>l >= 0</tt>).
 */
public synchronized void trim(int s, int l) {
    DoubleArrayList elems = sortedElements();
    clear();
    addAllOfFromTo(elems, s, elems.size() - 1 - l);
}
Also used : DoubleArrayList(cern.colt.list.DoubleArrayList)

Example 60 with DoubleArrayList

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

the class MightyStaticBin1D method moment.

/**
 * Returns the moment of <tt>k</tt>-th order with value <tt>c</tt>,
 * which is <tt>Sum( (x[i]-c)<sup>k</sup> ) / size()</tt>.
 *
 * @param k the order; must be greater than or equal to zero.
 * @param c any number.
 * @throws IllegalArgumentException if <tt>k < 0</tt>.
 * @return <tt>Double.NaN</tt> if <tt>!hasSumOfPower(k)</tt>.
 */
public synchronized double moment(int k, double c) {
    if (k < 0)
        throw new IllegalArgumentException("k must be >= 0");
    // checkOrder(k);
    if (!hasSumOfPowers(k))
        return Double.NaN;
    int maxOrder = Math.min(k, getMaxOrderForSumOfPowers());
    DoubleArrayList sumOfPows = new DoubleArrayList(maxOrder + 1);
    sumOfPows.add(size());
    sumOfPows.add(sum());
    sumOfPows.add(sumOfSquares());
    for (int i = 3; i <= maxOrder; i++) sumOfPows.add(sumOfPowers(i));
    return Descriptive.moment(k, c, size(), sumOfPows.elements());
}
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