public static BestSoFarWithTies <TScore, TItem> GetInstance(Comparison <TScore> isBetter) { BestSoFarWithTies <TScore, TItem> bestSoFarWithTies = new BestSoFarWithTies <TScore, TItem>(); bestSoFarWithTies.IsBetter = isBetter; return(bestSoFarWithTies); }
//Picks randomly among tied values public static double Mode(this IEnumerable <double> values, ref Random random) { var query = from value in values group value by value into g select new { value = g.Key, count = g.Count() }; BestSoFarWithTies <int, double> bestSoFarWithTies = BestSoFarWithTies <int, double> .GetInstance(SpecialFunctions.IntGreaterThan); foreach (var pair in query) { bestSoFarWithTies.Compare(pair.count, pair.value); } double mode = bestSoFarWithTies.ChampList.SampleAtRandom(random); return(mode); }