public void SampleStandard()
 {
     for (int i = 0; i < __loops; i++)
     {
         ZigguratGaussian.Sample(_rng);
     }
 }
示例#2
0
        /// <summary>
        /// Genetic mutation for auxiliary argument data.
        /// </summary>
        public void MutateAuxArgs(double[] auxArgs, IRandomSource rng, double connectionWeightRange)
        {
            // Mutate centre.
            // Add Gaussian distribution sample and clamp result to +-connectionWeightRange.
            double tmp = auxArgs[0] + ZigguratGaussian.Sample(rng, 0, _auxArgsMutationSigmaCenter);

            if (tmp < -connectionWeightRange)
            {
                auxArgs[0] = -connectionWeightRange;
            }
            else if (tmp > connectionWeightRange)
            {
                auxArgs[0] = connectionWeightRange;
            }
            else
            {
                auxArgs[0] = tmp;
            }

            // Mutate radius.
            // Add Gaussian distribution sample and clamp result to [0,1]
            tmp = auxArgs[1] + ZigguratGaussian.Sample(rng, 0, _auxArgsMutationSigmaCenter);
            if (tmp < 0.0)
            {
                auxArgs[1] = 0.0;
            }
            else if (tmp > 1.0)
            {
                auxArgs[1] = 1.0;
            }
            else
            {
                auxArgs[1] = tmp;
            }
        }
示例#3
0
        // --- Methods manipulating CheckResults
        public static void InitializeCheckResults()
        {
            Mod.Log.Info?.Write($"Initializing a new random buffer of size:{ResultsToPrecalcuate}");
            Xoshiro256PlusRandomBuilder builder = new Xoshiro256PlusRandomBuilder();
            IRandomSource rng    = builder.Create();
            double        mean   = Mod.Config.Probability.Mu;
            double        stdDev = Mod.Config.Probability.Sigma;

            ZigguratGaussian.Sample(rng, mean, stdDev, CheckResults);
            CheckResultIdx = 0;
        }
        public double SampleStandard()
        {
            double sum = 0f;

            for (int i = 0; i < __loops; i++)
            {
                sum += ZigguratGaussian.Sample(_rng);
            }

            return(sum);
        }
示例#5
0
        public void TestSampleBounds()
        {
            Xoshiro256PlusRandomBuilder builder = new Xoshiro256PlusRandomBuilder();
            IRandomSource rng    = builder.Create();
            double        mean   = 0;
            double        stdDev = 4;

            double[] sampleBuf = new double[4096];
            ZigguratGaussian.Sample(rng, mean, stdDev, sampleBuf);

            Dictionary <int, int> frequency = new Dictionary <int, int>();

            foreach (double sample in sampleBuf)
            {
                int normalizedVal = 0;
                if (sample > 0)
                {
                    normalizedVal = (int)Math.Floor(sample);
                }
                else if (sample < 0)
                {
                    normalizedVal = (int)Math.Ceiling(sample);
                }
                if (frequency.ContainsKey(normalizedVal))
                {
                    frequency[normalizedVal] = frequency[normalizedVal] + 1;
                }
                else
                {
                    frequency[normalizedVal] = 1;
                }
            }

            List <int> orderedKeys = frequency.OrderByDescending(kvp => kvp.Key)
                                     .Select(kvp => kvp.Key)
                                     .ToList();

            foreach (int key in orderedKeys)
            {
                Console.WriteLine($"Value:{key} had frequency:{frequency[key]}");
            }
        }
示例#6
0
        public void TestTimeFor4096()
        {
            Xoshiro256PlusRandomBuilder builder = new Xoshiro256PlusRandomBuilder();
            IRandomSource rng    = builder.Create();
            double        mean   = 0;
            double        stdDev = 4;

            double[] sampleBuf = new double[8172];

            Stopwatch timer = new Stopwatch();

            for (int i = 0; i < 10; i++)
            {
                timer.Start();
                ZigguratGaussian.Sample(rng, mean, stdDev, sampleBuf);
                timer.Stop();
                Console.WriteLine($"Execution took: {timer.Elapsed} to generate 8172 elements.");
                timer.Reset();
            }
        }
 /// <summary>
 /// Gets a variable from the Gaussian distribution with the provided mean and standard deviation.
 /// </summary>
 public double SampleGaussianDistribution(double mu, double sigma)
 {
     return(ZigguratGaussian.Sample(_rng, mu, sigma));
 }