Ejemplo n.º 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 (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] = 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);
        }
Ejemplo n.º 2
0
 static void SamplesUnchecked(System.Random rnd, double[] values, double mu, double sigma)
 {
     Normal.SamplesUnchecked(rnd, values, mu, sigma);
     CommonParallel.For(0, values.Length, 4096, (a, b) =>
     {
         for (int i = a; i < b; i++)
         {
             values[i] = Math.Exp(values[i]);
         }
     });
 }
Ejemplo n.º 3
0
        static void SamplesUnchecked(System.Random rnd, double[] values, int freedom)
        {
            var standard = new double[values.Length * freedom];

            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 * freedom;
                    double sum = 0;
                    for (int j = 0; j < freedom; j++)
                    {
                        sum += standard[k + j] * standard[k + j];
                    }

                    values[i] = Math.Sqrt(sum);
                }
            });
        }
Ejemplo n.º 4
0
 static IEnumerable <double> SamplesUnchecked(System.Random rnd, double mu, double sigma)
 {
     return(Normal.SamplesUnchecked(rnd, mu, sigma).Select(Math.Exp));
 }