Example usage for java.util IntSummaryStatistics getSum

List of usage examples for java.util IntSummaryStatistics getSum

Introduction

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

Prototype

public final long getSum() 

Source Link

Document

Returns the sum of values recorded, or zero if no values have been recorded.

Usage

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))]++;
    }//from www  .ja v  a  2 s.  c  om
    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 v  a 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}//from   w  w  w. jav a  2 s .c o 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);
    }
}