示例#1
0
        internal static void SamplesUnchecked(System.Random rnd, double[] values, double freedom)
        {
            // Use the simple method if the degrees of freedom is an integer anyway
            if (System.Math.Floor(freedom) == freedom && freedom < int.MaxValue)
            {
                var n        = (int)freedom;
                var standard = new double[values.Length * n];
                Normal.SamplesUnchecked(rnd, standard, 0.0, 1.0);
                CommonParallel.For(0, values.Length, 4096, (a, b) =>
                {
                    for (int i = a; i < b; i++)
                    {
                        int k      = i * n;
                        double sum = 0;
                        for (int j = 0; j < n; j++)
                        {
                            sum += standard[k + j] * standard[k + j];
                        }

                        values[i] = System.Math.Sqrt(sum);
                    }
                });
                return;
            }

            // Call the gamma function (see http://en.wikipedia.org/wiki/Gamma_distribution#Specializations
            // for a justification)
            Gamma.SamplesUnchecked(rnd, values, freedom / 2.0, .5);
        }
示例#2
0
 static void SamplesUnchecked(System.Random rnd, double[] values, double location, double scale, double freedom)
 {
     Gamma.SamplesUnchecked(rnd, values, 0.5 * freedom, 0.5);
     for (int i = 0; i < values.Length; i++)
     {
         values[i] = Normal.Sample(rnd, location, scale * System.Math.Sqrt(freedom / values[i]));
     }
 }
示例#3
0
 static void SamplesUnchecked(System.Random rnd, double[] values, double shape, double scale)
 {
     Gamma.SamplesUnchecked(rnd, values, shape, scale);
     CommonParallel.For(0, values.Length, 4096, (a, b) =>
     {
         for (int i = a; i < b; i++)
         {
             values[i] = 1.0 / values[i];
         }
     });
 }
示例#4
0
        internal static void SamplesUnchecked(System.Random rnd, double[] values, double a, double b)
        {
            var y = new double[values.Length];

            Gamma.SamplesUnchecked(rnd, values, a, 1.0);
            Gamma.SamplesUnchecked(rnd, y, b, 1.0);
            CommonParallel.For(0, values.Length, 4096, (aa, bb) =>
            {
                for (int i = aa; i < bb; i++)
                {
                    values[i] = values[i] / (values[i] + y[i]);
                }
            });
        }
示例#5
0
 static IEnumerable <double> SamplesUnchecked(System.Random rnd, double shape, double scale)
 {
     return(Gamma.SamplesUnchecked(rnd, shape, scale).Select(z => 1.0 / z));
 }
示例#6
0
 /// <summary>
 /// Fills an array with samples generated from the distribution.
 /// </summary>
 public void Samples(double[] values)
 {
     Gamma.SamplesUnchecked(_random, values, _shape, _rate);
 }