Java Code Examples for com.google.common.math.DoubleMath#mean()
The following examples show how to use
com.google.common.math.DoubleMath#mean() .
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: CorpusScorer.java From tac-kbp-eal with MIT License | 6 votes |
@Override public void finish() throws IOException { final ImmutableMap<Symbol, Double> scores = this.scores.build(); final ImmutableMap<Symbol, Integer> falsePositives = this.falsePositives.build(); final ImmutableMap<Symbol, Integer> truePositives = this.truePositives.build(); final ImmutableMap<Symbol, Integer> falseNegatives = this.falseNegatives.build(); // see guidelines section 7.3.1.1.3 for aggregating rules: outputDir.mkdirs(); final double meanScore = scores.isEmpty()?Double.NaN:DoubleMath.mean(scores.values()); Files.asCharSink(new File(outputDir, "linearScore.txt"), Charsets.UTF_8) .write(Double.toString(meanScore)); for (final Symbol queryId : scores.keySet()) { final File queryDir = new File(outputDir, queryId.asString()); queryDir.mkdirs(); final File queryScoreFile = new File(queryDir, "score.txt"); // avoid dividing by zero final double normalizer = Math.max(truePositives.get(queryId) + falseNegatives.get(queryId), 1); // see guidelines referenced above // pretends that the corpus is a single document Files.asCharSink(queryScoreFile, Charsets.UTF_8).write(String .format(SCORE_PATTERN, truePositives.get(queryId), falsePositives.get(queryId), falseNegatives.get(queryId), 100 * scores.get(queryId) / normalizer)); } }
Example 2
Source File: BloodTest.java From xDrip with GNU General Public License v3.0 | 4 votes |
public static String evaluateAccuracy(long period) { // CACHE?? final List<BloodTest> bloodTests = latestForGraph(1000, JoH.tsl() - period, JoH.tsl() - AddCalibration.estimatedInterstitialLagSeconds); final List<Double> difference = new ArrayList<>(); final List<Double> plugin_difference = new ArrayList<>(); if ((bloodTests == null) || (bloodTests.size() == 0)) return null; final boolean show_plugin = true; final CalibrationAbstract plugin = (show_plugin) ? PluggableCalibration.getCalibrationPluginFromPreferences() : null; for (BloodTest bt : bloodTests) { final BgReading bgReading = BgReading.getForPreciseTimestamp(bt.timestamp + (AddCalibration.estimatedInterstitialLagSeconds * 1000), BgGraphBuilder.DEXCOM_PERIOD); if (bgReading != null) { final Calibration calibration = bgReading.calibration; if (calibration == null) { Log.d(TAG, "Calibration for bgReading is null! @ " + JoH.dateTimeText(bgReading.timestamp)); continue; } final double diff = Math.abs(bgReading.calculated_value - bt.mgdl); difference.add(diff); if (d) { Log.d(TAG, "Evaluate Accuracy: difference: " + JoH.qs(diff)); } final CalibrationAbstract.CalibrationData cd = (plugin != null) ? plugin.getCalibrationData(bgReading.timestamp) : null; if ((plugin != null) && (cd != null)) { final double plugin_diff = Math.abs(bt.mgdl - plugin.getGlucoseFromBgReading(bgReading, cd)); plugin_difference.add(plugin_diff); if (d) Log.d(TAG, "Evaluate Plugin Accuracy: " + BgGraphBuilder.unitized_string_with_units_static(bt.mgdl) + " @ " + JoH.dateTimeText(bt.timestamp) + " difference: " + JoH.qs(plugin_diff) + "/" + JoH.qs(plugin_diff * Constants.MGDL_TO_MMOLL, 2) + " calibration: " + JoH.qs(cd.slope, 2) + " " + JoH.qs(cd.intercept, 2)); } } } if (difference.size() == 0) return null; double avg = DoubleMath.mean(difference); Log.d(TAG, "Average accuracy: " + accuracyAsString(avg) + " (" + JoH.qs(avg, 5) + ")"); if (plugin_difference.size() > 0) { double plugin_avg = DoubleMath.mean(plugin_difference); Log.d(TAG, "Plugin Average accuracy: " + accuracyAsString(plugin_avg) + " (" + JoH.qs(plugin_avg, 5) + ")"); return accuracyAsString(plugin_avg) + " / " + accuracyAsString(avg); } return accuracyAsString(avg); }
Example 3
Source File: BloodTest.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
public static String evaluateAccuracy(long period) { // CACHE?? final List<BloodTest> bloodTests = latestForGraph(1000, JoH.tsl() - period, JoH.tsl() - AddCalibration.estimatedInterstitialLagSeconds); final List<Double> difference = new ArrayList<>(); final List<Double> plugin_difference = new ArrayList<>(); if ((bloodTests == null) || (bloodTests.size() == 0)) return null; final boolean show_plugin = true; final CalibrationAbstract plugin = (show_plugin) ? PluggableCalibration.getCalibrationPluginFromPreferences() : null; for (BloodTest bt : bloodTests) { final BgReading bgReading = BgReading.getForPreciseTimestamp(bt.timestamp + (AddCalibration.estimatedInterstitialLagSeconds * 1000), BgGraphBuilder.DEXCOM_PERIOD); if (bgReading != null) { final Calibration calibration = bgReading.calibration; if (calibration == null) { Log.d(TAG, "Calibration for bgReading is null! @ " + JoH.dateTimeText(bgReading.timestamp)); continue; } final double diff = Math.abs(bgReading.calculated_value - bt.mgdl); difference.add(diff); if (d) { Log.d(TAG, "Evaluate Accuracy: difference: " + JoH.qs(diff)); } final CalibrationAbstract.CalibrationData cd = (plugin != null) ? plugin.getCalibrationData(bgReading.timestamp) : null; if ((plugin != null) && (cd != null)) { final double plugin_diff = Math.abs(bt.mgdl - plugin.getGlucoseFromBgReading(bgReading, cd)); plugin_difference.add(plugin_diff); if (d) Log.d(TAG, "Evaluate Plugin Accuracy: " + BgGraphBuilder.unitized_string_with_units_static(bt.mgdl) + " @ " + JoH.dateTimeText(bt.timestamp) + " difference: " + JoH.qs(plugin_diff) + "/" + JoH.qs(plugin_diff * Constants.MGDL_TO_MMOLL, 2) + " calibration: " + JoH.qs(cd.slope, 2) + " " + JoH.qs(cd.intercept, 2)); } } } if (difference.size() == 0) return null; double avg = DoubleMath.mean(difference); Log.d(TAG, "Average accuracy: " + accuracyAsString(avg) + " (" + JoH.qs(avg, 5) + ")"); if (plugin_difference.size() > 0) { double plugin_avg = DoubleMath.mean(plugin_difference); Log.d(TAG, "Plugin Average accuracy: " + accuracyAsString(plugin_avg) + " (" + JoH.qs(plugin_avg, 5) + ")"); return accuracyAsString(plugin_avg) + " / " + accuracyAsString(avg); } return accuracyAsString(avg); }
Example 4
Source File: ExampleCoverage.java From api-mining with GNU General Public License v3.0 | 4 votes |
private static double nanmean(final Collection<Double> values) { final List<Double> finiteValues = values.stream().filter(Double::isFinite).collect(Collectors.toList()); if (finiteValues.isEmpty()) return Double.NaN; return DoubleMath.mean(finiteValues); }
Example 5
Source File: AverageFromList.java From levelup-java-examples with Apache License 2.0 | 4 votes |
@Test public void average_from_list_of_numbers_with_google_guava () { double average = DoubleMath.mean(NUMBERS_FOR_AVERAGE); assertEquals(10, average, 0); }
Example 6
Source File: AverageFromArray.java From levelup-java-examples with Apache License 2.0 | 3 votes |
@Test public void calculate_average_of_array_guava () { double average = DoubleMath.mean(NUMBERS); assertEquals(35.36363636363637, average, 0); }
Example 7
Source File: GradePapers.java From levelup-java-exercises with Apache License 2.0 | 2 votes |
/** * Method should calculate the average scores * * @param grades * @return */ static double getTestScoreAverages (List<? extends Number> grades) { return DoubleMath.mean(grades); }