public void ValidateInverseCumulativeDistribution(double a, double b, double location, double scale, double x, double p)
        {
            var dist = new BetaScaled(a, b, location, scale);

            Assert.That(dist.InverseCumulativeDistribution(p), Is.EqualTo(x).Within(1e-6));
            Assert.That(BetaScaled.InvCDF(a, b, location, scale, p), Is.EqualTo(x).Within(1e-6));
        }
Example #2
0
        private BetaScaled GetPertDistribution(double min, double mostLikely,
                                               double max, Confidence confidence, System.Random randomSource = null)
        {
            var modepad             = 0.000000001;
            var lambda              = CalculateLambda(confidence);
            var mean                = (min + lambda * mostLikely + max) / (lambda + 2.0);
            var effectiveMostLikely = mostLikely;

            // ReSharper disable once CompareOfFloatsByEqualityOperator
            if (mostLikely - mean == 0.0)
            {
                effectiveMostLikely += modepad;
                mean = (min + lambda * effectiveMostLikely + max) / (lambda + 2.0);
            }

            var alpha = ((mean - min) * ((2.0 * effectiveMostLikely) - min - max)) /
                        ((effectiveMostLikely - mean) * (max - min));
            var beta = (alpha * (max - mean)) / (mean - min);

            if (BetaScaled.IsValidParameterSet(alpha, beta, min, max - min))
            {
                return(new BetaScaled(alpha, beta, min, max - min, randomSource));
            }
            else
            {
                return(null);
            }
        }
        public void ValidateDensityLn(double a, double b, double location, double scale, double x, double pdfln)
        {
            var n = new BetaScaled(a, b, location, scale);

            AssertHelpers.AlmostEqualRelative(pdfln, n.DensityLn(x), 5);
            AssertHelpers.AlmostEqualRelative(pdfln, BetaScaled.PDFLn(a, b, location, scale, x), 5);
        }
        public void CanSampleSequence()
        {
            var n   = new BetaScaled(2.0, 3.0, 0.0, 1.0);
            var ied = n.Samples();

            GC.KeepAlive(ied.Take(5).ToArray());
        }
        public void CanCreateBetaScaled(double a, double b, double location, double scale)
        {
            var n = new BetaScaled(a, b, location, scale);

            Assert.AreEqual(a, n.A);
            Assert.AreEqual(b, n.B);
            Assert.AreEqual(location, n.Location);
            Assert.AreEqual(scale, n.Scale);
        }
        private float Inheritance(double min, double max, double mode,
                                  double noise, Random rand)
        {
            //Get noise around inheritance using triangular ditribution
            double     Max          = Math.Min(mode + noise, max);
            double     Min          = Math.Max(mode - noise, min);
            BetaScaled Distribution = BetaScaled.PERT(Min, Max, mode, rand);

            return((float)Distribution.Sample());
        }
 //Functions for birth
 private float[] InitialDistributions(SimParams par, float noise, float initial, float max, float min)
 {
     float[] DistArray = new float[par.NumBirds];
     if (noise != 0)
     {
         float      Max  = Math.Min(initial + noise, max);
         float      Min  = Math.Max(initial - noise, min);
         BetaScaled Dist = BetaScaled.PERT(Min, Max, initial, par.Rand);
         for (int i = 0; i < par.NumBirds; i++)
         {
             DistArray[i] = (float)Dist.Sample();
         }
     }
     else
     {
         DistArray = Enumerable.Repeat(initial, par.NumBirds).ToArray();
     }
     return(DistArray);
 }
        public void ValidateMedianThrowsNotSupportedException()
        {
            var n = new BetaScaled(1.0, 1.0, 0.0, 1.0);

            Assert.Throws <NotSupportedException>(() => { var m = n.Median; });
        }
        public void CanSample()
        {
            var n = new BetaScaled(2.0, 3.0, 0.0, 1.0);

            n.Sample();
        }
 public void FailSampleSequenceStatic()
 {
     Assert.That(() => BetaScaled.Samples(new Random(0), 1.0, -1.0, 0.0, 1.0).First(), Throws.ArgumentException);
 }
        public void CanSampleSequenceStatic()
        {
            var ied = BetaScaled.Samples(new Random(0), 2.0, 3.0, 0.0, 1.0);

            GC.KeepAlive(ied.Take(5).ToArray());
        }
 public void CanSampleStatic()
 {
     BetaScaled.Sample(new Random(0), 2.0, 3.0, 0.0, 1.0);
 }
        public void ValidateMode(double a, double b, double location, double scale, double mode)
        {
            var n = new BetaScaled(a, b, location, scale);

            Assert.AreEqual(mode, n.Mode);
        }
        public void ValidateSkewness(double a, double b, double location, double scale, double skewness)
        {
            var n = new BetaScaled(a, b, location, scale);

            AssertHelpers.AlmostEqualRelative(skewness, n.Skewness, 14);
        }
        public void ValidateMean(double a, double b, double location, double scale, double mean)
        {
            var n = new BetaScaled(a, b, location, scale);

            Assert.AreEqual(mean, n.Mean);
        }
Example #16
0
 public void Initialize(Tuple <object, object, object> data)
 {
     export            = data;
     this.Distribution = BetaScaled.PERT((double)data.Item1, (double)data.Item2, (double)data.Item3);
 }
Example #17
0
 public BetaPertDistribution(double min, double max, double mostLikely)
 {
     this.Distribution = BetaScaled.PERT(min, max, mostLikely);
     export            = new Tuple <object, object, object>(min, max, mostLikely);
 }
        public void ValidateToString()
        {
            var n = new BetaScaled(1d, 2d, 0.0, 1.0);

            Assert.AreEqual("BetaScaled(α = 1, β = 2, μ = 0, σ = 1)", n.ToString());
        }
        public void ValidateMaximum()
        {
            var n = new BetaScaled(1.0, 1.0, 0.0, 1.0);

            Assert.AreEqual(1.0, n.Maximum);
        }