Browse Source

Distributions: shortcut static sample functions (continuous)

provider
Christoph Ruegg 13 years ago
parent
commit
0c5630492a
  1. 22
      src/Numerics/Distributions/Beta.cs
  2. 22
      src/Numerics/Distributions/Cauchy.cs
  3. 20
      src/Numerics/Distributions/Chi.cs
  4. 20
      src/Numerics/Distributions/ChiSquared.cs
  5. 22
      src/Numerics/Distributions/ContinuousUniform.cs
  6. 22
      src/Numerics/Distributions/Erlang.cs
  7. 20
      src/Numerics/Distributions/Exponential.cs
  8. 22
      src/Numerics/Distributions/FisherSnedecor.cs
  9. 22
      src/Numerics/Distributions/Gamma.cs
  10. 22
      src/Numerics/Distributions/InverseGamma.cs
  11. 22
      src/Numerics/Distributions/Laplace.cs
  12. 22
      src/Numerics/Distributions/LogNormal.cs
  13. 22
      src/Numerics/Distributions/Normal.cs
  14. 22
      src/Numerics/Distributions/Pareto.cs
  15. 20
      src/Numerics/Distributions/Rayleigh.cs
  16. 26
      src/Numerics/Distributions/Stable.cs
  17. 24
      src/Numerics/Distributions/StudentT.cs
  18. 23
      src/Numerics/Distributions/Triangular.cs
  19. 22
      src/Numerics/Distributions/Weibull.cs

22
src/Numerics/Distributions/Beta.cs

@ -561,5 +561,27 @@ namespace MathNet.Numerics.Distributions
yield return SampleUnchecked(rnd, a, b);
}
}
/// <summary>
/// Generates a sample from the distribution.
/// </summary>
/// <param name="a">The α shape parameter of the Beta distribution. Range: α ≥ 0.</param>
/// <param name="b">The β shape parameter of the Beta distribution. Range: β ≥ 0.</param>
/// <returns>a sample from the distribution.</returns>
public static double Sample(double a, double b)
{
return Sample(SystemRandomSource.Default, a, b);
}
/// <summary>
/// Generates a sequence of samples from the distribution.
/// </summary>
/// <param name="a">The α shape parameter of the Beta distribution. Range: α ≥ 0.</param>
/// <param name="b">The β shape parameter of the Beta distribution. Range: β ≥ 0.</param>
/// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<double> Samples(double a, double b)
{
return Samples(SystemRandomSource.Default, a, b);
}
}
}

22
src/Numerics/Distributions/Cauchy.cs

@ -361,5 +361,27 @@ namespace MathNet.Numerics.Distributions
yield return location + scale*Math.Tan(Constants.Pi*(rnd.NextDouble() - 0.5));
}
}
/// <summary>
/// Generates a sample from the distribution.
/// </summary>
/// <param name="location">The location (x0) of the distribution.</param>
/// <param name="scale">The scale (γ) of the distribution. Range: γ > 0.</param>
/// <returns>a sample from the distribution.</returns>
public static double Sample(double location, double scale)
{
return Sample(SystemRandomSource.Default, location, scale);
}
/// <summary>
/// Generates a sequence of samples from the distribution.
/// </summary>
/// <param name="location">The location (x0) of the distribution.</param>
/// <param name="scale">The scale (γ) of the distribution. Range: γ > 0.</param>
/// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<double> Samples(double location, double scale)
{
return Samples(SystemRandomSource.Default, location, scale);
}
}
}

20
src/Numerics/Distributions/Chi.cs

@ -337,5 +337,25 @@ namespace MathNet.Numerics.Distributions
yield return SampleUnchecked(rnd, freedom);
}
}
/// <summary>
/// Generates a sample from the distribution.
/// </summary>
/// <param name="freedom">The degrees of freedom (k) of the distribution. Range: k > 0.</param>
/// <returns>a sample from the distribution.</returns>
public static double Sample(int freedom)
{
return Sample(SystemRandomSource.Default, freedom);
}
/// <summary>
/// Generates a sequence of samples from the distribution.
/// </summary>
/// <param name="freedom">The degrees of freedom (k) of the distribution. Range: k > 0.</param>
/// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<double> Samples(int freedom)
{
return Samples(SystemRandomSource.Default, freedom);
}
}
}

20
src/Numerics/Distributions/ChiSquared.cs

@ -330,5 +330,25 @@ namespace MathNet.Numerics.Distributions
yield return SampleUnchecked(rnd, freedom);
}
}
/// <summary>
/// Generates a sample from the <c>ChiSquare</c> distribution.
/// </summary>
/// <param name="freedom">The degrees of freedom (k) of the distribution. Range: k > 0.</param>
/// <returns>a sample from the distribution. </returns>
public static double Sample(double freedom)
{
return Sample(SystemRandomSource.Default, freedom);
}
/// <summary>
/// Generates a sequence of samples from the distribution.
/// </summary>
/// <param name="freedom">The degrees of freedom (k) of the distribution. Range: k > 0.</param>
/// <returns>a sample from the distribution. </returns>
public static IEnumerable<double> Samples(double freedom)
{
return Samples(SystemRandomSource.Default, freedom);
}
}
}

22
src/Numerics/Distributions/ContinuousUniform.cs

@ -364,5 +364,27 @@ namespace MathNet.Numerics.Distributions
yield return lower + rnd.NextDouble()*(upper - lower);
}
}
/// <summary>
/// Generates a sample from the <c>ContinuousUniform</c> distribution.
/// </summary>
/// <param name="lower">Lower bound. Range: lower ≤ upper.</param>
/// <param name="upper">Upper bound. Range: lower ≤ upper.</param>
/// <returns>a uniformly distributed sample.</returns>
public static double Sample(double lower, double upper)
{
return Sample(SystemRandomSource.Default, lower, upper);
}
/// <summary>
/// Generates a sequence of samples from the <c>ContinuousUniform</c> distribution.
/// </summary>
/// <param name="lower">Lower bound. Range: lower ≤ upper.</param>
/// <param name="upper">Upper bound. Range: lower ≤ upper.</param>
/// <returns>a sequence of uniformly distributed samples.</returns>
public static IEnumerable<double> Samples(double lower, double upper)
{
return Samples(SystemRandomSource.Default, lower, upper);
}
}
}

22
src/Numerics/Distributions/Erlang.cs

@ -514,5 +514,27 @@ namespace MathNet.Numerics.Distributions
yield return SampleUnchecked(rnd, shape, rate);
}
}
/// <summary>
/// Generates a sample from the distribution.
/// </summary>
/// <param name="shape">The shape (k) of the Erlang distribution. Range: k ≥ 0.</param>
/// <param name="rate">The rate or inverse scale (λ) of the Erlang distribution. Range: λ ≥ 0.</param>
/// <returns>a sample from the distribution.</returns>
public static double Sample(double shape, double rate)
{
return Sample(SystemRandomSource.Default, shape, rate);
}
/// <summary>
/// Generates a sequence of samples from the distribution.
/// </summary>
/// <param name="shape">The shape (k) of the Erlang distribution. Range: k ≥ 0.</param>
/// <param name="rate">The rate or inverse scale (λ) of the Erlang distribution. Range: λ ≥ 0.</param>
/// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<double> Samples(double shape, double rate)
{
return Samples(SystemRandomSource.Default, shape, rate);
}
}
}

20
src/Numerics/Distributions/Exponential.cs

@ -349,5 +349,25 @@ namespace MathNet.Numerics.Distributions
yield return SampleUnchecked(rnd, rate);
}
}
/// <summary>
/// Draws a random sample from the distribution.
/// </summary>
/// <param name="rate">The rate (λ) parameter of the distribution. Range: λ ≥ 0.</param>
/// <returns>A random number from this distribution.</returns>
public static double Sample(double rate)
{
return Sample(SystemRandomSource.Default, rate);
}
/// <summary>
/// Generates a sequence of samples from the Exponential distribution.
/// </summary>
/// <param name="rate">The rate (λ) parameter of the distribution. Range: λ ≥ 0.</param>
/// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<double> Samples(double rate)
{
return Samples(SystemRandomSource.Default, rate);
}
}
}

22
src/Numerics/Distributions/FisherSnedecor.cs

@ -399,5 +399,27 @@ namespace MathNet.Numerics.Distributions
yield return SampleUnchecked(rnd, d1, d2);
}
}
/// <summary>
/// Generates a sample from the distribution.
/// </summary>
/// <param name="d1">The first degree of freedom (d1) of the distribution. Range: d1 > 0.</param>
/// <param name="d2">The second degree of freedom (d2) of the distribution. Range: d2 > 0.</param>
/// <returns>a sample from the distribution.</returns>
public static double Sample(double d1, double d2)
{
return Sample(SystemRandomSource.Default, d1, d2);
}
/// <summary>
/// Generates a sequence of samples from the distribution.
/// </summary>
/// <param name="d1">The first degree of freedom (d1) of the distribution. Range: d1 > 0.</param>
/// <param name="d2">The second degree of freedom (d2) of the distribution. Range: d2 > 0.</param>
/// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<double> Samples(double d1, double d2)
{
return Samples(SystemRandomSource.Default, d1, d2);
}
}
}

22
src/Numerics/Distributions/Gamma.cs

@ -546,5 +546,27 @@ namespace MathNet.Numerics.Distributions
yield return SampleUnchecked(rnd, shape, rate);
}
}
/// <summary>
/// Generates a sample from the Gamma distribution.
/// </summary>
/// <param name="shape">The shape (k, α) of the Gamma distribution. Range: α ≥ 0.</param>
/// <param name="rate">The rate or inverse scale (β) of the Gamma distribution. Range: β ≥ 0.</param>
/// <returns>a sample from the distribution.</returns>
public static double Sample(double shape, double rate)
{
return Sample(SystemRandomSource.Default, shape, rate);
}
/// <summary>
/// Generates a sequence of samples from the Gamma distribution.
/// </summary>
/// <param name="shape">The shape (k, α) of the Gamma distribution. Range: α ≥ 0.</param>
/// <param name="rate">The rate or inverse scale (β) of the Gamma distribution. Range: β ≥ 0.</param>
/// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<double> Samples(double shape, double rate)
{
return Samples(SystemRandomSource.Default, shape, rate);
}
}
}

22
src/Numerics/Distributions/InverseGamma.cs

@ -343,5 +343,27 @@ namespace MathNet.Numerics.Distributions
return Gamma.Samples(rnd, shape, scale).Select(z => 1.0/z);
}
/// <summary>
/// Generates a sample from the distribution.
/// </summary>
/// <param name="shape">The shape (α) of the distribution. Range: α > 0.</param>
/// <param name="scale">The scale (β) of the distribution. Range: β > 0.</param>
/// <returns>a sample from the distribution.</returns>
public static double Sample(double shape, double scale)
{
return Sample(SystemRandomSource.Default, shape, scale);
}
/// <summary>
/// Generates a sequence of samples from the distribution.
/// </summary>
/// <param name="shape">The shape (α) of the distribution. Range: α > 0.</param>
/// <param name="scale">The scale (β) of the distribution. Range: β > 0.</param>
/// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<double> Samples(double shape, double scale)
{
return Samples(SystemRandomSource.Default, shape, scale);
}
}
}

22
src/Numerics/Distributions/Laplace.cs

@ -349,5 +349,27 @@ namespace MathNet.Numerics.Distributions
yield return SampleUnchecked(rnd, location, scale);
}
}
/// <summary>
/// Generates a sample from the distribution.
/// </summary>
/// <param name="location">The location (μ) of the distribution.</param>
/// <param name="scale">The scale (b) of the distribution. Range: b > 0.</param>
/// <returns>a sample from the distribution.</returns>
public static double Sample(double location, double scale)
{
return Sample(SystemRandomSource.Default, location, scale);
}
/// <summary>
/// Generates a sequence of samples from the distribution.
/// </summary>
/// <param name="location">The location (μ) of the distribution.</param>
/// <param name="scale">The scale (b) of the distribution. Range: b > 0.</param>
/// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<double> Samples(double location, double scale)
{
return Samples(SystemRandomSource.Default, location, scale);
}
}
}

22
src/Numerics/Distributions/LogNormal.cs

@ -429,5 +429,27 @@ namespace MathNet.Numerics.Distributions
{
return Normal.Samples(rnd, mu, sigma).Select(Math.Exp);
}
/// <summary>
/// Generates a sample from the log-normal distribution using the <i>Box-Muller</i> algorithm.
/// </summary>
/// <param name="mu">The log-scale (μ) of the distribution.</param>
/// <param name="sigma">The shape (σ) of the distribution. Range: σ ≥ 0.</param>
/// <returns>a sample from the distribution.</returns>
public static double Sample(double mu, double sigma)
{
return Sample(SystemRandomSource.Default, mu, sigma);
}
/// <summary>
/// Generates a sequence of samples from the log-normal distribution using the <i>Box-Muller</i> algorithm.
/// </summary>
/// <param name="mu">The log-scale (μ) of the distribution.</param>
/// <param name="sigma">The shape (σ) of the distribution. Range: σ ≥ 0.</param>
/// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<double> Samples(double mu, double sigma)
{
return Samples(SystemRandomSource.Default, mu, sigma);
}
}
}

22
src/Numerics/Distributions/Normal.cs

@ -460,5 +460,27 @@ namespace MathNet.Numerics.Distributions
yield return mean + (stddev*sample.Item2);
}
}
/// <summary>
/// Generates a sample from the normal distribution using the <i>Box-Muller</i> algorithm.
/// </summary>
/// <param name="mean">The mean (μ) of the normal distribution.</param>
/// <param name="stddev">The standard deviation (σ) of the normal distribution. Range: σ ≥ 0.</param>
/// <returns>a sample from the distribution.</returns>
public static double Sample(double mean, double stddev)
{
return Sample(SystemRandomSource.Default, mean, stddev);
}
/// <summary>
/// Generates a sequence of samples from the normal distribution using the <i>Box-Muller</i> algorithm.
/// </summary>
/// <param name="mean">The mean (μ) of the normal distribution.</param>
/// <param name="stddev">The standard deviation (σ) of the normal distribution. Range: σ ≥ 0.</param>
/// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<double> Samples(double mean, double stddev)
{
return Samples(SystemRandomSource.Default, mean, stddev);
}
}
}

22
src/Numerics/Distributions/Pareto.cs

@ -374,5 +374,27 @@ namespace MathNet.Numerics.Distributions
yield return scale*Math.Pow(rnd.NextDouble(), power);
}
}
/// <summary>
/// Generates a sample from the distribution.
/// </summary>
/// <param name="scale">The scale (xm) of the distribution. Range: xm > 0.</param>
/// <param name="shape">The shape (α) of the distribution. Range: α > 0.</param>
/// <returns>a sample from the distribution.</returns>
public static double Sample(double scale, double shape)
{
return Sample(SystemRandomSource.Default, scale, shape);
}
/// <summary>
/// Generates a sequence of samples from the distribution.
/// </summary>
/// <param name="scale">The scale (xm) of the distribution. Range: xm > 0.</param>
/// <param name="shape">The shape (α) of the distribution. Range: α > 0.</param>
/// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<double> Samples(double scale, double shape)
{
return Samples(SystemRandomSource.Default, scale, shape);
}
}
}

20
src/Numerics/Distributions/Rayleigh.cs

@ -337,5 +337,25 @@ namespace MathNet.Numerics.Distributions
yield return scale*Math.Sqrt(-2.0*Math.Log(rnd.NextDouble()));
}
}
/// <summary>
/// Generates a sample from the distribution.
/// </summary>
/// <param name="scale">The scale (σ) of the distribution. Range: σ > 0.</param>
/// <returns>a sample from the distribution.</returns>
public static double Sample(double scale)
{
return Sample(SystemRandomSource.Default, scale);
}
/// <summary>
/// Generates a sequence of samples from the distribution.
/// </summary>
/// <param name="scale">The scale (σ) of the distribution. Range: σ > 0.</param>
/// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<double> Samples(double scale)
{
return Samples(SystemRandomSource.Default, scale);
}
}
}

26
src/Numerics/Distributions/Stable.cs

@ -489,5 +489,31 @@ namespace MathNet.Numerics.Distributions
yield return SampleUnchecked(rnd, alpha, beta, scale, location);
}
}
/// <summary>
/// Generates a sample from the distribution.
/// </summary>
/// <param name="alpha">The stability (α) of the distribution. Range: 2 ≥ α > 0.</param>
/// <param name="beta">The skewness (β) of the distribution. Range: 1 ≥ β ≥ -1.</param>
/// <param name="scale">The scale (c) of the distribution. Range: c > 0.</param>
/// <param name="location">The location (μ) of the distribution.</param>
/// <returns>a sample from the distribution.</returns>
public static double Sample(double alpha, double beta, double scale, double location)
{
return Sample(SystemRandomSource.Default, alpha, beta, scale, location);
}
/// <summary>
/// Generates a sequence of samples from the distribution.
/// </summary>
/// <param name="alpha">The stability (α) of the distribution. Range: 2 ≥ α > 0.</param>
/// <param name="beta">The skewness (β) of the distribution. Range: 1 ≥ β ≥ -1.</param>
/// <param name="scale">The scale (c) of the distribution. Range: c > 0.</param>
/// <param name="location">The location (μ) of the distribution.</param>
/// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<double> Samples(double alpha, double beta, double scale, double location)
{
return Samples(SystemRandomSource.Default, alpha, beta, scale, location);
}
}
}

24
src/Numerics/Distributions/StudentT.cs

@ -484,5 +484,29 @@ namespace MathNet.Numerics.Distributions
yield return SampleUnchecked(rnd, location, scale, freedom);
}
}
/// <summary>
/// Generates a sample from the Student t-distribution.
/// </summary>
/// <param name="location">The location (μ) of the distribution.</param>
/// <param name="scale">The scale (σ) of the distribution. Range: σ > 0.</param>
/// <param name="freedom">The degrees of freedom (ν) for the distribution. Range: ν > 0.</param>
/// <returns>a sample from the distribution.</returns>
public static double Sample(double location, double scale, double freedom)
{
return Sample(SystemRandomSource.Default, location, scale, freedom);
}
/// <summary>
/// Generates a sequence of samples from the Student t-distribution using the <i>Box-Muller</i> algorithm.
/// </summary>
/// <param name="location">The location (μ) of the distribution.</param>
/// <param name="scale">The scale (σ) of the distribution. Range: σ > 0.</param>
/// <param name="freedom">The degrees of freedom (ν) for the distribution. Range: ν > 0.</param>
/// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<double> Samples(double location, double scale, double freedom)
{
return Samples(SystemRandomSource.Default, location, scale, freedom);
}
}
}

23
src/Numerics/Distributions/Triangular.cs

@ -416,5 +416,28 @@ namespace MathNet.Numerics.Distributions
}
}
/// <summary>
/// Generates a sample from the <c>Triangular</c> distribution.
/// </summary>
/// <param name="lower">Lower bound. Range: lower ≤ mode ≤ upper</param>
/// <param name="upper">Upper bound. Range: lower ≤ mode ≤ upper</param>
/// <param name="mode">Mode (most frequent value). Range: lower ≤ mode ≤ upper</param>
/// <returns>a sample from the distribution.</returns>
public double Sample(double lower, double upper, double mode)
{
return Sample(SystemRandomSource.Default, lower, upper, mode);
}
/// <summary>
/// Generates a sequence of samples from the <c>Triangular</c> distribution.
/// </summary>
/// <param name="lower">Lower bound. Range: lower ≤ mode ≤ upper</param>
/// <param name="upper">Upper bound. Range: lower ≤ mode ≤ upper</param>
/// <param name="mode">Mode (most frequent value). Range: lower ≤ mode ≤ upper</param>
/// <returns>a sequence of samples from the distribution.</returns>
public IEnumerable<double> Samples(double lower, double upper, double mode)
{
return Samples(SystemRandomSource.Default, lower, upper, mode);
}
}
}

22
src/Numerics/Distributions/Weibull.cs

@ -413,5 +413,27 @@ namespace MathNet.Numerics.Distributions
yield return SampleUnchecked(rnd, shape, scale);
}
}
/// <summary>
/// Generates a sample from the Weibull distribution.
/// </summary>
/// <param name="shape">The shape (k) of the Weibull distribution. Range: k > 0.</param>
/// <param name="scale">The scale (λ) of the Weibull distribution. Range: λ > 0.</param>
/// <returns>a sample from the distribution.</returns>
public static double Sample(double shape, double scale)
{
return Sample(SystemRandomSource.Default, shape, scale);
}
/// <summary>
/// Generates a sequence of samples from the Weibull distribution.
/// </summary>
/// <param name="shape">The shape (k) of the Weibull distribution. Range: k > 0.</param>
/// <param name="scale">The scale (λ) of the Weibull distribution. Range: λ > 0.</param>
/// <returns>a sequence of samples from the distribution.</returns>
public static IEnumerable<double> Samples(double shape, double scale)
{
return Samples(SystemRandomSource.Default, shape, scale);
}
}
}

Loading…
Cancel
Save