예제 #1
0
        public void RandomizeParticles()
        {
            IGenerateRandom random = new MersenneTwisterGenerateRandom();

            for (int i = 0; i < ParticleCount; i++)
            {
                var p = new Particle(2);
                p.Location[0] = random.NextDouble(OutputCanvas.ActualWidth);
                p.Location[1] = random.NextDouble(OutputCanvas.ActualHeight);
                p.Velocity[0] = 3;
                p.Velocity[1] = random.NextDouble(2.0 * Math.PI);
                _particles.Add(p);
            }
        }
예제 #2
0
        public void TestBasic2()
        {
            UInt32[] seed = { 1, 2, 3 };
            var      rnd  = new MersenneTwisterGenerateRandom(seed);

            Assert.AreEqual(6.09861274980219, rnd.NextDouble(10), AIFH.DefaultPrecision);
        }
예제 #3
0
        /// <summary>
        /// Generate random data.
        /// </summary>
        /// <param name="seed">The seed to use.</param>
        /// <param name="rows">The number of rows to generate.</param>
        /// <param name="cols">The number of columns to generate.</param>
        /// <param name="low">The low value.</param>
        /// <param name="high">The high value.</param>
        /// <param name="distort">The distortion factor.</param>
        /// <returns>The data set.</returns>
        public DataHolder Generate(int seed, int rows, int cols, double low,
                                   double high, double distort)
        {
            IGenerateRandom rnd = new MersenneTwisterGenerateRandom((uint)seed);

            var ideal  = new double[rows][];
            var actual = new double[rows][];

            for (int row = 0; row < rows; row++)
            {
                for (int col = 0; col < cols; col++)
                {
                    ideal[row]       = new double[cols];
                    actual[row]      = new double[cols];
                    ideal[row][col]  = rnd.NextDouble(low, high);
                    actual[row][col] = ideal[row][col] + (rnd.NextGaussian() * distort);
                }
            }

            var result = new DataHolder {
                Actual = actual, Ideal = ideal
            };

            return(result);
        }
예제 #4
0
        /// <inheritdoc />
        public void Randomize()
        {
            IGenerateRandom rnd = new MersenneTwisterGenerateRandom();

            for (int i = 0; i < _data.Length; i++)
            {
                _data[i] = rnd.NextDouble() * 2.0 - 1.0;
            }
            SortData();
        }
예제 #5
0
        /**
         * @return A random genome.
         */
        private DoubleArrayGenome RandomGenome()
        {
            DoubleArrayGenome genome = new DoubleArrayGenome(PlantUniverse.GenomeSize);

            for (int i = 0; i < genome.Count; i++)
            {
                genome.Data[i] = rnd.NextDouble(0, 1);
            }
            return(genome);
        }
예제 #6
0
        public void TestDouble()
        {
            var rnd = new MersenneTwisterGenerateRandom(1);

            foreach (double aDoubleTest in DoubleTest)
            {
                double g = rnd.NextDouble();
                Assert.AreEqual(g, aDoubleTest, AIFH.DefaultPrecision);
            }
        }
예제 #7
0
        public void TestBasic()
        {
            var rnd = new MersenneTwisterGenerateRandom(1);

            Assert.AreEqual(4.1702200468159925, rnd.NextDouble(10), AIFH.DefaultPrecision);
        }