/// <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> /// <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 Cauchy distribution.</returns> /// public static double Random(double location, double scale, Random source) { // Generate uniform U on [-PI/2, +PI/2] double x = UniformContinuousDistribution.Random(-Math.PI / 2.0, +Math.PI / 2.0, source); return(Math.Tan(x) * scale + location); }
/// <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, null, null); return(n); }
/// <summary> /// Generates a random vector of observations from the current distribution. /// </summary> /// /// <param name="samples">The number of samples to generate.</param> /// <param name="result">The location where to store the samples.</param> /// /// <returns>A random vector of observations drawn from this distribution.</returns> /// public override double[] Generate(int samples, double[] result) { UniformContinuousDistribution.Random(samples, result); for (int i = 0; i < samples; i++) { result[i] = xm / Math.Pow(result[i], 1.0 / alpha); } return(result); }
/// <summary> /// Generates a random observation from the current distribution. /// </summary> /// /// <returns>A random observations drawn from this distribution.</returns> /// public override double Generate(Random source) { double u = UniformContinuousDistribution.Random(source); 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)); }
/// <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> /// <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 Cauchy distribution.</returns> /// public static double[] Random(double location, double scale, int samples, double[] result, Random source) { // Generate uniform U on [-PI/2, +PI/2] UniformContinuousDistribution.Random(-Math.PI / 2.0, +Math.PI / 2.0, samples, result, source); for (int i = 0; i < result.Length; i++) { result[i] = Math.Tan(result[i]) * scale + location; } return(result); }
/// <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); }
/// <summary> /// Generates a random observation from the current distribution. /// </summary> /// /// <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 observations drawn from this distribution.</returns> /// public override double Generate(Random source) { double U = UniformContinuousDistribution.Random(source); if (ksi == 0) { return(mu - sigma * Math.Log(U)); } return(mu + sigma * (Math.Pow(U, -ksi) - 1) / ksi); }
/// <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))); }
/// <summary> /// Generates a random vector of observations from the current distribution. /// </summary> /// /// <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>A random vector of observations drawn from this distribution.</returns> /// public override double[] Generate(int samples, double[] result, Random source) { double Fc = DistributionFunction(c); UniformContinuousDistribution.Random(samples, result, source); for (int i = 0; i < samples; i++) { double u = result[i]; if (u < Fc) result[i] = a + Math.Sqrt(u * (b - a) * (c - a)); else result[i] = b - Math.Sqrt((1 - u) * (b - a) * (b - c)); } return result; }
/// <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) { 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)); } values[i] = b - Math.Sqrt((1 - u) * (b - a) * (b - c)); } return(values); }
/// <summary> /// Generates a random vector of observations from the current distribution. /// </summary> /// /// <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>A random vector of observations drawn from this distribution.</returns> /// public override double[] Generate(int samples, double[] result, Random source) { UniformContinuousDistribution.Random(samples, result, source); if (ksi == 0) { for (int i = 0; i < result.Length; i++) { result[i] = mu - sigma * Math.Log(result[i]); } } else { for (int i = 0; i < result.Length; i++) { result[i] = mu + sigma * (Math.Pow(result[i], -ksi) - 1) / ksi; } } return(result); }
/// <summary> /// Generates a random observation from the current distribution. /// </summary> /// /// <returns>A random observations drawn from this distribution.</returns> /// public override double Generate(Random source) { double u = UniformContinuousDistribution.Random(source); return(xm / Math.Pow(u, 1.0 / alpha)); }