本文整理匯總了Java中java.util.stream.DoubleStream.iterator方法的典型用法代碼示例。如果您正苦於以下問題:Java DoubleStream.iterator方法的具體用法?Java DoubleStream.iterator怎麽用?Java DoubleStream.iterator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.stream.DoubleStream
的用法示例。
在下文中一共展示了DoubleStream.iterator方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: calculateRegionInfo
import java.util.stream.DoubleStream; //導入方法依賴的package包/類
/** {@inheritDoc} */
@Override public VarianceData calculateRegionInfo(DoubleStream s, int size) {
PrimitiveIterator.OfDouble itr = s.iterator();
int i = 0;
double mean = 0.0;
double m2 = 0.0;
// Here we calculate variance and mean by incremental computation.
while (itr.hasNext()) {
i++;
double x = itr.next();
double delta = x - mean;
mean += delta / i;
double delta2 = x - mean;
m2 += delta * delta2;
}
return new VarianceData(m2 / i, size, mean);
}
示例2: calculateRegionInfo
import java.util.stream.DoubleStream; //導入方法依賴的package包/類
/** {@inheritDoc} */
@Override public GiniData calculateRegionInfo(DoubleStream s, int l) {
PrimitiveIterator.OfDouble itr = s.iterator();
Map<Double, Integer> m = new HashMap<>();
int size = 0;
while (itr.hasNext()) {
size++;
m.compute(itr.next(), (a, i) -> i != null ? i + 1 : 1);
}
double c2 = m.values().stream().mapToDouble(v -> v * v).sum();
int[] cnts = new int[mapping.size()];
m.forEach((key, value) -> cnts[mapping.get(key)] = value);
return new GiniData(size != 0 ? 1 - c2 / (size * size) : 0.0, size, cnts, c2);
}