Example #1
0
        /// <summary>
        ///   Generates a random vector of observations from the
        ///   Beta distribution with the given parameters.
        /// </summary>
        ///
        /// <param name="alpha">The shape parameter α (alpha).</param>
        /// <param name="beta">The shape parameter β (beta).</param>
        /// <param name="min">The minimum possible value a.</param>
        /// <param name="max">The maximum possible value b.</param>
        /// <param name="samples">The number of samples to generate.</param>
        /// <param name="result">The location where to store the samples.</param>
        /// <param name="source">The random number generator to use as a source of randomness.
        ///   Default is to use <see cref="Accord.Math.Random.Generator.Random"/>.</param>
        ///
        /// <returns>An array of double values sampled from the specified Beta distribution.</returns>
        ///
        public static double[] Random(double alpha, double beta, double min, double max, int samples, double[] result, Random source)
        {
            BetaDistribution.Random(alpha, beta, samples, result, source);

            if (min != 0 || max != 1)
            {
                for (int i = 0; i < result.Length; i++)
                {
                    result[i] = result[i] * (max - min) + min;
                }
            }

            return(result);
        }
        /// <summary>
        ///   Generates a random vector of observations from the
        ///   Beta distribution with the given parameters.
        /// </summary>
        ///
        /// <param name="alpha">The shape parameter α (alpha).</param>
        /// <param name="beta">The shape parameter β (beta).</param>
        /// <param name="min">The minimum possible value a.</param>
        /// <param name="max">The maximum possible value b.</param>
        /// <param name="samples">The number of samples to generate.</param>
        ///
        /// <returns>An array of double values sampled from the specified Beta distribution.</returns>
        ///
        public static double[] Random(double alpha, double beta, double min, double max, int samples)
        {
            double[] r = BetaDistribution.Random(alpha, beta, samples);

            if (min != 0 || max != 1)
            {
                for (int i = 0; i < r.Length; i++)
                {
                    r[i] = r[i] * (max - min) + min;
                }
            }

            return(r);
        }
Example #3
0
        /// <summary>
        ///   Generates a random observation from a
        ///   Beta distribution with the given parameters.
        /// </summary>
        ///
        /// <param name="alpha">The shape parameter α (alpha).</param>
        /// <param name="beta">The shape parameter β (beta).</param>
        /// <param name="min">The minimum possible value a.</param>
        /// <param name="max">The maximum possible value b.</param>
        /// <param name="source">The random number generator to use as a source of randomness.
        ///   Default is to use <see cref="Accord.Math.Random.Generator.Random"/>.</param>
        ///
        /// <returns>A random double value sampled from the specified Beta distribution.</returns>
        ///
        public static double Random(double alpha, double beta, double min, double max, Random source)
        {
            double r = BetaDistribution.Random(alpha, beta, source);

            return(r * (max - min) + min);
        }