Ejemplo n.º 1
0
        public static byte[] SerializeFrugal(this FrugalQuantile estimator, FrugalSerializer serializer)
        {
            using (var stream = new MemoryStream())
            {
                serializer.Serialize(stream, estimator);

                return(stream.ToArray());
            }
        }
        public void EstimateMedianOfOneThousandIntegers()
        {
            //var actualMedian = FrugalQuantile.ShuffledEstimate(Enumerable.Range(0, 1000).ToList(), 1,2, FrugalQuantile.ConstantStepAdjuster);
            var actualMedian = FrugalQuantile.ShuffledEstimate(Enumerable.Range(0, 1000).ToList(), 1, 2, FrugalQuantile.LinearStepAdjuster);

            var msg = $"Estimated median of one thousand integers at 500 is {actualMedian}, should be near 500";

            Debug.WriteLine(msg);
            Assert.IsTrue(actualMedian >= 450 && actualMedian <= 550, msg);
        }
        public void EstimateMedianOfGaussianDistribution()
        {
            var gaussianRng  = new ZigguratGaussianSampler();
            var testData     = Enumerable.Range(0, 1000).Select(i => Math.Abs((int)gaussianRng.NextSample(500, 250))).ToList();
            var actualMedian = FrugalQuantile.ShuffledEstimate(testData, 1, 2, FrugalQuantile.LinearStepAdjuster);

            var msg = $"Estimated median of numbers following a Gaussian distribution is {actualMedian}, should be near 500";

            Debug.WriteLine(msg);
            Assert.IsTrue(actualMedian >= 450 && actualMedian <= 550, msg);
        }