public void should_work_with_random_uniform_distribution()
        {
            var random             = new Random();
            var desiredPercentiles = new double[] { 10, 20, 30, 40, 50, 60, 70, 80, 90 };
            var builder            = new ConstantErrorBasicCKMSBuilder(0.00001, desiredPercentiles);
            var referenceBuilder   = new NearestRankBuilder(desiredPercentiles);

            for (var i = 0; i < 10000; ++i)
            {
                var value = random.NextDouble() * 100;
                builder.AddValue(value);
                referenceBuilder.AddValue(value);
            }

            var percentiles          = builder.GetPercentiles().ToList();
            var referencePercentiles = referenceBuilder.GetPercentiles().ToList();

            Console.WriteLine("CKMS basic histogram");
            var squaredErrors = new List <double>();

            for (var i = 0; i < 9; ++i)
            {
                var deltaToPercentile = Math.Abs(percentiles[i].Value - referencePercentiles[i].Value);
                Console.WriteLine("[" + percentiles[i].Rank + "] => " + percentiles[i].Value + " (" + deltaToPercentile + ")");
                deltaToPercentile.ShouldBeLessThan(0.15);
                squaredErrors.Add(Math.Pow(deltaToPercentile, 2));
            }
            Console.WriteLine("MSE: " + squaredErrors.Average());
        }
Exemplo n.º 2
0
        public void should_work_with_sample_data(SampleFile sampleFile)
        {
            var builder = new NearestRankBuilder(new [] { 80, 90, 99, 99.9, 99.99, 99.999 });

            foreach (var line in File.ReadAllLines(sampleFile.Filename))
            {
                var value = double.Parse(line, CultureInfo.InvariantCulture);
                builder.AddValue(value);
            }

            builder.GetPercentiles().Select(p => (int)p.Value).ShouldBeEquivalentTo(sampleFile.ExpectedValues);
        }
Exemplo n.º 3
0
        public void should_return_percentiles_for_given_data(Expectation expectation)
        {
            var builder = new NearestRankBuilder(expectation.DesiredPercentiles);

            foreach (var datum in expectation.Values.Shuffle().ToArray())
            {
                builder.AddValue(datum);
            }

            var percentiles = builder.GetPercentiles().ToList();

            percentiles.ShouldBeEquivalentTo(expectation.ExpectedPercentiles, true);
        }
Exemplo n.º 4
0
        public void should_work_with_random_uniform_distribution()
        {
            var random  = new Random();
            var builder = new NearestRankBuilder();

            for (var i = 0; i < 1000000; ++i)
            {
                builder.AddValue(random.NextDouble() * 100);
            }

            var percentiles = builder.GetPercentiles().ToList();

            Console.WriteLine("Nearest rank");
            var squaredErrors = new List <double>();

            for (var i = 0; i < 9; ++i)
            {
                var deltaToPercentile = percentiles[i].Value - ((i + 1) * 10);
                deltaToPercentile.ShouldBeLessThan(0.1);
                Console.WriteLine("[" + percentiles[i].Rank + "] => " + percentiles[i].Value + " (" + deltaToPercentile + ")");
                squaredErrors.Add(Math.Pow(deltaToPercentile, 2));
            }
            Console.WriteLine("MSE: " + squaredErrors.Average());
        }