本文整理汇总了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;
}
}
示例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);
}
}