org.apache.commons.math3.stat.descriptive.moment.Variance.evaluate()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(15.3k)|赞(0)|评价(0)|浏览(152)

本文整理了Java中org.apache.commons.math3.stat.descriptive.moment.Variance.evaluate()方法的一些代码示例,展示了Variance.evaluate()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Variance.evaluate()方法的具体详情如下:
包路径:org.apache.commons.math3.stat.descriptive.moment.Variance
类名称:Variance
方法名:evaluate

Variance.evaluate介绍

[英]Returns the variance of the entries in the input array, or Double.NaN if the array is empty.

See Variance for details on the computing algorithm.

Returns 0 for a single-value (i.e. length = 1) sample.

Throws MathIllegalArgumentException if the array is null.

Does not change the internal state of the statistic.
[中]返回输入数组中项目的方差,如果数组为空,则返回Double.NaN
有关计算算法的详细信息,请参见方差。
对于单个值(即长度=1)样本,返回0。
如果数组为空,则抛出MathIllegalArgumentException
不会更改统计信息的内部状态。

代码示例

代码示例来源:origin: org.apache.commons/commons-math3

/**
 * Returns the variance of the entries in the input array, or
 * <code>Double.NaN</code> if the array is empty.
 *
 * <p>This method returns the bias-corrected sample variance (using {@code n - 1} in
 * the denominator).  Use {@link #populationVariance(double[])} for the non-bias-corrected
 * population variance.</p>
 * <p>
 * See {@link org.apache.commons.math3.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>MathIllegalArgumentException</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 MathIllegalArgumentException if the array is null
 */
public static double variance(final double[] values) throws MathIllegalArgumentException {
  return VARIANCE.evaluate(values);
}

代码示例来源:origin: org.apache.commons/commons-math3

/**
 * 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>This method returns the bias-corrected sample variance (using {@code n - 1} in
 * the denominator).  Use {@link #populationVariance(double[], int, int)} for the non-bias-corrected
 * population variance.</p>
 * <p>
 * See {@link org.apache.commons.math3.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>MathIllegalArgumentException</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 MathIllegalArgumentException 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) throws MathIllegalArgumentException {
  return VARIANCE.evaluate(values, begin, length);
}

代码示例来源:origin: org.apache.commons/commons-math3

/**
 * 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 Variance} for details on the computing algorithm.</p>
 * <p>
 * If <code>isBiasCorrected</code> is <code>true</code> the formula used
 * assumes that the supplied mean value is the arithmetic mean of the
 * sample data, not a known population parameter.  If the mean is a known
 * population parameter, or if the "population" version of the variance is
 * desired, set <code>isBiasCorrected</code> to <code>false</code> before
 * invoking this method.</p>
 * <p>
 * Returns 0 for a single-value (i.e. length = 1) sample.</p>
 * <p>
 * Throws <code>MathIllegalArgumentException</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 variance of the values or Double.NaN if the array is empty
 * @throws MathIllegalArgumentException if the array is null
 */
public double evaluate(final double[] values, final double mean) throws MathIllegalArgumentException {
  return evaluate(values, mean, 0, values.length);
}

代码示例来源:origin: org.apache.commons/commons-math3

/**
 * 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>This method returns the bias-corrected sample variance (using {@code n - 1} in
 * the denominator).  Use {@link #populationVariance(double[], double)} for the non-bias-corrected
 * population variance.</p>
 * <p>
 * See {@link org.apache.commons.math3.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>MathIllegalArgumentException</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 MathIllegalArgumentException if the array is null
 */
public static double variance(final double[] values, final double mean)
throws MathIllegalArgumentException {
  return VARIANCE.evaluate(values, mean);
}

代码示例来源:origin: org.apache.commons/commons-math3

/**
 * 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>MathIllegalArgumentException</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 MathIllegalArgumentException if the array is null
 */
@Override
public double evaluate(final double[] values) throws MathIllegalArgumentException  {
  return FastMath.sqrt(variance.evaluate(values));
}

代码示例来源:origin: org.apache.commons/commons-math3

/**
 * Returns the <a href="http://en.wikibooks.org/wiki/Statistics/Summary/Variance">
 * population variance</a> of the entries in the input array, or
 * <code>Double.NaN</code> if the array is empty.
 * <p>
 * See {@link org.apache.commons.math3.stat.descriptive.moment.Variance} for
 * details on the formula and computing algorithm.</p>
 * <p>
 * Returns 0 for a single-value (i.e. length = 1) sample.</p>
 * <p>
 * Throws <code>MathIllegalArgumentException</code> if the array is null.</p>
 *
 * @param values the input array
 * @return the population variance of the values or Double.NaN if the array is empty
 * @throws MathIllegalArgumentException if the array is null
 */
public static double populationVariance(final double[] values)
throws MathIllegalArgumentException {
  return new Variance(false).evaluate(values);
}

代码示例来源:origin: org.apache.commons/commons-math3

/**
 * 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>MathIllegalArgumentException</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 MathIllegalArgumentException if the array is null
 */
@Override
public double evaluate(final double[] values) throws MathIllegalArgumentException {
  if (values == null) {
    throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY);
  }
  return evaluate(values, 0, values.length);
}

代码示例来源:origin: org.apache.commons/commons-math3

/**
 * 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>MathIllegalArgumentException</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 MathIllegalArgumentException 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)
throws MathIllegalArgumentException  {
  return FastMath.sqrt(variance.evaluate(values, begin, length));
}

代码示例来源:origin: org.apache.commons/commons-math3

/**
 * Returns the <a href="http://en.wikibooks.org/wiki/Statistics/Summary/Variance">
 * population variance</a> 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.math3.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>MathIllegalArgumentException</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 population variance of the values or Double.NaN if length = 0
 * @throws MathIllegalArgumentException if the array is null or the array index
 *  parameters are not valid
 */
public static double populationVariance(final double[] values, final int begin,
    final int length) throws MathIllegalArgumentException {
  return new Variance(false).evaluate(values, begin, length);
}

代码示例来源:origin: org.apache.commons/commons-math3

/**
 * 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>MathIllegalArgumentException</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 MathIllegalArgumentException if the array is null
 */
public double evaluate(final double[] values, final double mean)
throws MathIllegalArgumentException  {
  return FastMath.sqrt(variance.evaluate(values, mean));
}

代码示例来源:origin: org.apache.commons/commons-math3

/**
 * Returns the <a href="http://en.wikibooks.org/wiki/Statistics/Summary/Variance">
 * population variance</a> 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.math3.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>MathIllegalArgumentException</code> if the array is null.</p>
 *
 * @param values the input array
 * @param mean the precomputed mean value
 * @return the population variance of the values or Double.NaN if the array is empty
 * @throws MathIllegalArgumentException if the array is null
 */
public static double populationVariance(final double[] values, final double mean)
throws MathIllegalArgumentException {
  return new Variance(false).evaluate(values, mean);
}

代码示例来源:origin: org.apache.commons/commons-math3

/**
 * Returns the Standard Deviation of the entries in the specified portion of
 * 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
 * @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 MathIllegalArgumentException if the array is null or the array index
 *  parameters are not valid
 */
public double evaluate(final double[] values, final double mean,
    final int begin, final int length) throws MathIllegalArgumentException  {
  return FastMath.sqrt(variance.evaluate(values, mean, begin, length));
}

代码示例来源:origin: org.apache.commons/commons-math3

return new Variance(false).evaluate(values, mean, begin, length);

代码示例来源:origin: prestodb/presto

@Override
public Number getExpectedValue(int start, int length)
{
  if (length == 0) {
    return null;
  }
  double[] values = new double[length];
  for (int i = 0; i < length; i++) {
    values[i] = start + i;
  }
  Variance variance = new Variance(false);
  return variance.evaluate(values);
}

代码示例来源:origin: prestodb/presto

@Override
public Number getExpectedValue(int start, int length)
{
  if (length < 2) {
    return null;
  }
  double[] values = new double[length];
  for (int i = 0; i < length; i++) {
    values[i] = start + i;
  }
  Variance variance = new Variance();
  return variance.evaluate(values);
}

代码示例来源:origin: prestodb/presto

@Override
public Number getExpectedValue(int start, int length)
{
  if (length == 0) {
    return null;
  }
  double[] values = new double[length];
  for (int i = 0; i < length; i++) {
    values[i] = start + i;
  }
  Variance variance = new Variance(false);
  return variance.evaluate(values);
}

代码示例来源:origin: org.apache.commons/commons-math3

/**
 * Calculates the variance of the y values.
 *
 * @return Y variance
 */
protected double calculateYVariance() {
  return new Variance().evaluate(yVector.toArray());
}

代码示例来源:origin: prestodb/presto

@Override
public Number getExpectedValue(int start, int length)
{
  if (length < 2) {
    return null;
  }
  double[] values = new double[length];
  for (int i = 0; i < length; i++) {
    values[i] = start + i;
  }
  Variance variance = new Variance();
  return variance.evaluate(values);
}

代码示例来源:origin: linkedin/cruise-control

/**
 * The variance of the derived resources.
 * @return a non-null array where the ith index is the variance of RawAndDerivedResource.ordinal().
 */
public double[] variance() {
 RawAndDerivedResource[] resources = RawAndDerivedResource.values();
 double[][] utilization = utilizationMatrix();
 double[] variance = new double[resources.length];
 for (int resourceIndex = 0; resourceIndex < resources.length; resourceIndex++) {
  Variance varianceCalculator = new Variance();
  variance[resourceIndex] = varianceCalculator.evaluate(utilization[resourceIndex]);
 }
 return variance;
}

代码示例来源:origin: org.apache.commons/commons-math3

/**
 * Compute a covariance matrix from a matrix whose columns represent
 * covariates.
 * @param matrix input matrix (must have at least one column and two rows)
 * @param biasCorrected determines whether or not covariance estimates are bias-corrected
 * @return covariance matrix
 * @throws MathIllegalArgumentException if the matrix does not contain sufficient data
 */
protected RealMatrix computeCovarianceMatrix(RealMatrix matrix, boolean biasCorrected)
throws MathIllegalArgumentException {
  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;
}

相关文章