public void should_return_no_percentiles_if_there_is_not_enough_data() { var builder = new PsquareHistogramAlgorithmBuilder(); var percentiles = builder.GetPercentiles().ToList(); percentiles.Count.ShouldEqual(0); }
public void should_return_percentiles_for_given_data(Expectation expectation) { var builder = new PsquareHistogramAlgorithmBuilder(expectation.DesiredNumberOfBuckets); foreach (var datum in expectation.Values.ToArray()) { builder.AddValue(datum); } var percentiles = builder.GetPercentiles().ToList(); var roundedPercentiles = percentiles.Select(p => new Percentile(p.Rank, Math.Round(p.Value, 2))).ToList(); roundedPercentiles.ShouldBeEquivalentTo(expectation.ExpectedPercentiles, true); }
public void should_work_with_random_uniform_distribution() { var random = new Random(); var builder = new PsquareHistogramAlgorithmBuilder(); for (var i = 0; i < 1000000; ++i) { builder.AddValue(random.NextDouble() * 100); } var percentiles = builder.GetPercentiles().ToList(); Console.WriteLine("P² histogram"); var squaredErrors = new List <double>(); for (var i = 0; i < 9; ++i) { var deltaToPercentile = Math.Abs(percentiles[i].Value - ((i + 1) * 10)); deltaToPercentile.ShouldBeLessThan(0.15); Console.WriteLine("[" + percentiles[i].Rank + "] => " + percentiles[i].Value + " (" + deltaToPercentile + ")"); squaredErrors.Add(Math.Pow(deltaToPercentile, 2)); } Console.WriteLine("MSE: " + squaredErrors.Average()); }