Example usage for java.util IntSummaryStatistics getMax

List of usage examples for java.util IntSummaryStatistics getMax

Introduction

In this page you can find the example usage for java.util IntSummaryStatistics getMax.

Prototype

public final int getMax() 

Source Link

Document

Returns the maximum value recorded, or Integer.MIN_VALUE if no values have been recorded.

Usage

From source file:edu.umd.umiacs.clip.tools.classifier.ConfusionMatrix.java

public static ConfusionMatrix loadLibSVM(String goldPath, String predPath, double... cutoffs) {
    int[] gold = readAllLines(goldPath).stream().mapToInt(line -> new Integer(line.split("\\s+")[0])).toArray();
    IntSummaryStatistics stats = Arrays.stream(gold).summaryStatistics();
    double cutoff = stats.getMin() == stats.getMax() ? cutoffs[0] : ((stats.getMax() + stats.getMin()) / 2);
    List<Boolean> goldList = Arrays.stream(gold).boxed().map(i -> i > cutoff).collect(toList());
    List<Boolean> predList = readAllLines(predPath).stream().map(pred -> new Double(pred) > cutoff)
            .collect(toList());// www  .  java 2  s .  c  om
    return new ConfusionMatrix(goldList, predList);
}

From source file:com.cloudera.oryx.app.serving.als.model.LocalitySensitiveHashTest.java

private static void doTestHashDistribution(int features, double sampleRate, int numCores) {
    LocalitySensitiveHash lsh = new LocalitySensitiveHash(sampleRate, features, numCores);
    int numHashes = lsh.getNumHashes();
    RandomGenerator random = RandomManager.getRandom();
    int[] counts = new int[1 << numHashes];
    int trials = 100_000;
    for (int i = 0; i < trials; i++) {
        counts[lsh.getIndexFor(VectorMath.randomVectorF(features, random))]++;
    }//  w w w  .j  a v a 2  s .  co m
    log.info("{}", Arrays.toString(counts));

    IntSummaryStatistics stats = Arrays.stream(counts).summaryStatistics();
    log.info("Total {} / Max {} / Min {}", stats.getSum(), stats.getMax(), stats.getMin());
    assertEquals(trials, stats.getSum());
    assertLessOrEqual(stats.getMax(), 2 * stats.getMin());
}

From source file:eu.cloudwave.wp5.feedbackhandler.aggregations.strategies.SimpleRequestAggregationStrategyImpl.java

/**
 * {@inheritDoc}//w  w w.  j  a v  a2  s  .co m
 */
@Override
public RequestAggregationValues aggregate(RequestCollector requests) {

    IntSummaryStatistics stats = requests.getReqTimestamps().stream()
            .collect(Collectors.groupingBy(
                    timestamp -> DateUtils.round(new Date(timestamp), timestampAggregation),
                    Collectors.counting()))
            .values().stream().mapToInt(p -> toInt(p)).summaryStatistics();

    return new RequestAggregationValuesImpl(stats.getMin(), stats.getMax(), stats.getAverage(), stats.getSum(),
            stats.getCount());
}

From source file:eu.cloudwave.wp5.feedbackhandler.aggregations.strategies.RequestAggregationStrategyImpl.java

/**
 * {@inheritDoc}/* w  ww.  ja va2  s .co m*/
 */
@Override
public RequestAggregationValues aggregate(RequestCollector requests) {
    double expectedCount = getExpectedNumberOfMeasurementValueGroups();

    /*
     * Group by aggregation interval and create summary statistics with min, avg, max and count
     */
    Collection<Long> groupedByAggregationInterval = requests.getReqTimestamps().stream()
            .collect(Collectors.groupingBy(
                    timestamp -> DateUtils.round(new Date(timestamp), timestampAggregation),
                    Collectors.counting()))
            .values();
    int calculatedCount = groupedByAggregationInterval.size();

    try {
        if (calculatedCount != 0) {
            // use integer summaryStatistics to get min, avg, max
            IntSummaryStatistics stats = groupedByAggregationInterval.stream().mapToInt(p -> toInt(p))
                    .summaryStatistics();

            // no time range selected, just return int summary
            if (expectedCount == 0) {
                return new RequestAggregationValuesImpl(stats.getMin(), stats.getMax(), stats.getAverage(),
                        stats.getSum(), stats.getCount());
            } else {
                // if calculated count != expected count --> adjust minimum, average and count value
                if (Double.compare(calculatedCount, expectedCount) != 0) {
                    double newAverage = (double) (stats.getSum() / expectedCount);
                    return new RequestAggregationValuesImpl(0, stats.getMax(), newAverage, stats.getSum(),
                            (int) expectedCount);
                } else {
                    return new RequestAggregationValuesImpl(stats.getMin(), stats.getMax(), stats.getAverage(),
                            stats.getSum(), (int) expectedCount);
                }
            }
        } else {
            return new RequestAggregationValuesImpl(0, 0, 0, 0, 0);
        }
    } catch (ArithmeticException e) {
        System.out.println(e.getMessage());
        return new RequestAggregationValuesImpl(0, 0, 0, 0, 0);
    }
}