コード例 #1
0
            public override double Generate(Random source)
            {
                double x = baseNormal.Generate(source);
                double y = gammaDistr.Generate(source);

                return((x / Math.Sqrt(y / DegreesOfFreedom) * ScaleCoefficient) + mean);
            }
コード例 #2
0
        protected override double[] GenerateRandomInternal(Random rnd)
        {
            double[,] ltf = Chol.LeftTriangularFactor;
            double[] result = new double[Dimension];
            double[] u      = Means;

            // TODO: I Don't remember, what happens here. I should check it out.
            // OK. I checked, it doesn't work properly...
            for (int i = 0; i < Dimension; i++)
            {
                result[i] = BaseNormal.Generate(rnd);

                // result[i] = _baseNormal.Generate(rnd) / Math.Sqrt(_baseGamma.Generate(rnd) / DegreesOfFreedom);
            }

            result = Matrix.Dot(ltf, result);

            double[] gammaSqrt = baseGamma.Generate(Dimension, rnd).Divide(DegreesOfFreedom).Sqrt();

            // from MATHlab function MVTRND(C,DF,N).
            result = Elementwise.Divide(result, gammaSqrt);

            // double[] chiSqrt = _baseChi.Generate(Dimension, rnd).Divide(DegreesOfFreedom).Sqrt();

            // result = Elementwise.Divide(result, chiSqrt); //from R func R/rmvt.R
            result = Elementwise.Add(result, u);

            return(result);
        }
コード例 #3
0
 private double Rnd2()
 {
     while (true)
     {
         double rval = _gamma.Generate();
         if (rval < T.X2 - T.X1)
         {
             return(T.X2 - rval);
         }
     }
 }
コード例 #4
0
        /// <summary>
        /// Generates random demand array.
        /// </summary>
        /// <param name="clients">Number of clients.</param>
        /// <returns>Demand array.</returns>
        public int[] GenerateDemands(int clients)
        {
            var demands = new int[clients];

            for (int i = 0; i < clients; i++)
            {
                var r = _gammaDistribution.Generate();
                demands[i] = (int)Math.Ceiling(r);
            }
            return(demands);
        }
コード例 #5
0
        public void GenerateTest5()
        {
            Accord.Math.Tools.SetupGenerator(1);

            var target  = new GammaDistribution(42, 0.1337);
            var samples = target.Generate(10000000);

            var actual = GammaDistribution.Estimate(samples);

            Assert.AreEqual(42, actual.Scale, 5e-2);
            Assert.AreEqual(0.1337, actual.Shape, 5e-4);
        }
コード例 #6
0
        public void GenerateTest6()
        {
            // https://github.com/accord-net/framework/issues/281
            Accord.Math.Random.Generator.Seed = 1;

            var target  = new GammaDistribution(1.5, 0.9);
            var samples = target.Generate(10000000);

            var actual = GammaDistribution.Estimate(samples);

            Assert.AreEqual(1.5, actual.Scale, 5e-2);
            Assert.AreEqual(0.9, actual.Shape, 5e-4);
        }
コード例 #7
0
        public void GenerateTest2()
        {
            Accord.Math.Tools.SetupGenerator(0);

            GammaDistribution target = new GammaDistribution(5, 2);

            double[] samples = target.Generate(10000000);

            var actual = GammaDistribution.Estimate(samples);

            Assert.AreEqual(5, actual.Scale, 1e-3);
            Assert.AreEqual(2, actual.Shape, 1e-3);
        }
コード例 #8
0
        public void GenerateTest4()
        {
            Accord.Math.Tools.SetupGenerator(1);

            GammaDistribution target = new GammaDistribution(0.4, 0.2);

            double[] samples = new double[10000000];
            for (int i = 0; i < samples.Length; i++)
            {
                samples[i] = target.Generate();
            }

            var actual = GammaDistribution.Estimate(samples);

            Assert.AreEqual(0.4, actual.Scale, 1e-3);
            Assert.AreEqual(0.2, actual.Shape, 1e-3);
        }
コード例 #9
0
 private double RndC2()
 {
     return(_gamma.Generate() + T.X2);
 }
コード例 #10
0
        public void GenerateTest3()
        {
            Accord.Math.Tools.SetupGenerator(1);

            GammaDistribution target = new GammaDistribution(4, 2);

            double[] samples = new double[1000000];
            for (int i = 0; i < samples.Length; i++)
                samples[i] = target.Generate();

            var actual = GammaDistribution.Estimate(samples);
            actual.Fit(samples);

            Assert.AreEqual(4, actual.Scale, 0.01);
            Assert.AreEqual(2, actual.Shape, 0.01);
        }
コード例 #11
0
        public void GenerateTest2()
        {
            Accord.Math.Tools.SetupGenerator(0);

            GammaDistribution target = new GammaDistribution(5, 2);

            double[] samples = target.Generate(1000000);

            var actual = GammaDistribution.Estimate(samples);
            actual.Fit(samples);

            Assert.AreEqual(5, actual.Scale, 0.02);
            Assert.AreEqual(2, actual.Shape, 0.01);
        }
コード例 #12
0
 public override double[] Generate(int samples, double[] result, Random source)
 {
     return(baseGamma.Generate(samples, result, source));
 }
コード例 #13
0
        public void GenerateTest6()
        {
            // https://github.com/accord-net/framework/issues/281
            Accord.Math.Random.Generator.Seed = 1;

            var target = new GammaDistribution(1.5, 0.9);
            var samples = target.Generate(10000000);

            var actual = GammaDistribution.Estimate(samples);
            Assert.AreEqual(1.5, actual.Scale, 5e-2);
            Assert.AreEqual(0.9, actual.Shape, 5e-4);
        }
コード例 #14
0
        public void GenerateTest5()
        {
            Accord.Math.Tools.SetupGenerator(1);

            var target = new GammaDistribution(42, 0.1337);
            var samples = target.Generate(10000000);

            var actual = GammaDistribution.Estimate(samples);
            Assert.AreEqual(42, actual.Scale, 5e-2);
            Assert.AreEqual(0.1337, actual.Shape, 5e-4);
        }