private static void CalculateScores(List <Game> games) { var confidence = WilsonScore.pnormaldist(0.95); foreach (var game in games) { game.AllTotalReviews = game.AllPositiveReviews + game.AllNegativeReviews; game.WilsonScore = WilsonScore.Score(game.AllPositiveReviews, game.AllTotalReviews, confidence) * 100; } }
public void MatchesAnotherImplementation() { for (var confidence = 0.01; confidence <= 0.99; confidence += 0.01) { var z = Normal.InvCDF( mean: 0, stddev: 1, p: 1 - (1 - confidence) / 2); for (uint total = 1; total < 100; ++total) { for (uint up = 0; up <= total; ++up) { var myScore = WilsonScore.CalculateWithZScore(up, total, z); var theirScore = Wilson.Score(up, total, z); var difference = Math.Abs(theirScore - myScore); Assert.IsTrue( difference <= 1E-15, $"Difference was {difference}: my score: {myScore}; their score: {theirScore}; up/total: {up}/{total}; confidence: {confidence}"); } } } }