/** * {@inheritDoc} */ @Override public void increment(final double d) { sumOfLogs.increment(d); }
/** * Returns an array of the results of a statistic. * @param stats univariate statistic array * @return results array */ private double[] getResults(StorelessUnivariateStatistic[] stats) { double[] results = new double[stats.length]; for (int i = 0; i < results.length; ++i) { results[i] = stats[i].getResult(); } return results; }
/** * {@inheritDoc} */ @Override public void clear() { sumOfLogs.clear(); }
@Override public FieldValue evaluate(List<FieldValue> arguments){ StorelessUnivariateStatistic statistic = createStatistic(); DataType dataType = null; for(int i = 0; i < arguments.size(); i++){ FieldValue value = getOptionalArgument(arguments, i); // "Missing values in the input to an aggregate function are simply ignored" if(Objects.equals(FieldValues.MISSING_VALUE, value)){ continue; } statistic.increment((value.asNumber()).doubleValue()); if(dataType != null){ dataType = TypeUtil.getCommonDataType(dataType, value.getDataType()); } else { dataType = value.getDataType(); } } // "If all inputs are missing, then the result evaluates to a missing value" if(statistic.getN() == 0){ return FieldValues.MISSING_VALUE; } Double result = statistic.getResult(); return FieldValueUtil.create(getResultDataType(dataType), OpType.CONTINUOUS, result); }
/** * Copies source to dest. * <p>Neither source nor dest can be null.</p> * * @param source GeometricMean to copy * @param dest GeometricMean to copy to * @throws NullArgumentException if either source or dest is null */ public static void copy(GeometricMean source, GeometricMean dest) throws NullArgumentException { MathUtils.checkNotNull(source); MathUtils.checkNotNull(dest); dest.setData(source.getDataRef()); dest.sumOfLogs = source.sumOfLogs.copy(); }
/** * {@inheritDoc} */ public long getN() { return sumOfLogs.getN(); }
/** * Returns the geometric mean of the entries in the specified portion * of the input array. * <p> * See {@link GeometricMean} for details on the computing algorithm.</p> * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * * @param values input array containing the values * @param begin first array element to include * @param length the number of elements to include * @return the geometric mean or Double.NaN if length = 0 or * any of the values are <= 0. * @throws MathIllegalArgumentException if the input array is null or the array * index parameters are not valid */ @Override public double evaluate( final double[] values, final int begin, final int length) throws MathIllegalArgumentException { return FastMath.exp( sumOfLogs.evaluate(values, begin, length) / length); }
MathUtils.checkNotNull(source); MathUtils.checkNotNull(dest); dest.maxImpl = source.maxImpl.copy(); dest.minImpl = source.minImpl.copy(); dest.sumImpl = source.sumImpl.copy(); dest.sumLogImpl = source.sumLogImpl.copy(); dest.sumsqImpl = source.sumsqImpl.copy(); dest.secondMoment = source.secondMoment.copy(); dest.n = source.n; dest.varianceImpl = new Variance(dest.secondMoment); } else { dest.varianceImpl = source.varianceImpl.copy(); dest.meanImpl = source.meanImpl.copy(); dest.geoMeanImpl = source.geoMeanImpl.copy();
/** * {@inheritDoc} */ public long getN() { return sumOfLogs.getN(); }
/** * Returns the geometric mean of the entries in the specified portion * of the input array. * <p> * See {@link GeometricMean} for details on the computing algorithm.</p> * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * * @param values input array containing the values * @param begin first array element to include * @param length the number of elements to include * @return the geometric mean or Double.NaN if length = 0 or * any of the values are <= 0. * @throws MathIllegalArgumentException if the input array is null or the array * index parameters are not valid */ @Override public double evaluate( final double[] values, final int begin, final int length) throws MathIllegalArgumentException { return Math.exp( sumOfLogs.evaluate(values, begin, length) / length); }
/** * Returns the mean of the values that have been added. * <p> * Double.NaN is returned if no values have been added. * </p> * @return the mean */ public double getMean() { return meanImpl.getResult(); }
/** * Add a value to the data * @param value the value to add */ public void addValue(double value) { sumImpl.increment(value); sumsqImpl.increment(value); minImpl.increment(value); maxImpl.increment(value); sumLogImpl.increment(value); secondMoment.increment(value); // If mean, variance or geomean have been overridden, // need to increment these if (meanImpl != mean) { meanImpl.increment(value); } if (varianceImpl != variance) { varianceImpl.increment(value); } if (geoMeanImpl != geoMean) { geoMeanImpl.increment(value); } n++; }