A predictable random number generator. This is useful for unit tests and benchmarks where we want random numbers, but we want them to be the same each time. This class exists on both Java and C# so it can even provide consistent random numbers over the two platforms. Random numbers are created using a LCG. http://en.wikipedia.org/wiki/Linear_congruential_generator
        /// <summary>
        /// Generate a random training set. 
        /// </summary>
        /// <param name="seed">The seed value to use, the same seed value will always produce
        /// the same results.</param>
        /// <param name="count">How many training items to generate.</param>
        /// <param name="inputCount">How many input numbers.</param>
        /// <param name="idealCount">How many ideal numbers.</param>
        /// <param name="min">The minimum random number.</param>
        /// <param name="max">The maximum random number.</param>
        /// <returns>The random training set.</returns>
        public static BasicMLDataSet Generate(long seed,
            int count, int inputCount,
            int idealCount, double min, double max)
        {
            var rand =
                new LinearCongruentialGenerator(seed);

            var result = new BasicMLDataSet();
            for (int i = 0; i < count; i++)
            {
                var inputData = new BasicMLData(inputCount);

                for (int j = 0; j < inputCount; j++)
                {
                    inputData[j] = rand.Range(min, max);
                }

                var idealData = new BasicMLData(idealCount);

                for (int j = 0; j < idealCount; j++)
                {
                    idealData[j] = rand.Range(min, max);
                }

                var pair = new BasicMLDataPair(inputData,
                                               idealData);
                result.Add(pair);
            }
            return result;
        }
Пример #2
0
 public ConsistentRandomizer(double min, double max, int seed)
 {
     this._xffd6352b2e5d70e3 = max;
     this._xd088075e67f6ea91 = min;
     this._x5f33b0fc94247cc0 = seed;
     this._xc25f3ba15c9fba69 = new LinearCongruentialGenerator((long) seed);
 }
        /// <summary>
        /// Generate random training into a training set.
        /// </summary>
        /// <param name="training">The training set to generate into.</param>
        /// <param name="seed">The seed to use.</param>
        /// <param name="count">How much data to generate.</param>
        /// <param name="min">The low random value.</param>
        /// <param name="max">The high random value.</param>
        public static void Generate(IMLDataSetAddable training,
            long seed,
            int count,
            double min, double max)
        {
            var rand
                = new LinearCongruentialGenerator(seed);

            int inputCount = training.InputSize;
            int idealCount = training.IdealSize;

            for (int i = 0; i < count; i++)
            {
                var inputData = new BasicMLData(inputCount);

                for (int j = 0; j < inputCount; j++)
                {
                    inputData[j] = rand.Range(min, max);
                }

                var idealData = new BasicMLData(idealCount);

                for (int j = 0; j < idealCount; j++)
                {
                    idealData[j] = rand.Range(min, max);
                }

                var pair = new BasicMLDataPair(inputData,
                                               idealData);
                training.Add(pair);
            }
        }
 /// <summary>
 /// Construct a range randomizer.
 /// </summary>
 /// <param name="seed">The seed for the random number generator.</param>
 /// <param name="min">The minimum random value.</param>
 /// <param name="max">The maximum random value.</param>
 public ConsistentRandomizer(int seed, double min,
          double max)
 {
     this.rand = new LinearCongruentialGenerator(seed);
     this.Max = max;
     this.Min = min;
 }
Пример #5
0
 public static BasicMLDataSet Generate(long seed, int count, int inputCount, int idealCount, double min, double max)
 {
     IMLData data;
     int num2;
     IMLData data2;
     BasicMLDataPair pair;
     LinearCongruentialGenerator generator = new LinearCongruentialGenerator(seed);
     BasicMLDataSet set = new BasicMLDataSet();
     int num = 0;
     goto Label_0018;
     Label_000C:
     set.Add(pair);
     Label_0014:
     num++;
     Label_0018:
     if (num < count)
     {
         data = new BasicMLData(inputCount);
         num2 = 0;
         while (num2 < inputCount)
         {
             data.Data[num2] = generator.Range(min, max);
             num2++;
         }
         data2 = new BasicMLData(idealCount);
         if (((uint) count) < 0)
         {
             goto Label_000C;
         }
         if ((((uint) idealCount) & 0) != 0)
         {
             goto Label_0014;
         }
         int num3 = 0;
     Label_002D:
         if (num3 < idealCount)
         {
             data2[num3] = generator.Range(min, max);
             if ((((uint) idealCount) - ((uint) max)) <= uint.MaxValue)
             {
                 num3++;
                 goto Label_002D;
             }
         }
         else
         {
             goto Label_0032;
         }
         goto Label_00C6;
     }
     if (0 == 0)
     {
         return set;
     }
     Label_0032:
     pair = new BasicMLDataPair(data, data2);
     Label_00C6:
     if ((((uint) num2) & 0) == 0)
     {
         goto Label_000C;
     }
     goto Label_0018;
 }
Пример #6
0
 public static void Generate(IMLDataSet training, long seed, int count, double min, double max)
 {
     int num;
     int idealSize;
     int num3;
     IMLData data;
     int num4;
     IMLData data2;
     int num5;
     LinearCongruentialGenerator generator = new LinearCongruentialGenerator(seed);
     goto Label_0111;
     Label_0023:
     if (num3 < count)
     {
         data = new BasicMLData(num);
         num4 = 0;
         while (true)
         {
             if (num4 < num)
             {
                 data[num4] = generator.Range(min, max);
             }
             else
             {
                 data2 = new BasicMLData(idealSize);
                 num5 = 0;
                 goto Label_004D;
             }
             num4++;
         }
     }
     if ((((uint) num) - ((uint) num)) >= 0)
     {
         if ((((uint) num4) - ((uint) num3)) >= 0)
         {
             if ((((uint) seed) + ((uint) seed)) >= 0)
             {
                 return;
             }
             goto Label_0111;
         }
         goto Label_00F5;
     }
     Label_0047:
     num5++;
     Label_004D:
     if (num5 >= idealSize)
     {
         if ((((uint) max) + ((uint) num3)) <= uint.MaxValue)
         {
             BasicMLDataPair inputData = new BasicMLDataPair(data, data2);
             training.Add(inputData);
             num3++;
         }
     }
     else
     {
         data2[num5] = generator.Range(min, max);
         if (((uint) num5) >= 0)
         {
             goto Label_0047;
         }
     }
     goto Label_0023;
     Label_00F5:
     num3 = 0;
     goto Label_0023;
     Label_0111:
     num = training.InputSize;
     idealSize = training.IdealSize;
     goto Label_00F5;
 }