Beispiel #1
0
 public static void GenerateSortedAndShuffleNPercent(SortingArray array, int chance)
 {
     GenerateSorted(array);
     for (int i = 0; i < array.Length; i++)
     {
         StandardGenerator rand = new StandardGenerator();
         int randNum            = rand.Next(101);
         if (randNum <= chance)
         {
             int pos = rand.Next(array.Length);
             array.Swap(i, pos);
             Updated(array);
         }
     }
 }
        /// <summary>
        ///   Generates a random vector of observations from the current distribution.
        /// </summary>
        ///
        /// <param name="samples">The number of samples to generate.</param>
        ///
        /// <returns>A random vector of observations drawn from this distribution.</returns>
        ///
        public double[][] Generate(int samples)
        {
            if (chol == null)
            {
                throw new NonPositiveDefiniteMatrixException("Covariance matrix is not positive definite.");
            }

            var r = new StandardGenerator(BestCS.Math.Tools.Random.Next());

            double[,] A = chol.LeftTriangularFactor;

            double[][] data = new double[samples][];
            for (int i = 0; i < data.Length; i++)
            {
                double[] sample = new double[Dimension];
                for (int j = 0; j < sample.Length; j++)
                {
                    sample[j] = r.Next();
                }

                data[i] = A.Multiply(sample).Add(Mean);
            }

            return(data);
        }
Beispiel #3
0
        /// <summary>
        ///   Samples a value from the function given a input value.
        /// </summary>
        ///
        /// <param name="x">Function input value.</param>
        ///
        /// <returns>
        ///   Draws a random value from the function.
        /// </returns>
        ///
        public double Generate(double x)
        {
            // assume zero-mean noise
            double y = alpha * x + gaussian.Next();

            if (y > range.Max)
            {
                y = range.Max;
            }
            else if (y < range.Min)
            {
                y = range.Min;
            }

            return(y);
        }
Beispiel #4
0
 public static void GenerateRandom(SortingArray array)
 {
     for (int i = 0; i < array.Length; i++)
     {
         StandardGenerator rand = new StandardGenerator();
         int val = rand.Next(1, array.Length + 1);
         array.Modify(i, val);
         Updated(array);
     }
 }
Beispiel #5
0
 public static void Shuffle(SortingArray array)
 {
     for (int i = 0; i < array.Length; i++)
     {
         StandardGenerator rand = new StandardGenerator();
         int pos = rand.Next(0, array.Length);
         array.Swap(i, pos);
         Updated(array);
     }
 }
Beispiel #6
0
 public static void GenerateRandomAscending(SortingArray array)
 {
     for (int i = 0; i < array.Length; i++)
     {
         StandardGenerator rand = new StandardGenerator();
         int value = rand.Next(i, array.Length) + 1;
         array.Modify(i, value);
         Updated(array);
     }
 }
Beispiel #7
0
        /// <summary>
        ///   Generates a random vector of observations from the current distribution.
        /// </summary>
        ///
        /// <returns>A random vector of observations drawn from this distribution.</returns>
        ///
        public double[] Generate()
        {
            var r = new StandardGenerator(Accord.Math.Tools.Random.Next());

            double[,] A = chol.LeftTriangularFactor;

            double[] sample = new double[Dimension];
            for (int j = 0; j < sample.Length; j++)
            {
                sample[j] = r.Next();
            }

            return(A.Multiply(sample).Add(Mean));
        }
        /// <summary>
        ///   Generates a random vector of observations from the current distribution.
        /// </summary>
        ///
        /// <returns>A random vector of observations drawn from this distribution.</returns>
        ///
        public double[] Generate()
        {
            if (chol == null)
            {
                throw new NonPositiveDefiniteMatrixException("Covariance matrix is not positive definite.");
            }

            var r = new StandardGenerator(Accord.Math.Tools.Random.Next());

            double[,] A = chol.LeftTriangularFactor;

            double[] sample = new double[Dimension];
            for (int j = 0; j < sample.Length; j++)
            {
                sample[j] = r.Next();
            }

            return(A.Multiply(sample).Add(Mean));
        }
Beispiel #9
0
        /// <summary>
        ///   Generates a random vector of observations from the current distribution.
        /// </summary>
        ///
        /// <param name="samples">The number of samples to generate.</param>
        ///
        /// <returns>A random vector of observations drawn from this distribution.</returns>
        ///
        public double[][] Generate(int samples)
        {
            var r = new StandardGenerator(Accord.Math.Tools.Random.Next());

            double[,] A = chol.LeftTriangularFactor;

            double[][] data = new double[samples][];
            for (int i = 0; i < data.Length; i++)
            {
                double[] sample = new double[Dimension];
                for (int j = 0; j < sample.Length; j++)
                {
                    sample[j] = r.Next();
                }

                data[i] = A.Multiply(sample).Add(Mean);
            }

            return(data);
        }
Beispiel #10
0
 /// <summary>
 /// Generate next random number.
 /// </summary>
 ///
 /// <returns>Returns next random number.</returns>
 ///
 public float Next()
 {
     return((float)rand.Next() * stdDev + mean);
 }
Beispiel #11
0
 /// <summary>
 /// Generate next random number.
 /// </summary>
 ///
 /// <returns>Returns next random number.</returns>
 ///
 public double Next()
 {
     return(rand.Next() * stdDev + mean);
 }