com.google.common.math.Stats Java Examples

The following examples show how to use com.google.common.math.Stats. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Main.java    From Java-for-Data-Science with MIT License 5 votes vote down vote up
public void usingGuava() {
    // Using Google Guava to find mean
    Stats testStat = Stats.of(testData);
    double mean = testStat.mean();
    out.println("The mean is " + mean);

}
 
Example #2
Source File: BenchJdbcAvroJob.java    From dbeam with Apache License 2.0 4 votes vote down vote up
private String tsvMetrics() {
  final List<String> columns = newArrayList(
      "recordCount", "writeElapsedMs", "msPerMillionRows", "bytesWritten", "KbWritePerSec");
  final Collector<CharSequence, ?, String> tabJoining = Collectors.joining("\t");
  final Stream<String> lines =
      IntStream.range(0, this.metrics.size())
          .mapToObj(i ->
              String.format(
                  "run_%02d  \t%s",
                  i,
                  columns.stream()
                      .map(c -> String.format("% 10d",
                          Optional.of(this.metrics.get(i).get(c)).orElse(0L)))
                      .collect(tabJoining)));
  final List<Stats> stats =
      columns.stream()
          .map(c ->
              Stats.of(
                  (Iterable<Long>)
                      this.metrics.stream().map(m -> Optional.of(m.get(c)).orElse(0L))
                          ::iterator))
          .collect(Collectors.toList());
  final Map<String, Function<Stats, Double>> relevantStats =
      ImmutableMap.of(
          "max     ", Stats::max,
          "mean    ", Stats::mean,
          "min     ", Stats::min,
          "stddev  ", Stats::populationStandardDeviation);
  final Stream<String> statsSummary =
      relevantStats.entrySet().stream()
          .map(e ->
              String.format(
                  "%s\t%s",
                  e.getKey(),
                  stats.stream()
                      .map(e.getValue())
                      .map(v -> String.format("% 10.1f", v))
                      .collect(tabJoining)));
  return String.format("name    \t%12s\n%s",
      String.join("\t", columns),
      Stream.concat(lines, statsSummary)
          .collect(Collectors.joining("\n")));
}