📄 statutils.java
字号:
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.commons.math.stat;import org.apache.commons.math.stat.descriptive.UnivariateStatistic;import org.apache.commons.math.stat.descriptive.moment.GeometricMean;import org.apache.commons.math.stat.descriptive.moment.Mean;import org.apache.commons.math.stat.descriptive.moment.Variance;import org.apache.commons.math.stat.descriptive.rank.Max;import org.apache.commons.math.stat.descriptive.rank.Min;import org.apache.commons.math.stat.descriptive.rank.Percentile;import org.apache.commons.math.stat.descriptive.summary.Product;import org.apache.commons.math.stat.descriptive.summary.Sum;import org.apache.commons.math.stat.descriptive.summary.SumOfLogs;import org.apache.commons.math.stat.descriptive.summary.SumOfSquares;/** * StatUtils provides static methods for computing statistics based on data * stored in double[] arrays. * * @version $Revision: 617953 $ $Date: 2008-02-02 22:54:00 -0700 (Sat, 02 Feb 2008) $ */public final class StatUtils { /** sum */ private static UnivariateStatistic sum = new Sum(); /** sumSq */ private static UnivariateStatistic sumSq = new SumOfSquares(); /** prod */ private static UnivariateStatistic prod = new Product(); /** sumLog */ private static UnivariateStatistic sumLog = new SumOfLogs(); /** min */ private static UnivariateStatistic min = new Min(); /** max */ private static UnivariateStatistic max = new Max(); /** mean */ private static UnivariateStatistic mean = new Mean(); /** variance */ private static Variance variance = new Variance(); /** percentile */ private static Percentile percentile = new Percentile(); /** geometric mean */ private static GeometricMean geometricMean = new GeometricMean(); /** * Private Constructor */ private StatUtils() { } /** * Returns the sum of the values in the input array, or * <code>Double.NaN</code> if the array is empty. * <p> * Throws <code>IllegalArgumentException</code> if the input array * is null.</p> * * @param values array of values to sum * @return the sum of the values or <code>Double.NaN</code> if the array * is empty * @throws IllegalArgumentException if the array is null */ public static double sum(final double[] values) { return sum.evaluate(values); } /** * Returns the sum of the entries in the specified portion of * the input array, or <code>Double.NaN</code> if the designated subarray * is empty. * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * * @param values the input array * @param begin index of the first array element to include * @param length the number of elements to include * @return the sum of the values or Double.NaN if length = 0 * @throws IllegalArgumentException if the array is null or the array index * parameters are not valid */ public static double sum(final double[] values, final int begin, final int length) { return sum.evaluate(values, begin, length); } /** * Returns the sum of the squares of the entries in the input array, or * <code>Double.NaN</code> if the array is empty. * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * * @param values input array * @return the sum of the squared values or <code>Double.NaN</code> if the * array is empty * @throws IllegalArgumentException if the array is null */ public static double sumSq(final double[] values) { return sumSq.evaluate(values); } /** * Returns the sum of the squares of the entries in the specified portion of * the input array, or <code>Double.NaN</code> if the designated subarray * is empty. * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * * @param values the input array * @param begin index of the first array element to include * @param length the number of elements to include * @return the sum of the squares of the values or Double.NaN if length = 0 * @throws IllegalArgumentException if the array is null or the array index * parameters are not valid */ public static double sumSq(final double[] values, final int begin, final int length) { return sumSq.evaluate(values, begin, length); } /** * Returns the product of the entries in the input array, or * <code>Double.NaN</code> if the array is empty. * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * * @param values the input array * @return the product of the values or Double.NaN if the array is empty * @throws IllegalArgumentException if the array is null */ public static double product(final double[] values) { return prod.evaluate(values); } /** * Returns the product of the entries in the specified portion of * the input array, or <code>Double.NaN</code> if the designated subarray * is empty. * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * * @param values the input array * @param begin index of the first array element to include * @param length the number of elements to include * @return the product of the values or Double.NaN if length = 0 * @throws IllegalArgumentException if the array is null or the array index * parameters are not valid */ public static double product(final double[] values, final int begin, final int length) { return prod.evaluate(values, begin, length); } /** * Returns the sum of the natural logs of the entries in the input array, or * <code>Double.NaN</code> if the array is empty. * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * <p> * See {@link org.apache.commons.math.stat.descriptive.summary.SumOfLogs}. * </p> * * @param values the input array * @return the sum of the natural logs of the values or Double.NaN if * the array is empty * @throws IllegalArgumentException if the array is null */ public static double sumLog(final double[] values) { return sumLog.evaluate(values); } /** * Returns the sum of the natural logs of the entries in the specified portion of * the input array, or <code>Double.NaN</code> if the designated subarray * is empty. * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * <p> * See {@link org.apache.commons.math.stat.descriptive.summary.SumOfLogs}. * </p> * * @param values the input array * @param begin index of the first array element to include * @param length the number of elements to include * @return the sum of the natural logs of the values or Double.NaN if * length = 0 * @throws IllegalArgumentException if the array is null or the array index * parameters are not valid */ public static double sumLog(final double[] values, final int begin, final int length) { return sumLog.evaluate(values, begin, length); } /** * Returns the arithmetic mean of the entries in the input array, or * <code>Double.NaN</code> if the array is empty. * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * <p> * See {@link org.apache.commons.math.stat.descriptive.moment.Mean} for * details on the computing algorithm.</p> * * @param values the input array * @return the mean of the values or Double.NaN if the array is empty * @throws IllegalArgumentException if the array is null */ public static double mean(final double[] values) { return mean.evaluate(values); } /** * Returns the arithmetic mean of the entries in the specified portion of * the input array, or <code>Double.NaN</code> if the designated subarray * is empty. * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * <p> * See {@link org.apache.commons.math.stat.descriptive.moment.Mean} for * details on the computing algorithm.</p> * * @param values the input array * @param begin index of the first array element to include * @param length the number of elements to include * @return the mean of the values or Double.NaN if length = 0 * @throws IllegalArgumentException if the array is null or the array index * parameters are not valid */ public static double mean(final double[] values, final int begin, final int length) { return mean.evaluate(values, begin, length); } /** * Returns the geometric mean of the entries in the input array, or * <code>Double.NaN</code> if the array is empty. * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * <p> * See {@link org.apache.commons.math.stat.descriptive.moment.GeometricMean} * for details on the computing algorithm.</p> * * @param values the input array * @return the geometric mean of the values or Double.NaN if the array is empty * @throws IllegalArgumentException if the array is null */ public static double geometricMean(final double[] values) { return geometricMean.evaluate(values); } /** * Returns the geometric mean of the entries in the specified portion of * the input array, or <code>Double.NaN</code> if the designated subarray * is empty. * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * <p> * See {@link org.apache.commons.math.stat.descriptive.moment.GeometricMean} * for details on the computing algorithm.</p> * * @param values the input array * @param begin index of the first array element to include * @param length the number of elements to include * @return the geometric mean of the values or Double.NaN if length = 0 * @throws IllegalArgumentException if the array is null or the array index * parameters are not valid */ public static double geometricMean(final double[] values, final int begin, final int length) { return geometricMean.evaluate(values, begin, length); } /** * Returns the variance of the entries in the input array, or * <code>Double.NaN</code> if the array is empty. * <p> * See {@link org.apache.commons.math.stat.descriptive.moment.Variance} for * details on the computing algorithm.</p> * <p> * Returns 0 for a single-value (i.e. length = 1) sample.</p> * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * * @param values the input array * @return the variance of the values or Double.NaN if the array is empty * @throws IllegalArgumentException if the array is null */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -