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


Java LocalizedFormats.NORMALIZE_NAN属性代码示例

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


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

示例1: normalizeArray

/**
 * Normalizes an array to make it sum to a specified value.
 * Returns the result of the transformation
 * <pre>
 *    x |-> x * normalizedSum / sum
 * </pre>
 * applied to each non-NaN element x of the input array, where sum is the
 * sum of the non-NaN entries in the input array.
 * <p>
 * Throws IllegalArgumentException if {@code normalizedSum} is infinite
 * or NaN and ArithmeticException if the input array contains any infinite elements
 * or sums to 0.
 * <p>
 * Ignores (i.e., copies unchanged to the output array) NaNs in the input array.
 *
 * @param values Input array to be normalized
 * @param normalizedSum Target sum for the normalized array
 * @return the normalized array.
 * @throws MathArithmeticException if the input array contains infinite
 * elements or sums to zero.
 * @throws MathIllegalArgumentException if the target sum is infinite or {@code NaN}.
 * @since 2.1
 */
public static double[] normalizeArray(double[] values, double normalizedSum)
    throws MathIllegalArgumentException, MathArithmeticException {
    if (Double.isInfinite(normalizedSum)) {
        throw new MathIllegalArgumentException(LocalizedFormats.NORMALIZE_INFINITE);
    }
    if (Double.isNaN(normalizedSum)) {
        throw new MathIllegalArgumentException(LocalizedFormats.NORMALIZE_NAN);
    }
    double sum = 0d;
    final int len = values.length;
    double[] out = new double[len];
    for (int i = 0; i < len; i++) {
        if (Double.isInfinite(values[i])) {
            throw new MathIllegalArgumentException(LocalizedFormats.INFINITE_ARRAY_ELEMENT, values[i], i);
        }
        if (!Double.isNaN(values[i])) {
            sum += values[i];
        }
    }
    if (sum == 0) {
        throw new MathArithmeticException(LocalizedFormats.ARRAY_SUMS_TO_ZERO);
    }
    for (int i = 0; i < len; i++) {
        if (Double.isNaN(values[i])) {
            out[i] = Double.NaN;
        } else {
            out[i] = values[i] * normalizedSum / sum;
        }
    }
    return out;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:54,代码来源:MathArrays.java

示例2: normalizeArray

/**
 * Normalizes an array to make it sum to a specified value.
 * Returns the result of the transformation <pre>
 *    x |-> x * normalizedSum / sum
 * </pre>
 * applied to each non-NaN element x of the input array, where sum is the
 * sum of the non-NaN entries in the input array.</p>
 *
 * <p>Throws IllegalArgumentException if {@code normalizedSum} is infinite
 * or NaN and ArithmeticException if the input array contains any infinite elements
 * or sums to 0.</p>
 *
 * <p>Ignores (i.e., copies unchanged to the output array) NaNs in the input array.</p>
 *
 * @param values Input array to be normalized
 * @param normalizedSum Target sum for the normalized array
 * @return the normalized array.
 * @throws MathArithmeticException if the input array contains infinite
 * elements or sums to zero.
 * @throws MathIllegalArgumentException if the target sum is infinite or {@code NaN}.
 * @since 2.1
 */
public static double[] normalizeArray(double[] values, double normalizedSum) {
    if (Double.isInfinite(normalizedSum)) {
        throw new MathIllegalArgumentException(LocalizedFormats.NORMALIZE_INFINITE);
    }
    if (Double.isNaN(normalizedSum)) {
        throw new MathIllegalArgumentException(LocalizedFormats.NORMALIZE_NAN);
    }
    double sum = 0d;
    final int len = values.length;
    double[] out = new double[len];
    for (int i = 0; i < len; i++) {
        if (Double.isInfinite(values[i])) {
            throw new MathIllegalArgumentException(LocalizedFormats.INFINITE_ARRAY_ELEMENT, values[i], i);
        }
        if (!Double.isNaN(values[i])) {
            sum += values[i];
        }
    }
    if (sum == 0) {
        throw new MathArithmeticException(LocalizedFormats.ARRAY_SUMS_TO_ZERO);
    }
    for (int i = 0; i < len; i++) {
        if (Double.isNaN(values[i])) {
            out[i] = Double.NaN;
        } else {
            out[i] = values[i] * normalizedSum / sum;
        }
    }
    return out;
}
 
开发者ID:jiaminghan,项目名称:droidplanner-master,代码行数:52,代码来源:MathArrays.java


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