/** * Returns a copy of the ResizableDoubleArray. Does not contract before * the copy, so the returned object is an exact copy of this. * * @return a new ResizableDoubleArray with the same data and configuration * properties as this * @since 2.0 */ public synchronized ResizableDoubleArray copy() { final ResizableDoubleArray result = new ResizableDoubleArray(); copy(this, result); return result; }
/** * Adds the value to the dataset. If the dataset is at the maximum size * (i.e., the number of stored elements equals the currently configured * windowSize), the first (oldest) element in the dataset is discarded * to make room for the new value. * * @param v the value to be added */ public void addValue(double v) { if (windowSize != INFINITE_WINDOW) { if (getN() == windowSize) { eDA.addElementRolling(v); } else if (getN() < windowSize) { eDA.addElement(v); } } else { eDA.addElement(v); } }
initialCapacity); checkContractExpand(contractionCriterion, expansionFactor); addElements(data);
/** * Sets the contraction criteria. * * @param contractionCriteria contraction criteria * @throws MathIllegalArgumentException if the contractionCriteria is less than * the expansionCriteria. * @deprecated As of 3.1 (to be removed in 4.0 as field will become "final"). */ @Deprecated public void setContractionCriteria(float contractionCriteria) throws MathIllegalArgumentException { checkContractExpand(contractionCriteria, getExpansionFactor()); synchronized(this) { this.contractionCriterion = contractionCriteria; } }
expand(); if (shouldContract()) { contract();
private Double aggregateSubjects(MathArrays.Function aggregator, List<Subject> aggregationSubjects) throws IncomputableFieldException { ResizableDoubleArray doubles = new ResizableDoubleArray(); for (Subject subject : aggregationSubjects) { String value = null; try { value = singleValueField.valueForSubject(subject, true); doubles.addElement(Double.parseDouble(value)); } catch (IncomputableFieldException e) { log.warn("Incomputable field not included in aggregation for subject {} ({})", subject.getName(), subject.getId()); } catch (NullPointerException | NumberFormatException e) { log.warn("Incomputable field not included in aggregation for subject {} ({}), value {} cannot be " + "converted to numeric type.", subject.getName(), subject.getId(), value); } } Double retVal = doubles.compute(aggregator); if (retVal.isNaN()) { throw new IncomputableFieldException(String.format("Aggregation function %s returned NaN (any " + "NaN values in the set? or trying to operate on an empty set?)", function)); } else if (retVal.isInfinite()) { throw new IncomputableFieldException(String.format("Aggregation function %s returned Infinity (possible division by zero?)", function)); } return retVal; }
/** * Sets the expansionFactor. Throws IllegalArgumentException if the * the following conditions are not met: * <ul> * <li><code>expansionFactor > 1</code></li> * <li><code>contractionFactor >= expansionFactor</code></li> * </ul> * @param expansionFactor the new expansion factor value. * @throws MathIllegalArgumentException if expansionFactor is <= 1 or greater * than contractionFactor * @deprecated As of 3.1 (to be removed in 4.0 as field will become "final"). */ @Deprecated public void setExpansionFactor(float expansionFactor) throws MathIllegalArgumentException { checkContractExpand(getContractionCriterion(), expansionFactor); // The check above verifies that the expansion factor is > 1.0; synchronized(this) { this.expansionFactor = expansionFactor; } }
/** * Construct a DescriptiveStatistics instance with an infinite window * and the initial data values in double[] initialDoubleArray. * If initialDoubleArray is null, then this constructor corresponds to * DescriptiveStatistics() * * @param initialDoubleArray the initial double[]. */ public DescriptiveStatistics(double[] initialDoubleArray) { if (initialDoubleArray != null) { eDA = new ResizableDoubleArray(initialDoubleArray); } }
public void setData(double[] x){ if(data!=null)data.clear(); for(int i=0;i<x.length;i++){ data.addElement(x[i]); } }
/** * Discards the <code>i</code> initial elements of the array. For example, * if the array contains the elements 1,2,3,4, invoking * <code>discardFrontElements(2)</code> will cause the first two elements * to be discarded, leaving 3,4 in the array. Throws illegalArgumentException * if i exceeds numElements. * * @param i the number of elements to discard from the front of the array * @throws MathIllegalArgumentException if i is greater than numElements. * @since 2.0 */ public synchronized void discardFrontElements(int i) throws MathIllegalArgumentException { discardExtremeElements(i,true); }
public void increment(double value, double frequency){ for(int w=0;w<frequency;w++){ data.addElement(value); } }
/** * Copy constructor. Creates a new ResizableDoubleArray that is a deep, * fresh copy of the original. Needs to acquire synchronization lock * on original. Original may not be null; otherwise a {@link NullArgumentException} * is thrown. * * @param original array to copy * @exception NullArgumentException if original is null * @since 2.0 */ public ResizableDoubleArray(ResizableDoubleArray original) throws NullArgumentException { MathUtils.checkNotNull(original); copy(original, this); }
/** * Adds an element to the end of this expandable array. * * @param value Value to be added to end of array. */ public synchronized void addElement(double value) { if (internalArray.length <= startIndex + numElements) { expand(); } internalArray[startIndex + numElements++] = value; }
/** * Checks the expansion factor and the contraction criterion and throws an * IllegalArgumentException if the contractionCriteria is less than the * expansionCriteria * * @param expansion factor to be checked * @param contraction criteria to be checked * @throws MathIllegalArgumentException if the contractionCriteria is less than * the expansionCriteria. * @deprecated As of 3.1. Please use * {@link #checkContractExpand(double,double)} instead. */ @Deprecated protected void checkContractExpand(float contraction, float expansion) throws MathIllegalArgumentException { checkContractExpand((double) contraction, (double) expansion); }
/** * Resets all statistics and storage */ public void clear() { eDA.clear(); }
/** * Apply the given statistic to the data associated with this set of statistics. * @param stat the statistic to apply * @return the computed value of the statistic. */ public double apply(UnivariateStatistic stat) { // No try-catch or advertised exception here because arguments are guaranteed valid return eDA.compute(stat); }
ResizableDoubleArray doubles = new ResizableDoubleArray(); doubles.addElement(Double.parseDouble(((SingleValueField) field).valueForSubject(subject, null))); }catch (IncomputableFieldException e){ log.warn("Incomputable field not included in statistics for subject {} ({})", Double descriptiveStaistic = doubles.compute(statistic.getStatistic());
expand(); if (shouldContract()) { contract();
/** * Sets the contraction criteria. * * @param contractionCriteria contraction criteria * @throws MathIllegalArgumentException if the contractionCriteria is less than * the expansionCriteria. * @deprecated As of 3.1 (to be removed in 4.0 as field will become "final"). */ @Deprecated public void setContractionCriteria(float contractionCriteria) throws MathIllegalArgumentException { checkContractExpand(contractionCriteria, getExpansionFactor()); synchronized(this) { this.contractionCriterion = contractionCriteria; } }