/** * In some cases if one just want to access all values, * that method is faster than {@see getValues} due to no {@see DoubleList} initialization. * * @return a copy of the values as array */ public double[] getValuesAsArray() { return values.toArray(); }
/** * In some cases if one just want to access all values, * that method is faster than {@see getValues} due to no {@see DoubleList} initialization. * * @return a copy of the values as array */ public double[] getValuesAsArray() { return values.toArray(); }
/** * Implemented the quantile type 7 referred to * http://tolstoy.newcastle.edu.au/R/e17/help/att-1067/Quartiles_in_R.pdf * and * http://stat.ethz.ch/R-manual/R-patched/library/stats/html/quantile.html * as its the default quantile implementation * <p> * <code> * QuantileType7 = function (v, p) { * v = sort(v) * h = ((length(v)-1)*p)+1 * v[floor(h)]+((h-floor(h))*(v[floor(h)+1]- v[floor(h)])) * } * </code> * * @param values - the values to aggregate the percentile * @param percentile - the percentile (0 - 1), e.g. 0.25 * @return the value of the n-th percentile */ public static double evaluate(DoubleList values, double percentile) { double[] doubles = values.toArray(); Arrays.sort(doubles); return evaluateForDoubles(doubles, percentile); }
/** * Implemented the quantile type 7 referred to * http://tolstoy.newcastle.edu.au/R/e17/help/att-1067/Quartiles_in_R.pdf * and * http://stat.ethz.ch/R-manual/R-patched/library/stats/html/quantile.html * as its the default quantile implementation * <p> * <code> * QuantileType7 = function (v, p) { * v = sort(v) * h = ((length(v)-1)*p)+1 * v[floor(h)]+((h-floor(h))*(v[floor(h)+1]- v[floor(h)])) * } * </code> * * @param percentile - the percentile (0 - 1), e.g. 0.25 * @return the value of the n-th percentile */ public double percentile(double percentile) { double[] copy = toArray(); Arrays.sort(copy);// Attention: this is only necessary because this list is not restricted to non-descending values return evaluateForDoubles(copy, percentile); }
/** * @param list the list * @param start the start index * @param end the end index * @return sublist */ public static DoubleList subList(DoubleList list, int start, int end) { if (list.isEmpty()) { return list; } if (start < 0 || end > list.size()) { throw new IndexOutOfBoundsException(""); } return new DoubleList(copyOfRange(list.toArray(), start, end), end - start); } }
/** * Appends all of the elements in the specified collection to the end of * this list, in the order that they are returned by the * specified collection's Iterator. The behavior of this operation is * undefined if the specified collection is modified while the operation * is in progress. (This implies that the behavior of this call is * undefined if the specified collection is this list, and this * list is nonempty.) * * @param c collection containing elements to be added to this list * @return <tt>true</tt> if this list changed as a result of the call * @throws NullPointerException if the specified collection is null */ public boolean addAll(DoubleList c) { double[] a = c.toArray(); int numNew = a.length; int newCapacity = calculateNewCapacity(doubles.length, size + numNew); growIfNeeded(newCapacity); System.arraycopy(a, 0, doubles, size, numNew); size += numNew; return numNew != 0; }
/** * Inserts all of the elements in the specified collection into this * list, starting at the specified position. Shifts the element * currently at that position (if any) and any subsequent elements to * the right (increases their indices). The new elements will appear * in the list in the order that they are returned by the * specified collection's iterator. * * @param index index at which to insert the first element from the * specified collection * @param c collection containing elements to be added to this list * @return <tt>true</tt> if this list changed as a result of the call * @throws IndexOutOfBoundsException * @throws NullPointerException if the specified collection is null */ public boolean addAll(int index, DoubleList c) { rangeCheckForAdd(index, size); double[] a = c.toArray(); int numNew = a.length; int newCapacity = calculateNewCapacity(doubles.length, size + numNew); growIfNeeded(newCapacity); int numMoved = size - index; if (numMoved > 0) { System.arraycopy(doubles, index, doubles, index + numNew, numMoved); } System.arraycopy(a, 0, doubles, index, numNew); size += numNew; return numNew != 0; }