Пример #1
0
        /// <summary>
        ///   Estimates a new uniform distribution from a given set of observations.
        /// </summary>
        ///
        public static UniformContinuousDistribution Estimate(double[] observations)
        {
            var n = new UniformContinuousDistribution();

            n.Fit(observations);
            return(n);
        }
Пример #2
0
        /// <summary>
        ///   Generates a random observation from the
        ///   Cauchy distribution with the given parameters.
        /// </summary>
        ///
        /// <param name="location">The location parameter x0.</param>
        /// <param name="scale">The scale parameter gamma.</param>
        ///
        /// <returns>A random double value sampled from the specified Cauchy distribution.</returns>
        ///
        public static double Random(double location, double scale)
        {
            // Generate uniform U on [-PI/2, +PI/2]
            double x = UniformContinuousDistribution.Random(-Math.PI / 2.0, +Math.PI / 2.0);

            return(Math.Tan(x) * scale + location);
        }
Пример #3
0
 /// <summary>
 ///   Generates a random vector of observations from the
 ///   Cauchy distribution with the given parameters.
 /// </summary>
 ///
 /// <param name="location">The location parameter x0.</param>
 /// <param name="scale">The scale parameter gamma.</param>
 /// <param name="samples">The number of samples to generate.</param>
 ///
 /// <returns>An array of double values sampled from the specified Cauchy distribution.</returns>
 ///
 public static double[] Random(double location, double scale, int samples)
 {
     // Generate uniform U on [-PI/2, +PI/2]
     double[] x = UniformContinuousDistribution.Random(-Math.PI / 2.0, +Math.PI / 2.0, samples);
     for (int i = 0; i < x.Length; i++)
     {
         x[i] = Math.Tan(x[i]) * scale + location;
     }
     return(x);
 }
Пример #4
0
        /// <summary>
        ///   Generates a random observation from the current distribution.
        /// </summary>
        ///
        /// <returns>A random observations drawn from this distribution.</returns>
        ///
        public override double Generate()
        {
            double u  = UniformContinuousDistribution.Random();
            double Fc = DistributionFunction(c);

            if (u < Fc)
            {
                return(a + Math.Sqrt(u * (b - a) * (c - a)));
            }
            return(b - Math.Sqrt((1 - u) * (b - a) * (b - c)));
        }
Пример #5
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 override double[] Generate(int samples)
        {
            double Fc = DistributionFunction(c);

            double[] values = UniformContinuousDistribution.Random(samples);

            for (int i = 0; i < values.Length; i++)
            {
                double u = values[i];

                if (u < Fc)
                {
                    values[i] = a + Math.Sqrt(u * (b - a) * (c - a));
                }
                else
                {
                    values[i] = b - Math.Sqrt((1 - u) * (b - a) * (b - c));
                }
            }

            return(values);
        }