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


Java MathArrays.normalizeArray方法代码示例

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


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

示例1: EnumeratedDistribution

import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
 * Create an enumerated distribution using the given random number generator
 * and probability mass function enumeration.
 *
 * @param rng random number generator.
 * @param pmf probability mass function enumerated as a list of <T, probability>
 * pairs.
 * @throws NotPositiveException if any of the probabilities are negative.
 * @throws NotFiniteNumberException if any of the probabilities are infinite.
 * @throws NotANumberException if any of the probabilities are NaN.
 * @throws MathArithmeticException all of the probabilities are 0.
 */
public EnumeratedDistribution(final RandomGenerator rng, final List<Pair<T, Double>> pmf)
    throws NotPositiveException, MathArithmeticException, NotFiniteNumberException, NotANumberException {
    random = rng;

    singletons = new ArrayList<T>(pmf.size());
    final double[] probs = new double[pmf.size()];

    for (int i = 0; i < pmf.size(); i++) {
        final Pair<T, Double> sample = pmf.get(i);
        singletons.add(sample.getKey());
        final double p = sample.getValue();
        if (p < 0) {
            throw new NotPositiveException(sample.getValue());
        }
        if (Double.isInfinite(p)) {
            throw new NotFiniteNumberException(p);
        }
        if (Double.isNaN(p)) {
            throw new NotANumberException();
        }
        probs[i] = p;
    }

    probabilities = MathArrays.normalizeArray(probs, 1.0);

    cumulativeProbabilities = new double[probabilities.length];
    double sum = 0;
    for (int i = 0; i < probabilities.length; i++) {
        sum += probabilities[i];
        cumulativeProbabilities[i] = sum;
    }
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:45,代码来源:EnumeratedDistribution.java

示例2: initializeMembershipMatrix

import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
 * Initialize the membership matrix with random values.
 */
private void initializeMembershipMatrix() {
    for (int i = 0; i < points.size(); i++) {
        for (int j = 0; j < k; j++) {
            membershipMatrix[i][j] = random.nextDouble();
        }
        membershipMatrix[i] = MathArrays.normalizeArray(membershipMatrix[i], 1.0);
    }
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:12,代码来源:FuzzyKMeansClusterer.java


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