/// <summary>
        ///   Constructs a new Gaussian Weight initialization.
        /// </summary>
        ///
        /// <param name="network">The activation network whose weights will be initialized.</param>
        /// <param name="stdDev">The standard deviation to be used. Common values lie in the 0.001-
        /// 0.1 range. Default is 0.1.</param>
        ///
        public GaussianWeights(ActivationNetwork network, double stdDev = 0.1)
        {
            this.network = network;

            this.random = new GaussianGenerator(0f, (float)stdDev, Accord.Math.Tools.Random.Next());

            this.UpdateThresholds = false;
        }
        /// <summary>
        ///   Constructs a new Gaussian Weight initialization.
        /// </summary>
        /// 
        /// <param name="network">The activation network whose weights will be initialized.</param>
        /// <param name="stdDev">The standard deviation to be used. Common values lie in the 0.001-
        /// 0.1 range. Default is 0.1.</param>
        /// 
        public GaussianWeights(ActivationNetwork network, double stdDev = 0.1)
        {
            this.network = network;

            this.random = new GaussianGenerator(0f, (float)stdDev, Accord.Math.Tools.Random.Next());

            this.UpdateThresholds = false;
        }
        //scale bicubic
        private static Bitmap Scale(Bitmap image)
        {
            IRandomNumberGenerator generator = new GaussianGenerator(1.05f, 0.1f);

            ResizeBicubic filter = new ResizeBicubic((int)(image.Width * 1.035), (int)(image.Height * 1.035));

            // apply the filter
            return(filter.Apply(image));
        }
        //apply couds texture to smudge the image
        private static Bitmap Texturize(Bitmap image)
        {
            IRandomNumberGenerator generator = new GaussianGenerator(-.25f, 0.3f);

            // create filter
            Texturer filter = new Texturer(new CloudsTexture(), generator.Next(), .995);//.98

            // apply the filter
            return(filter.Apply(image));
        }
        //cause gaussian noise spikes
        private static Bitmap Speckle(Bitmap image)
        {
            IRandomNumberGenerator generator = new GaussianGenerator(0f, 5f);

            // create filter
            AdditiveNoise filter = new AdditiveNoise(generator);

            // apply the filter

            return(filter.Apply(image));
        }
예제 #6
0
    public static void TestGaussian()
    {
        float t = math.sqrt(-2.0f * math.log(UnityEngine.Random.value)) * math.cos(UnityEngine.Random.value);

        Debug.Log(t);


        Dictionary <int, int> _cnt1 = new Dictionary <int, int>();
        Dictionary <int, int> _cnt2 = new Dictionary <int, int>();
        GaussianGenerator     rndg  = new GaussianGenerator(new Random((uint)UnityEngine.Random.Range(0, int.MaxValue)));

        for (int i = 0; i < 100000; i++)
        {
            float2 r    = rndg.NextFloat2();
            int2   keys = new int2(Mathf.FloorToInt(r[0] * 20), Mathf.FloorToInt(r[1] * 20));
            if (!_cnt1.ContainsKey(keys[0]))
            {
                _cnt1[keys[0]] = 0;
            }

            _cnt1[keys[0]] += 1;
            if (!_cnt2.ContainsKey(keys[1]))
            {
                _cnt2[keys[1]] = 0;
            }

            _cnt2[keys[1]] += 1;
        }

        int width  = math.max(_cnt1.Max(kv => kv.Key), _cnt2.Max(kv => kv.Key));
        int height = math.max(_cnt1.Max(kv => kv.Value), _cnt2.Max(kv => kv.Value)) / 10;

        for (int i = -width; i < width; i++)
        {
            {
                float val1 = 0.5f / height;
                if (_cnt1.ContainsKey(i))
                {
                    val1 = _cnt1[i] / (float)height;
                }

                Debug.DrawRay(Vector3.right * i / (width / 5f), Vector3.up * val1, Color.blue, 10, false);
            }
            {
                float val2 = 0.5f / height;
                if (_cnt2.ContainsKey(i))
                {
                    val2 = _cnt2[i] / (float)height;
                }

                Debug.DrawRay(Vector3.right * i / (width / 5f) + Vector3.forward / 10, Vector3.up * val2, Color.yellow, 10, false);
            }
        }
    }
예제 #7
0
    private IntVector2 setLevelSize(int seed)
    {
        System.Random rand       = new System.Random(seed);
        double        mean       = (_levelSettings.minLevelSize + _levelSettings.maxLevelSize) / 2;
        float         sizeX      = (float)GaussianGenerator.getGaussian(mean, _levelSettings.levelSizeVariance, rand);
        float         sizeY      = (float)GaussianGenerator.getGaussian(mean, _levelSettings.levelSizeVariance, rand);
        int           finalSizeX = (int)Math.Round(Mathf.Clamp(sizeX, _levelSettings.minLevelSize, _levelSettings.maxLevelSize));
        int           finalSizeY = (int)Math.Round(Mathf.Clamp(sizeY, _levelSettings.minLevelSize, _levelSettings.maxLevelSize));

        return(new IntVector2(finalSizeX, finalSizeY));
    }
예제 #8
0
 public void Mutate(ref GaussianGenerator rnd, float learningRate)
 {
     foreach (Layer layer in model.layers)
     {
         for (int iWeight = 0; iWeight < layer.weights.Length; iWeight++)
         {
             layer.weights[iWeight] += rnd.NextFloat1() * learningRate;
         }
     }
     PrepareCache();
 }
예제 #9
0
    public void GaussianTest()
    {
        Random            _rndu = new Random((uint)UnityEngine.Random.Range(0, int.MaxValue));
        GaussianGenerator _rndn = new GaussianGenerator(_rndu);

        for (int iCnt = 0; iCnt < 100; iCnt++)
        {
            float val = _rndn.NextFloat1();
            Debug.Log(val);
            Debug.Assert(!float.IsNaN(val));
        }
    }
예제 #10
0
        public static double Beta()
        {
            GaussianGenerator generator = new GaussianGenerator(0, 1);
            double            x         = generator.Next();

            x *= x;
            x *= 0.5;
            double y = generator.Next();

            y *= y;
            y *= 0.5;
            return(x / (x + y));
        }
예제 #11
0
        /// <summary>
        ///   Random Gamma-distribution number generation
        ///   based on Marsaglia's Simple Method (2000).
        /// </summary>
        ///
        public static double Random(double d, double c)
        {
            var g = new GaussianGenerator(0, 1, Generator.Random.Next());

            // References:
            //
            // - Marsaglia, G. A Simple Method for Generating Gamma Variables, 2000
            //

            while (true)
            {
                // 2. Generate v = (1+cx)^3 with x normal
                double x, t, v;

                do
                {
                    x = g.Next();
                    t = (1.0 + c * x);
                    v = t * t * t;
                } while (v <= 0);


                // 3. Generate uniform U
                double U = Accord.Math.Random.Generator.Random.NextDouble();

                // 4. If U < 1-0.0331*x^4 return d*v.
                double x2 = x * x;
                if (U < 1 - 0.0331 * x2 * x2)
                {
                    return(d * v);
                }

                // 5. If log(U) < 0.5*x^2 + d*(1-v+log(v)) return d*v.
                if (Math.Log(U) < 0.5 * x2 + d * (1.0 - v + Math.Log(v)))
                {
                    return(d * v);
                }

                // 6. Goto step 2
            }
        }
예제 #12
0
파일: Util.cs 프로젝트: afalchetti/monorfs
 /// <summary>
 /// Static generator initialization.
 /// </summary>
 static Util()
 {
     Gaussian = new GaussianGenerator(0, 1);
     Uniform  = new UniformGenerator(new Range(0, 1));
 }
예제 #13
0
 public void Start()
 {
     _rndg = new GaussianGenerator(new Random((uint)UnityEngine.Random.Range(0, int.MaxValue)));
 }