本文整理汇总了Java中com.google.common.math.DoubleMath.mean方法的典型用法代码示例。如果您正苦于以下问题:Java DoubleMath.mean方法的具体用法?Java DoubleMath.mean怎么用?Java DoubleMath.mean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.math.DoubleMath
的用法示例。
在下文中一共展示了DoubleMath.mean方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: finish
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
@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));
}
}
示例2: assertDistributionStatsMatchCalcFromSample
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
private static void assertDistributionStatsMatchCalcFromSample(Distribution distribution,
double[] samples) {
double wantedMean = DoubleMath.mean(samples);
double wantedSumSquareDeviations = 0.0;
for (int i = 0; i < samples.length; i++) {
wantedSumSquareDeviations += Math.pow((wantedMean - samples[i]), 2);
}
assertEquals(wantedSumSquareDeviations, distribution.getSumOfSquaredDeviation(), TOLERANCE);
assertEquals(samples.length, distribution.getCount());
assertEquals(wantedMean, distribution.getMean(), 1e-5);
assertEquals(Ordering.<Double>natural().max(Doubles.asList(samples)).doubleValue(),
distribution.getMaximum(), TOLERANCE);
assertEquals(Ordering.<Double>natural().min(Doubles.asList(samples)).doubleValue(),
distribution.getMinimum(), TOLERANCE);
}
示例3: getR2
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
public static Double getR2(double sse, List<Double> targetValues) {
if (targetValues.size() < 2) {
return null;
}
double targetMean = DoubleMath.mean(targetValues);
double targetTotalSumOfSquares = targetValues.stream().mapToDouble(v -> Math.pow(v - targetMean, 2.0)).sum();
double rSquared = 1 - sse / targetTotalSumOfSquares;
return Math.max(rSquared, 0.0);
}
示例4: evaluateAccuracy
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
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);
}
示例5: average_from_list_of_numbers_with_google_guava
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
@Test
public void average_from_list_of_numbers_with_google_guava () {
double average = DoubleMath.mean(NUMBERS_FOR_AVERAGE);
assertEquals(10, average, 0);
}
示例6: calculate_average_of_array_guava
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
@Test
public void calculate_average_of_array_guava () {
double average = DoubleMath.mean(NUMBERS);
assertEquals(35.36363636363637, average, 0);
}
示例7: getConcentration
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
/**
* Returns the concentration level based on the internal values
* @return
*/
public synchronized float getConcentration(){
return (float) DoubleMath.mean(this.mConcentrationBuffer);
}
示例8: getTestScoreAverages
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
/**
* Method should calculate the average scores
*
* @param grades
* @return
*/
static double getTestScoreAverages (List<? extends Number> grades) {
return DoubleMath.mean(grades);
}