Ejemplo n.º 1
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;
        }
 public void TestIntRange()
 {
     var rnd = new MersenneTwisterGenerateRandom(1);
     foreach (int aIntRangeTest in IntRangeTest)
     {
         int g = rnd.NextInt(0, 10);
         Assert.AreEqual(g, aIntRangeTest);
     }
 }
 public void TestInt()
 {
     var rnd = new MersenneTwisterGenerateRandom(1);
     foreach (int aIntTest in IntTest)
     {
         int g = rnd.NextInt();
         Assert.AreEqual(g, aIntTest, AIFH.DefaultPrecision);
     }
 }
 public void TestGenerateBoolean()
 {
     var rnd = new MersenneTwisterGenerateRandom(1);
     foreach (bool aBooleanTest in BooleanTest)
     {
         bool g = rnd.NextBoolean();
         Assert.AreEqual(g, aBooleanTest);
     }
 }
 public void TestGaussianFloat()
 {
     var rnd = new MersenneTwisterGenerateRandom(1);
     foreach (double aGaussianTest in GaussianTest)
     {
         double g = rnd.NextGaussian();
         Assert.AreEqual(g, aGaussianTest, AIFH.DefaultPrecision);
     }
 }
 public void TestFloat()
 {
     var rnd = new MersenneTwisterGenerateRandom(1);
     foreach (float aFloatTest in FloatTest)
     {
         var l = (float) rnd.NextFloat();
         Assert.AreEqual(l, aFloatTest, AIFH.DefaultPrecision);
     }
 }
 public void TestDoubleRange()
 {
     var rnd = new MersenneTwisterGenerateRandom(1);
     foreach (double aDoubleRangeTest in DoubleRangeTest)
     {
         double g = rnd.NextDouble(-1, 1);
         Assert.AreEqual(g, aDoubleRangeTest, AIFH.DefaultPrecision);
     }
 }
        public void TestBasic2()
        {
            UInt32[] seed = {1, 2, 3};
            var rnd = new MersenneTwisterGenerateRandom(seed);

            Assert.AreEqual(6.09861274980219, rnd.NextDouble(10), AIFH.DefaultPrecision);
        }
        public void TestBasic()
        {
            var rnd = new MersenneTwisterGenerateRandom(1);

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