当前位置: 首页>>代码示例>>Java>>正文


Java MathArrays.checkNonNegative方法代码示例

本文整理汇总了Java中org.apache.commons.math3.util.MathArrays.checkNonNegative方法的典型用法代码示例。如果您正苦于以下问题:Java MathArrays.checkNonNegative方法的具体用法?Java MathArrays.checkNonNegative怎么用?Java MathArrays.checkNonNegative使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.math3.util.MathArrays的用法示例。


在下文中一共展示了MathArrays.checkNonNegative方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkArray

import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
 * Checks to make sure that the input long[][] array is rectangular,
 * has at least 2 rows and 2 columns, and has all non-negative entries.
 *
 * @param in input 2-way table to check
 * @throws NullArgumentException if the array is null
 * @throws DimensionMismatchException if the array is not valid
 * @throws NotPositiveException if the array contains any negative entries
 */
private void checkArray(final long[][] in)
    throws NullArgumentException, DimensionMismatchException,
    NotPositiveException {

    if (in.length < 2) {
        throw new DimensionMismatchException(in.length, 2);
    }

    if (in[0].length < 2) {
        throw new DimensionMismatchException(in[0].length, 2);
    }

    MathArrays.checkRectangular(in);
    MathArrays.checkNonNegative(in);

}
 
开发者ID:biocompibens,项目名称:SME,代码行数:26,代码来源:ChiSquareTest.java

示例2: g

import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
 * Computes the <a href="http://en.wikipedia.org/wiki/G-test">G statistic
 * for Goodness of Fit</a> comparing {@code observed} and {@code expected}
 * frequency counts.
 *
 * <p>This statistic can be used to perform a G test (Log-Likelihood Ratio
 * Test) evaluating the null hypothesis that the observed counts follow the
 * expected distribution.</p>
 *
 * <p><strong>Preconditions</strong>: <ul>
 * <li>Expected counts must all be positive. </li>
 * <li>Observed counts must all be &ge; 0. </li>
 * <li>The observed and expected arrays must have the same length and their
 * common length must be at least 2. </li></ul></p>
 *
 * <p>If any of the preconditions are not met, a
 * {@code MathIllegalArgumentException} is thrown.</p>
 *
 * <p><strong>Note:</strong>This implementation rescales the
 * {@code expected} array if necessary to ensure that the sum of the
 * expected and observed counts are equal.</p>
 *
 * @param observed array of observed frequency counts
 * @param expected array of expected frequency counts
 * @return G-Test statistic
 * @throws NotPositiveException if {@code observed} has negative entries
 * @throws NotStrictlyPositiveException if {@code expected} has entries that
 * are not strictly positive
 * @throws DimensionMismatchException if the array lengths do not match or
 * are less than 2.
 */
public double g(final double[] expected, final long[] observed)
        throws NotPositiveException, NotStrictlyPositiveException,
        DimensionMismatchException {

    if (expected.length < 2) {
        throw new DimensionMismatchException(expected.length, 2);
    }
    if (expected.length != observed.length) {
        throw new DimensionMismatchException(expected.length, observed.length);
    }
    MathArrays.checkPositive(expected);
    MathArrays.checkNonNegative(observed);

    double sumExpected = 0d;
    double sumObserved = 0d;
    for (int i = 0; i < observed.length; i++) {
        sumExpected += expected[i];
        sumObserved += observed[i];
    }
    double ratio = 1d;
    boolean rescale = false;
    if (FastMath.abs(sumExpected - sumObserved) > 10E-6) {
        ratio = sumObserved / sumExpected;
        rescale = true;
    }
    double sum = 0d;
    for (int i = 0; i < observed.length; i++) {
        final double dev = rescale ?
                FastMath.log((double) observed[i] / (ratio * expected[i])) :
                    FastMath.log((double) observed[i] / expected[i]);
        sum += ((double) observed[i]) * dev;
    }
    return 2d * sum;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:66,代码来源:GTest.java


注:本文中的org.apache.commons.math3.util.MathArrays.checkNonNegative方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。