Java Code Examples for org.apache.commons.math.stat.descriptive.summary.Sum#evaluate()

The following examples show how to use org.apache.commons.math.stat.descriptive.summary.Sum#evaluate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Mean.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 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
 */
@Override
public double evaluate(final double[] values,final int begin, final int length) {
    if (test(values, begin, length)) {
        Sum sum = new Sum();
        double sampleSize = length;
        
        // Compute initial estimate using definitional formula
        double xbar = sum.evaluate(values, begin, length) / sampleSize;
        
        // Compute correction factor in second pass
        double correction = 0;
        for (int i = begin; i < begin + length; i++) {
            correction += (values[i] - xbar);
        }
        return xbar + (correction/sampleSize);
    }
    return Double.NaN;
}
 
Example 2
Source File: Mean.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 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
 */
@Override
public double evaluate(final double[] values,final int begin, final int length) {
    if (test(values, begin, length)) {
        Sum sum = new Sum();
        double sampleSize = length;

        // Compute initial estimate using definitional formula
        double xbar = sum.evaluate(values, begin, length) / sampleSize;

        // Compute correction factor in second pass
        double correction = 0;
        for (int i = begin; i < begin + length; i++) {
            correction += values[i] - xbar;
        }
        return xbar + (correction/sampleSize);
    }
    return Double.NaN;
}
 
Example 3
Source File: Mean.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 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
 */
@Override
public double evaluate(final double[] values,final int begin, final int length) {
    if (test(values, begin, length)) {
        Sum sum = new Sum();
        double sampleSize = length;
        
        // Compute initial estimate using definitional formula
        double xbar = sum.evaluate(values, begin, length) / sampleSize;
        
        // Compute correction factor in second pass
        double correction = 0;
        for (int i = begin; i < begin + length; i++) {
            correction += (values[i] - xbar);
        }
        return xbar + (correction/sampleSize);
    }
    return Double.NaN;
}
 
Example 4
Source File: Mean.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 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
 */
@Override
public double evaluate(final double[] values,final int begin, final int length) {
    if (test(values, begin, length)) {
        Sum sum = new Sum();
        double sampleSize = length;

        // Compute initial estimate using definitional formula
        double xbar = sum.evaluate(values, begin, length) / sampleSize;

        // Compute correction factor in second pass
        double correction = 0;
        for (int i = begin; i < begin + length; i++) {
            correction += values[i] - xbar;
        }
        return xbar + (correction/sampleSize);
    }
    return Double.NaN;
}
 
Example 5
Source File: Mean.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 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
 */
@Override
public double evaluate(final double[] values,final int begin, final int length) {
    if (test(values, begin, length)) {
        Sum sum = new Sum();
        double sampleSize = length;

        // Compute initial estimate using definitional formula
        double xbar = sum.evaluate(values, begin, length) / sampleSize;

        // Compute correction factor in second pass
        double correction = 0;
        for (int i = begin; i < begin + length; i++) {
            correction += values[i] - xbar;
        }
        return xbar + (correction/sampleSize);
    }
    return Double.NaN;
}
 
Example 6
Source File: Mean.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 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
 */
@Override
public double evaluate(final double[] values,final int begin, final int length) {
    if (test(values, begin, length)) {
        Sum sum = new Sum();
        double sampleSize = length;

        // Compute initial estimate using definitional formula
        double xbar = sum.evaluate(values, begin, length) / sampleSize;

        // Compute correction factor in second pass
        double correction = 0;
        for (int i = begin; i < begin + length; i++) {
            correction += values[i] - xbar;
        }
        return xbar + (correction/sampleSize);
    }
    return Double.NaN;
}
 
Example 7
Source File: Mean.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 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
 */
@Override
public double evaluate(final double[] values,final int begin, final int length) {
    if (test(values, begin, length)) {
        Sum sum = new Sum();
        double sampleSize = length;

        // Compute initial estimate using definitional formula
        double xbar = sum.evaluate(values, begin, length) / sampleSize;

        // Compute correction factor in second pass
        double correction = 0;
        for (int i = begin; i < begin + length; i++) {
            correction += values[i] - xbar;
        }
        return xbar + (correction/sampleSize);
    }
    return Double.NaN;
}
 
Example 8
Source File: Mean.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 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
 */
@Override
public double evaluate(final double[] values,final int begin, final int length) {
    if (test(values, begin, length)) {
        Sum sum = new Sum();
        double sampleSize = length;

        // Compute initial estimate using definitional formula
        double xbar = sum.evaluate(values, begin, length) / sampleSize;

        // Compute correction factor in second pass
        double correction = 0;
        for (int i = begin; i < begin + length; i++) {
            correction += values[i] - xbar;
        }
        return xbar + (correction/sampleSize);
    }
    return Double.NaN;
}
 
Example 9
Source File: Mean.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 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
 */
@Override
public double evaluate(final double[] values,final int begin, final int length) {
    if (test(values, begin, length)) {
        Sum sum = new Sum();
        double sampleSize = length;

        // Compute initial estimate using definitional formula
        double xbar = sum.evaluate(values, begin, length) / sampleSize;

        // Compute correction factor in second pass
        double correction = 0;
        for (int i = begin; i < begin + length; i++) {
            correction += values[i] - xbar;
        }
        return xbar + (correction/sampleSize);
    }
    return Double.NaN;
}
 
Example 10
Source File: Mean.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 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
 */
@Override
public double evaluate(final double[] values,final int begin, final int length) {
    if (test(values, begin, length)) {
        Sum sum = new Sum();
        double sampleSize = length;
        
        // Compute initial estimate using definitional formula
        double xbar = sum.evaluate(values, begin, length) / sampleSize;
        
        // Compute correction factor in second pass
        double correction = 0;
        for (int i = begin; i < begin + length; i++) {
            correction += (values[i] - xbar);
        }
        return xbar + (correction/sampleSize);
    }
    return Double.NaN;
}
 
Example 11
Source File: Nopol2017_0069_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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 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
 */
@Override
public double evaluate(final double[] values,final int begin, final int length) {
    if (test(values, begin, length)) {
        Sum sum = new Sum();
        double sampleSize = length;

        // Compute initial estimate using definitional formula
        double xbar = sum.evaluate(values, begin, length) / sampleSize;

        // Compute correction factor in second pass
        double correction = 0;
        for (int i = begin; i < begin + length; i++) {
            correction += values[i] - xbar;
        }
        return xbar + (correction/sampleSize);
    }
    return Double.NaN;
}
 
Example 12
Source File: Mean.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the weighted 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 either array is null.</p>
 * <p>
 * See {@link Mean} for details on the computing algorithm. The two-pass algorithm
 * described above is used here, with weights applied in computing both the original
 * estimate and the correction factor.</p>
 * <p>
 * Throws <code>IllegalArgumentException</code> if any of the following are true:
 * <ul><li>the values array is null</li>
 *     <li>the weights array is null</li>
 *     <li>the weights array does not have the same length as the values array</li>
 *     <li>the weights array contains one or more infinite values</li>
 *     <li>the weights array contains one or more NaN values</li>
 *     <li>the weights array contains negative values</li>
 *     <li>the start and length arguments do not determine a valid array</li>
 * </ul></p>
 *
 * @param values the input array
 * @param weights the weights 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 parameters are not valid
 * @since 2.1
 */
public double evaluate(final double[] values, final double[] weights,
                       final int begin, final int length) {
    if (test(values, weights, begin, length)) {
        Sum sum = new Sum();

        // Compute initial estimate using definitional formula
        double sumw = sum.evaluate(weights,begin,length);
        double xbarw = sum.evaluate(values, weights, begin, length) / sumw;

        // Compute correction factor in second pass
        double correction = 0;
        for (int i = begin; i < begin + length; i++) {
            correction += weights[i] * (values[i] - xbarw);
        }
        return xbarw + (correction/sumw);
    }
    return Double.NaN;
}
 
Example 13
Source File: Mean.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the weighted 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 either array is null.</p>
 * <p>
 * See {@link Mean} for details on the computing algorithm. The two-pass algorithm
 * described above is used here, with weights applied in computing both the original
 * estimate and the correction factor.</p>
 * <p>
 * Throws <code>IllegalArgumentException</code> if any of the following are true:
 * <ul><li>the values array is null</li>
 *     <li>the weights array is null</li>
 *     <li>the weights array does not have the same length as the values array</li>
 *     <li>the weights array contains one or more infinite values</li>
 *     <li>the weights array contains one or more NaN values</li>
 *     <li>the weights array contains negative values</li>
 *     <li>the start and length arguments do not determine a valid array</li>
 * </ul></p>
 *
 * @param values the input array
 * @param weights the weights 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 parameters are not valid
 * @since 2.1
 */
public double evaluate(final double[] values, final double[] weights,
                       final int begin, final int length) {
    if (test(values, weights, begin, length)) {
        Sum sum = new Sum();

        // Compute initial estimate using definitional formula
        double sumw = sum.evaluate(weights,begin,length);
        double xbarw = sum.evaluate(values, weights, begin, length) / sumw;

        // Compute correction factor in second pass
        double correction = 0;
        for (int i = begin; i < begin + length; i++) {
            correction += weights[i] * (values[i] - xbarw);
        }
        return xbarw + (correction/sumw);
    }
    return Double.NaN;
}
 
Example 14
Source File: Mean.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the weighted 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 either array is null.</p>
 * <p>
 * See {@link Mean} for details on the computing algorithm. The two-pass algorithm
 * described above is used here, with weights applied in computing both the original
 * estimate and the correction factor.</p>
 * <p>
 * Throws <code>IllegalArgumentException</code> if any of the following are true:
 * <ul><li>the values array is null</li>
 *     <li>the weights array is null</li>
 *     <li>the weights array does not have the same length as the values array</li>
 *     <li>the weights array contains one or more infinite values</li>
 *     <li>the weights array contains one or more NaN values</li>
 *     <li>the weights array contains negative values</li>
 *     <li>the start and length arguments do not determine a valid array</li>
 * </ul></p>
 *
 * @param values the input array
 * @param weights the weights 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 parameters are not valid
 * @since 2.1
 */
public double evaluate(final double[] values, final double[] weights,
                       final int begin, final int length) {
    if (test(values, weights, begin, length)) {
        Sum sum = new Sum();

        // Compute initial estimate using definitional formula
        double sumw = sum.evaluate(weights,begin,length);
        double xbarw = sum.evaluate(values, weights, begin, length) / sumw;

        // Compute correction factor in second pass
        double correction = 0;
        for (int i = begin; i < begin + length; i++) {
            correction += weights[i] * (values[i] - xbarw);
        }
        return xbarw + (correction/sumw);
    }
    return Double.NaN;
}
 
Example 15
Source File: Mean.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the weighted 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 either array is null.</p>
 * <p>
 * See {@link Mean} for details on the computing algorithm. The two-pass algorithm
 * described above is used here, with weights applied in computing both the original
 * estimate and the correction factor.</p>
 * <p>
 * Throws <code>IllegalArgumentException</code> if any of the following are true:
 * <ul><li>the values array is null</li>
 *     <li>the weights array is null</li>
 *     <li>the weights array does not have the same length as the values array</li>
 *     <li>the weights array contains one or more infinite values</li>
 *     <li>the weights array contains one or more NaN values</li>
 *     <li>the weights array contains negative values</li>
 *     <li>the start and length arguments do not determine a valid array</li>
 * </ul></p>
 *
 * @param values the input array
 * @param weights the weights 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 parameters are not valid
 * @since 2.1
 */
public double evaluate(final double[] values, final double[] weights,
                       final int begin, final int length) {
    if (test(values, weights, begin, length)) {
        Sum sum = new Sum();

        // Compute initial estimate using definitional formula
        double sumw = sum.evaluate(weights,begin,length);
        double xbarw = sum.evaluate(values, weights, begin, length) / sumw;

        // Compute correction factor in second pass
        double correction = 0;
        for (int i = begin; i < begin + length; i++) {
            correction += weights[i] * (values[i] - xbarw);
        }
        return xbarw + (correction/sumw);
    }
    return Double.NaN;
}
 
Example 16
Source File: Nopol2017_0069_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Returns the weighted 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 either array is null.</p>
 * <p>
 * See {@link Mean} for details on the computing algorithm. The two-pass algorithm
 * described above is used here, with weights applied in computing both the original
 * estimate and the correction factor.</p>
 * <p>
 * Throws <code>IllegalArgumentException</code> if any of the following are true:
 * <ul><li>the values array is null</li>
 *     <li>the weights array is null</li>
 *     <li>the weights array does not have the same length as the values array</li>
 *     <li>the weights array contains one or more infinite values</li>
 *     <li>the weights array contains one or more NaN values</li>
 *     <li>the weights array contains negative values</li>
 *     <li>the start and length arguments do not determine a valid array</li>
 * </ul></p>
 *
 * @param values the input array
 * @param weights the weights 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 parameters are not valid
 * @since 2.1
 */
public double evaluate(final double[] values, final double[] weights,
                       final int begin, final int length) {
    if (test(values, weights, begin, length)) {
        Sum sum = new Sum();

        // Compute initial estimate using definitional formula
        double sumw = sum.evaluate(weights,begin,length);
        double xbarw = sum.evaluate(values, weights, begin, length) / sumw;

        // Compute correction factor in second pass
        double correction = 0;
        for (int i = begin; i < begin + length; i++) {
            correction += weights[i] * (values[i] - xbarw);
        }
        return xbarw + (correction/sumw);
    }
    return Double.NaN;
}
 
Example 17
Source File: Mean.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the weighted 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 either array is null.</p>
 * <p>
 * See {@link Mean} for details on the computing algorithm. The two-pass algorithm
 * described above is used here, with weights applied in computing both the original
 * estimate and the correction factor.</p>
 * <p>
 * Throws <code>IllegalArgumentException</code> if any of the following are true:
 * <ul><li>the values array is null</li>
 *     <li>the weights array is null</li>
 *     <li>the weights array does not have the same length as the values array</li>
 *     <li>the weights array contains one or more infinite values</li>
 *     <li>the weights array contains one or more NaN values</li>
 *     <li>the weights array contains negative values</li>
 *     <li>the start and length arguments do not determine a valid array</li>
 * </ul></p>
 *
 * @param values the input array
 * @param weights the weights 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 parameters are not valid
 */
public double evaluate(final double[] values, final double[] weights,
                       final int begin, final int length) {
    if (test(values, weights, begin, length)) {
        Sum sum = new Sum();

        // Compute initial estimate using definitional formula
        double sumw = sum.evaluate(weights,begin,length);
        double xbarw = sum.evaluate(values, weights, begin, length) / sumw;

        // Compute correction factor in second pass
        double correction = 0;
        for (int i = begin; i < begin + length; i++) {
            correction += weights[i] * (values[i] - xbarw);
        }
        return xbarw + (correction/sumw);
    }
    return Double.NaN;
}
 
Example 18
Source File: Mean.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the weighted 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 either array is null.</p>
 * <p>
 * See {@link Mean} for details on the computing algorithm. The two-pass algorithm
 * described above is used here, with weights applied in computing both the original
 * estimate and the correction factor.</p>
 * <p>
 * Throws <code>IllegalArgumentException</code> if any of the following are true:
 * <ul><li>the values array is null</li>
 *     <li>the weights array is null</li>
 *     <li>the weights array does not have the same length as the values array</li>
 *     <li>the weights array contains one or more infinite values</li>
 *     <li>the weights array contains one or more NaN values</li>
 *     <li>the weights array contains negative values</li>
 *     <li>the start and length arguments do not determine a valid array</li>
 * </ul></p>
 *
 * @param values the input array
 * @param weights the weights 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 parameters are not valid
 * @since 2.1
 */
public double evaluate(final double[] values, final double[] weights,
                       final int begin, final int length) {
    if (test(values, weights, begin, length)) {
        Sum sum = new Sum();

        // Compute initial estimate using definitional formula
        double sumw = sum.evaluate(weights,begin,length);
        double xbarw = sum.evaluate(values, weights, begin, length) / sumw;

        // Compute correction factor in second pass
        double correction = 0;
        for (int i = begin; i < begin + length; i++) {
            correction += weights[i] * (values[i] - xbarw);
        }
        return xbarw + (correction/sumw);
    }
    return Double.NaN;
}
 
Example 19
Source File: Nopol2017_0069_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Returns the weighted 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 either array is null.</p>
 * <p>
 * See {@link Mean} for details on the computing algorithm. The two-pass algorithm
 * described above is used here, with weights applied in computing both the original
 * estimate and the correction factor.</p>
 * <p>
 * Throws <code>IllegalArgumentException</code> if any of the following are true:
 * <ul><li>the values array is null</li>
 *     <li>the weights array is null</li>
 *     <li>the weights array does not have the same length as the values array</li>
 *     <li>the weights array contains one or more infinite values</li>
 *     <li>the weights array contains one or more NaN values</li>
 *     <li>the weights array contains negative values</li>
 *     <li>the start and length arguments do not determine a valid array</li>
 * </ul></p>
 *
 * @param values the input array
 * @param weights the weights 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 parameters are not valid
 * @since 2.1
 */
public double evaluate(final double[] values, final double[] weights,
                       final int begin, final int length) {
    if (test(values, weights, begin, length)) {
        Sum sum = new Sum();

        // Compute initial estimate using definitional formula
        double sumw = sum.evaluate(weights,begin,length);
        double xbarw = sum.evaluate(values, weights, begin, length) / sumw;

        // Compute correction factor in second pass
        double correction = 0;
        for (int i = begin; i < begin + length; i++) {
            correction += weights[i] * (values[i] - xbarw);
        }
        if (xbarw < length) {
            return xbarw + (correction/sumw);
        }
    }
    return Double.NaN;
}
 
Example 20
Source File: Mean.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the weighted 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 either array is null.</p>
 * <p>
 * See {@link Mean} for details on the computing algorithm. The two-pass algorithm
 * described above is used here, with weights applied in computing both the original
 * estimate and the correction factor.</p>
 * <p>
 * Throws <code>IllegalArgumentException</code> if any of the following are true:
 * <ul><li>the values array is null</li>
 *     <li>the weights array is null</li>
 *     <li>the weights array does not have the same length as the values array</li>
 *     <li>the weights array contains one or more infinite values</li>
 *     <li>the weights array contains one or more NaN values</li>
 *     <li>the weights array contains negative values</li>
 *     <li>the start and length arguments do not determine a valid array</li>
 * </ul></p>
 *
 * @param values the input array
 * @param weights the weights 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 parameters are not valid
 * @since 2.1
 */
public double evaluate(final double[] values, final double[] weights,
                       final int begin, final int length) {
    if (test(values, weights, begin, length)) {
        Sum sum = new Sum();

        // Compute initial estimate using definitional formula
        double sumw = sum.evaluate(weights,begin,length);
        double xbarw = sum.evaluate(values, weights, begin, length) / sumw;

        // Compute correction factor in second pass
        double correction = 0;
        for (int i = begin; i < begin + length; i++) {
            correction += weights[i] * (values[i] - xbarw);
        }
        return xbarw + (correction/sumw);
    }
    return Double.NaN;
}