/** * 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 */ public static double variance(final double[] values) { return VARIANCE.evaluate(values); }
/** * 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 */ public static double variance(final double[] values) { return variance.evaluate(values); }
/** * 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 */ public static double variance(final double[] values) { return VARIANCE.evaluate(values); }
/** * Returns the variance of the entries in the specified portion of * the input array, or <code>Double.NaN</code> if the designated subarray * 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 or the * array index parameters are not valid.</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 variance 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 variance(final double[] values, final int begin, final int length) { return VARIANCE.evaluate(values, begin, length); }
/** * Returns the variance of the entries in the input array, using the * precomputed mean value. Returns <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> * The formula used assumes that the supplied mean value is the arithmetic * mean of the sample data, not a known population parameter. This method * is supplied only to save computation when the mean has already been * computed.</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 * @param mean the precomputed mean value * @return the variance of the values or Double.NaN if the array is empty * @throws IllegalArgumentException if the array is null */ public static double variance(final double[] values, final double mean) { return VARIANCE.evaluate(values, mean); }
/** * Returns the Standard Deviation of the entries in the input array, or * <code>Double.NaN</code> if the array is empty. * <p> * Returns 0 for a single-value (i.e. length = 1) sample.</p> * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * <p> * Does not change the internal state of the statistic.</p> * * @param values the input array * @return the standard deviation of the values or Double.NaN if length = 0 * @throws IllegalArgumentException if the array is null */ public double evaluate(final double[] values) { return Math.sqrt(variance.evaluate(values)); }
/** * Returns the Standard Deviation of the entries in the input array, or * <code>Double.NaN</code> if the array is empty. * <p> * Returns 0 for a single-value (i.e. length = 1) sample.</p> * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * <p> * Does not change the internal state of the statistic.</p> * * @param values the input array * @return the standard deviation of the values or Double.NaN if length = 0 * @throws IllegalArgumentException if the array is null */ @Override public double evaluate(final double[] values) { return Math.sqrt(variance.evaluate(values)); }
/** * Returns the Standard Deviation of the entries in the specified portion of * the input array, or <code>Double.NaN</code> if the designated subarray * is empty. * <p> * Returns 0 for a single-value (i.e. length = 1) sample. </p> * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * <p> * Does not change the internal state of the statistic.</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 standard deviation 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 double evaluate(final double[] values, final int begin, final int length) { return Math.sqrt(variance.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 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> * <p> * Does not change the internal state of the statistic.</p> * * @param values the input array * @return the variance of the values or Double.NaN if length = 0 * @throws IllegalArgumentException if the array is null */ public double evaluate(final double[] values) { if (values == null) { throw new IllegalArgumentException("input values array is null"); } return evaluate(values, 0, values.length); }
/** * Returns the Standard Deviation of the entries in the specified portion of * the input array, or <code>Double.NaN</code> if the designated subarray * is empty. * <p> * Returns 0 for a single-value (i.e. length = 1) sample. </p> * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * <p> * Does not change the internal state of the statistic.</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 standard deviation 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) { return Math.sqrt(variance.evaluate(values, begin, length)); }
/** * Returns the Standard Deviation of the entries in the input array, using * the precomputed mean value. Returns * <code>Double.NaN</code> if the designated subarray is empty. * <p> * Returns 0 for a single-value (i.e. length = 1) sample.</p> * <p> * The formula used assumes that the supplied mean value is the arithmetic * mean of the sample data, not a known population parameter. This method * is supplied only to save computation when the mean has already been * computed.</p> * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * <p> * Does not change the internal state of the statistic.</p> * * @param values the input array * @param mean the precomputed mean value * @return the standard deviation of the values or Double.NaN if length = 0 * @throws IllegalArgumentException if the array is null */ public double evaluate(final double[] values, final double mean) { return Math.sqrt(variance.evaluate(values, mean)); }
/** * Returns the Standard Deviation of the entries in the input array, or * <code>Double.NaN</code> if the array is empty. * <p> * Returns 0 for a single-value (i.e. length = 1) sample.</p> * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * <p> * Does not change the internal state of the statistic.</p> * * @param values the input array * @return the standard deviation of the values or Double.NaN if length = 0 * @throws IllegalArgumentException if the array is null */ @Override public double evaluate(final double[] values) { return FastMath.sqrt(variance.evaluate(values)); }
/** * Returns the variance of the entries in the input array, or * <code>Double.NaN</code> if the array is empty. * <p> * See {@link 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> * <p> * Does not change the internal state of the statistic.</p> * * @param values the input array * @return the variance of the values or Double.NaN if length = 0 * @throws IllegalArgumentException if the array is null */ @Override public double evaluate(final double[] values) { if (values == null) { throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } return evaluate(values, 0, values.length); }
/** * Returns the Standard Deviation of the entries in the specified portion of * the input array, or <code>Double.NaN</code> if the designated subarray * is empty. * <p> * Returns 0 for a single-value (i.e. length = 1) sample. </p> * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * <p> * Does not change the internal state of the statistic.</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 standard deviation 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) { return FastMath.sqrt(variance.evaluate(values, begin, length)); }
/** * Returns the Standard Deviation of the entries in the input array, using * the precomputed mean value. Returns * <code>Double.NaN</code> if the designated subarray is empty. * <p> * Returns 0 for a single-value (i.e. length = 1) sample.</p> * <p> * The formula used assumes that the supplied mean value is the arithmetic * mean of the sample data, not a known population parameter. This method * is supplied only to save computation when the mean has already been * computed.</p> * <p> * Throws <code>IllegalArgumentException</code> if the array is null.</p> * <p> * Does not change the internal state of the statistic.</p> * * @param values the input array * @param mean the precomputed mean value * @return the standard deviation of the values or Double.NaN if length = 0 * @throws IllegalArgumentException if the array is null */ public double evaluate(final double[] values, final double mean) { return FastMath.sqrt(variance.evaluate(values, mean)); }
/** * Calculates the variance of the y values. * * @return Y variance */ protected double calculateYVariance() { return new Variance().evaluate(Y.getData()); }
private void prepareVariance() { this.var = new double[this.feats[0].length]; Matrix m = new DenseMatrix(feats); double[] colArr = new double[this.feats.length]; Variance v = new Variance(); for (int i = 0; i < this.var.length; i++) { m.column(i).storeOn(colArr, 0); this.var[i] = v.evaluate(colArr); } }
private void prepareVariance() { this.var = new double[this.feats[0].length]; Matrix m = new DenseMatrix(feats); double[] colArr = new double[this.feats.length]; Variance v = new Variance(); for (int i = 0; i < this.var.length; i++) { m.column(i).storeOn(colArr, 0); this.var[i] = v.evaluate(colArr); } }
/** * Compute a covariance matrix from a matrix whose columns represent * covariates. * @param matrix input matrix (must have at least two columns and two rows) * @param biasCorrected determines whether or not covariance estimates are bias-corrected * @return covariance matrix */ protected RealMatrix computeCovarianceMatrix(RealMatrix matrix, boolean biasCorrected) { int dimension = matrix.getColumnDimension(); Variance variance = new Variance(biasCorrected); RealMatrix outMatrix = new BlockRealMatrix(dimension, dimension); for (int i = 0; i < dimension; i++) { for (int j = 0; j < i; j++) { double cov = covariance(matrix.getColumn(i), matrix.getColumn(j), biasCorrected); outMatrix.setEntry(i, j, cov); outMatrix.setEntry(j, i, cov); } outMatrix.setEntry(i, i, variance.evaluate(matrix.getColumn(i))); } return outMatrix; }
/** * Compute a covariance matrix from a matrix whose columns represent * covariates. * @param matrix input matrix (must have at least two columns and two rows) * @param biasCorrected determines whether or not covariance estimates are bias-corrected * @return covariance matrix */ protected RealMatrix computeCovarianceMatrix(RealMatrix matrix, boolean biasCorrected) { int dimension = matrix.getColumnDimension(); Variance variance = new Variance(biasCorrected); RealMatrix outMatrix = new BlockRealMatrix(dimension, dimension); for (int i = 0; i < dimension; i++) { for (int j = 0; j < i; j++) { double cov = covariance(matrix.getColumn(i), matrix.getColumn(j), biasCorrected); outMatrix.setEntry(i, j, cov); outMatrix.setEntry(j, i, cov); } outMatrix.setEntry(i, i, variance.evaluate(matrix.getColumn(i))); } return outMatrix; }