Example #1
0
        /// <summary>
        ///   Estimates a new Beta distribution from a set of observations.
        /// </summary>
        ///
        public static BetaDistribution Estimate(double[] samples, BetaOptions options)
        {
            var beta = new BetaDistribution(1, 1);

            beta.Fit(samples, (double[])null, options);
            return(beta);
        }
Example #2
0
        /// <summary>
        ///   Estimates a new Beta distribution from a set of weighted observations.
        /// </summary>
        ///
        public static BetaDistribution Estimate(double[] samples, double[] weights)
        {
            var beta = new BetaDistribution(1, 1);

            beta.Fit(samples, weights, null);
            return(beta);
        }
        public void BetaMLEFit_IntWeights()
        {
            double[] x = { 1.0, 0.1, 0.5, 0.3, 0.5, 0.8, 0.6, 0.7, 0.9, 0.9, 0.9 };
            int[] w = { 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 2 };

            BetaDistribution target = new BetaDistribution(0, 1);


            var options = new BetaOptions()
            {
                Method = BetaEstimationMethod.MaximumLikelihood
            };

            target.Fit(x, w, options);

            Assert.AreEqual(1.1810718232044195, target.Alpha);
            Assert.AreEqual(0.60843093922651903, target.Beta, 1e-10);
        }
        public void BetaMLEFit_RealWeights()
        {
            double[] x = { 1.0, 0.1, 0.5, 0.3, 0.5, 0.8, 0.6, 0.7, 0.9, 0.9, 0.9 };
            int[] w = { 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 2 };

            BetaDistribution target = new BetaDistribution(0, 1);


            var options = new BetaOptions()
            {
                Method = BetaEstimationMethod.MaximumLikelihood
            };

            target.Fit(x, w.ToDouble(), options);

            Assert.AreEqual(1.1401591160220996, target.Alpha);
            Assert.AreEqual(0.58735469613259694, target.Beta);
        }
        public void BetaMLEFitTest1()
        {
            double[] x = samples;

            {
                BetaDistribution target = new BetaDistribution(0, 1);
                var options = new BetaOptions() { Method = BetaEstimationMethod.Moments };
                target.Fit(x, options);

                Assert.AreEqual(1, target.Alpha, 0.04);
                Assert.AreEqual(3, target.Beta, 0.5);
            }

            {
                BetaDistribution target = new BetaDistribution(0, 1);
                var options = new BetaOptions() { Method = BetaEstimationMethod.MaximumLikelihood };
                target.Fit(x, options);

                Assert.AreEqual(1, target.Alpha, 0.04);
                Assert.AreEqual(3, target.Beta, 0.55);
            }
        }
        public void BetaFit_IntWeights()
        {
            double[] x = { 1.0, 0.1, 0.5, 0.3, 0.5, 0.8, 0.6, 0.7, 0.9, 0.9, 0.9 };
            int[] w = { 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 2 };

            BetaDistribution target = new BetaDistribution(0, 1);

            target.Fit(x, w);

            Assert.AreEqual(1.1810718232044195, target.Alpha);
            Assert.AreEqual(0.60843093922651903, target.Beta, 1e-8);
        }
        public void BetaFit_RealWeights()
        {
            double[] x = { 1.0, 0.1, 0.5, 0.3, 0.5, 0.8, 0.6, 0.7, 0.9, 0.9, 0.9 };
            int[] w = { 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 2 };

            BetaDistribution target = new BetaDistribution(0, 1);

            target.Fit(x, w.ToDouble());

            Assert.AreEqual(1.1401591160220996, target.Alpha);
            Assert.AreEqual(0.58735469613259694, target.Beta);
        }
        public void BetaFitTest1()
        {
            double[] x = { 0.1, 0.5, 0.3, 0.8, 0.6, 0.7, 0.9, 0.9, 0.9, 0.9 };

            BetaDistribution target = new BetaDistribution(0, 1);

            target.Fit(x);

            Assert.AreEqual(1.1810718232044195, target.Alpha);
            Assert.AreEqual(0.60843093922651903, target.Beta);
        }