/// <summary> /// Genetic mutation for auxiliary argument data. /// </summary> public void MutateAuxArgs(double[] auxArgs, XorShiftRandom rng, ZigguratGaussianSampler gaussianSampler, double connectionWeightRange) { // Mutate center. // Add gaussian ditribution sample and clamp result to +-connectionWeightRange. double tmp = auxArgs[0] + gaussianSampler.NextSample(0, _auxArgsMutationSigmaCenter); if (tmp < -connectionWeightRange) { auxArgs[0] = -connectionWeightRange; } else if (tmp > connectionWeightRange) { auxArgs[0] = connectionWeightRange; } else { auxArgs[0] = tmp; } // Mutate radius. // Add gaussian ditribution sample and clamp result to [0,1] tmp = auxArgs[1] + gaussianSampler.NextSample(0, _auxArgsMutationSigmaRadius); if (tmp < 0.0) { auxArgs[1] = 0.0; } else if (tmp > 1.0) { auxArgs[1] = 1.0; } else { auxArgs[1] = tmp; } }
//public static float NextGaussianFloat() //{ // float U, u, v, S; // do // { // u = 2 * Random.value - 1; // v = 2 * Random.value - 1; // S = u * u + v * v; // } while (S>=1.0); // float fac = Mathf.Sqrt(-2 * Mathf.Log(S) / S); // return u * fac; //} public static int RandomGaussianIntInRange(int min, int max) //using ZigguratGaussianSampler.cs, for gold and exp { int mean = (min + max) / 2; int sigma = (max - mean) / 3; int returnValue; do { returnValue = (int)normalSampler.NextSample(mean, sigma); } while (returnValue < min || returnValue > max); return(returnValue); }
public static float GaussRandom() { if (!gaussianSamplerInitialized) { NewGaussSeed(); } return((float)gaussianSampler.NextSample()); }
/// <summary> /// Return a gaussian distributed random integer in the range [min,max] /// Note: standard deviation will be (max-min/6.0) /// </summary> /// <param name="min">Inclusive minimum of range</param> /// <param name="max">Inclusive maximum of range</param> /// <returns></returns> public int Inclusive(int min, int max) { var range = max - min; var mean = (max + min) / 2.0; var sigma = range / 3.0; var gaussian = (int)_ziggurt.NextSample(mean, sigma); if (gaussian > max) { return(max); } if (gaussian < min) { return(min); } return(gaussian); }
public void EstimateMedianOfGaussianDistribution() { var gaussianRng = new ZigguratGaussianSampler(); var testData = Enumerable.Range(0, 1000).Select(i => Math.Abs((int)gaussianRng.NextSample(500, 250))).ToList(); var actualMedian = FrugalQuantile.ShuffledEstimate(testData, 1, 2, FrugalQuantile.LinearStepAdjuster); var msg = $"Estimated median of numbers following a Gaussian distribution is {actualMedian}, should be near 500"; Debug.WriteLine(msg); Assert.IsTrue(actualMedian >= 450 && actualMedian <= 550, msg); }
//нормальное распределение(зиккурат-алогритм) public static double ZigguratNormalDistibution() { ZigguratGaussianSampler zig = new ZigguratGaussianSampler(); Random rnd = new Random(); var res = zig.NextSample(); if (Math.Abs(res) > 1) { return(rnd.NextDouble()); } return(Math.Abs(res)); }
/// <summary> /// Genetic mutation for auxiliary argument data. /// </summary> public void MutateAuxArgs(double[] auxArgs, XorShiftRandom rng, ZigguratGaussianSampler gaussianSampler, double connectionWeightRange) { // Mutate center. // Add gaussian ditribution sample and clamp result to +-connectionWeightRange. double tmp = auxArgs[0] + gaussianSampler.NextSample(0, _auxArgsMutationSigmaCenter); if(tmp < -connectionWeightRange) { auxArgs[0] = -connectionWeightRange; } else if(tmp > connectionWeightRange) { auxArgs[0] = connectionWeightRange; } else { auxArgs[0] = tmp; } // Mutate radius. // Add gaussian ditribution sample and clamp result to [0,1] tmp = auxArgs[1] + gaussianSampler.NextSample(0, _auxArgsMutationSigmaRadius); if(tmp < 0.0) { auxArgs[1] = 0.0; } else if(tmp > 1.0) { auxArgs[1] = 1.0; } else { auxArgs[1] = tmp; } }