예제 #1
0
        private float[] GenerateGradient(GridPoint gridPoint)
        {
            int    hash   = gridPoint.GetHashCode();
            Random random = new Random(Generate.CombineSeed(seed, hash));

            if (dimension == 1)
            {
                return(new float[] { (float)random.NextDouble() * 2 - 1 });                //between -1 and 1
            }

            float[] randomPoint = new float[dimension];
            for (int i = 0; i < dimension; i++)
            {
                randomPoint[i] = GaussianRandom(random, 0, 1);
            }
            float sum   = randomPoint.Sum(n => n * n);
            float scale = (float)Math.Pow(sum, -0.5);

            float[] grad = randomPoint.Select(coord => coord * scale).ToArray();
            return(grad);
        }