use of java.util.stream.IntStream in project flink by apache.
the class DescriptorProperties method extractMaxIndex.
private int extractMaxIndex(String key, String suffixPattern) {
// extract index and property keys
final String escapedKey = Pattern.quote(key);
final Pattern pattern = Pattern.compile(escapedKey + "\\.(\\d+)" + suffixPattern);
final IntStream indexes = properties.keySet().stream().flatMapToInt(k -> {
final Matcher matcher = pattern.matcher(k);
if (matcher.find()) {
return IntStream.of(Integer.valueOf(matcher.group(1)));
}
return IntStream.empty();
});
// determine max index
return indexes.max().orElse(-1);
}
use of java.util.stream.IntStream in project flink by apache.
the class CatalogPropertiesUtil method getCount.
/**
* Extracts the property count under the given key and suffix.
*
* <p>For example:
*
* <pre>
* schema.0.name, schema.1.name -> 2
* </pre>
*/
private static int getCount(Map<String, String> map, String key, String suffix) {
final String escapedKey = Pattern.quote(key);
final String escapedSuffix = Pattern.quote(suffix);
final String escapedSeparator = Pattern.quote(SEPARATOR);
final Pattern pattern = Pattern.compile(escapedKey + escapedSeparator + "(\\d+)" + escapedSeparator + escapedSuffix);
final IntStream indexes = map.keySet().stream().flatMapToInt(k -> {
final Matcher matcher = pattern.matcher(k);
if (matcher.find()) {
return IntStream.of(Integer.parseInt(matcher.group(1)));
}
return IntStream.empty();
});
return indexes.max().orElse(-1) + 1;
}
use of java.util.stream.IntStream in project pyramid by cheng-li.
the class LKBOutputCalculator method getLeafOutput.
@Override
public double getLeafOutput(double[] probabilities, double[] labels) {
double numerator = 0;
double denominator = 0;
IntStream intStream = IntStream.range(0, probabilities.length);
if (parallel) {
intStream = intStream.parallel();
}
numerator = intStream.mapToDouble(i -> labels[i] * probabilities[i]).sum();
IntStream intStream2 = IntStream.range(0, probabilities.length);
if (parallel) {
intStream2 = intStream2.parallel();
}
denominator = intStream2.mapToDouble(i -> Math.abs(labels[i]) * (1 - Math.abs(labels[i])) * probabilities[i]).sum();
// for (int i=0;i<probabilities.length;i++) {
// double label = labels[i];
// numerator += label*probabilities[i];
// denominator += Math.abs(label) * (1 - Math.abs(label))*probabilities[i];
// }
double out;
if (denominator == 0) {
out = 0;
} else {
out = ((numClasses - 1) * numerator) / (numClasses * denominator);
}
// todo does the threshold matter?
if (out > 1) {
out = 1;
}
if (out < -1) {
out = -1;
}
if (Double.isNaN(out)) {
throw new RuntimeException("leaf value is NaN");
}
if (Double.isInfinite(out)) {
throw new RuntimeException("leaf value is Infinite");
}
return out;
}
use of java.util.stream.IntStream in project pyramid by cheng-li.
the class LogisticLoss method updatePredictedCounts.
private void updatePredictedCounts() {
StopWatch stopWatch = new StopWatch();
if (logger.isDebugEnabled()) {
stopWatch.start();
}
IntStream intStream;
if (isParallel) {
intStream = IntStream.range(0, numParameters).parallel();
} else {
intStream = IntStream.range(0, numParameters);
}
intStream.forEach(i -> this.predictedCounts.set(i, calPredictedCount(i)));
if (logger.isDebugEnabled()) {
logger.debug("time spent on updatePredictedCounts = " + stopWatch);
}
}
use of java.util.stream.IntStream in project pyramid by cheng-li.
the class LogisticLoss method updateEmpricalCounts.
// todo removed isParallel
private void updateEmpricalCounts() {
IntStream intStream;
if (isParallel) {
intStream = IntStream.range(0, numParameters).parallel();
} else {
intStream = IntStream.range(0, numParameters);
}
intStream.forEach(i -> this.empiricalCounts.set(i, calEmpricalCount(i)));
}
Aggregations