Example usage for java.util IntSummaryStatistics getMin

List of usage examples for java.util IntSummaryStatistics getMin

Introduction

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

Prototype

public final int getMin() 

Source Link

Document

Returns the minimum value recorded, or Integer.MAX_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());//from w  w  w  .  ja va2s .c o m
    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. jav a2s .  c o  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}/*from  w w  w .  ja  va 2s .  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  w  w.j av a 2 s  .c om
 */
@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);
    }
}