Java examples for java.lang:float
Get the weighted average of the scores computed.
import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; public class Main{ /**//from w w w .java 2 s .co m * Get the weighted average of the scores computed. */ public static double getWeightedScore(List<Double> scores, List<Double> scoreWeights) { double fscore = 0.0; if (scores == null || scores.size() == 0) { return fscore; } int nScores = scores.size(); if (scoreWeights == null || scoreWeights.size() == 0 || nScores != scoreWeights.size()) { return ((double) VectorUtils.sum(scores)) / nScores; } double tScoreWt = VectorUtils.sum(scoreWeights); for (int i = 0; i < nScores; i++) { fscore += (((double) scoreWeights.get(i)) / tScoreWt) * scores.get(i); } return fscore; } }