|
|
|
@ -3,7 +3,7 @@ |
|
|
|
// http://numerics.mathdotnet.com
|
|
|
|
// http://github.com/mathnet/mathnet-numerics
|
|
|
|
//
|
|
|
|
// Copyright (c) 2009-2019 Math.NET
|
|
|
|
// Copyright (c) 2009-2020 Math.NET
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person
|
|
|
|
// obtaining a copy of this software and associated documentation
|
|
|
|
@ -482,6 +482,43 @@ namespace MathNet.Numerics.Distributions |
|
|
|
return _d?.DensityLn(x) ?? PDFLn(Location, Scale, Skew, P, Q, x); |
|
|
|
} |
|
|
|
|
|
|
|
public double Sample() |
|
|
|
{ |
|
|
|
return SampleUnchecked(_random, Location, Scale, Skew, P, Q); |
|
|
|
} |
|
|
|
|
|
|
|
public void Samples(double[] values) |
|
|
|
{ |
|
|
|
SamplesUnchecked(_random, values, Location, Scale, Skew, P, Q); |
|
|
|
} |
|
|
|
|
|
|
|
public IEnumerable<double> Samples() |
|
|
|
{ |
|
|
|
return SamplesUnchecked(_random, Location, Scale, Skew, P, Q); |
|
|
|
} |
|
|
|
|
|
|
|
static double SampleUnchecked(System.Random rnd, double location, double scale, double skew, double p, double q) |
|
|
|
{ |
|
|
|
var u = ContinuousUniform.Sample(rnd, 0, 1); |
|
|
|
return InvCDF(location, scale, skew, p, q, u); |
|
|
|
} |
|
|
|
|
|
|
|
static void SamplesUnchecked(System.Random rnd, double[] values, double location, double scale, double skew, double p, double q) |
|
|
|
{ |
|
|
|
for (int i = 0; i < values.Length; i++) |
|
|
|
{ |
|
|
|
values[i] = SampleUnchecked(rnd, location, scale, skew, p, q); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static IEnumerable<double> SamplesUnchecked(System.Random rnd, double location, double scale, double skew, double p, double q) |
|
|
|
{ |
|
|
|
while (true) |
|
|
|
{ |
|
|
|
yield return SampleUnchecked(rnd, location, scale, skew, p, q); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Generates a sample from the Skew Generalized t-distribution.
|
|
|
|
/// </summary>
|
|
|
|
@ -519,22 +556,39 @@ namespace MathNet.Numerics.Distributions |
|
|
|
throw new ArgumentException(Resources.InvalidDistributionParameters); |
|
|
|
} |
|
|
|
|
|
|
|
while (true) |
|
|
|
{ |
|
|
|
yield return SampleUnchecked(rnd, location, scale, skew, p, q); |
|
|
|
} |
|
|
|
return SamplesUnchecked(rnd, location, scale, skew, p, q); |
|
|
|
} |
|
|
|
|
|
|
|
public static IEnumerable<double> Samples(double location, double scale, double skew, double p, double q) |
|
|
|
/// <summary>
|
|
|
|
/// Fills an array with samples from the Skew Generalized t-distribution using inverse transform.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="rnd">The random number generator to use.</param>
|
|
|
|
/// <param name="values">The array to fill with the samples.</param>
|
|
|
|
/// <param name="location">The location (μ) of the distribution.</param>
|
|
|
|
/// <param name="scale">The scale (σ) of the distribution. Range: σ > 0.</param>
|
|
|
|
/// <param name="skew">The skew, 1 > λ > -1</param>
|
|
|
|
/// <param name="p">First parameter that controls kurtosis. Range: p > 0</param>
|
|
|
|
/// <param name="q">Second parameter that controls kurtosis. Range: q > 0</param>
|
|
|
|
/// <returns>a sequence of samples from the distribution.</returns>
|
|
|
|
public static void Samples(System.Random rnd, double[] values, double location, double scale, double skew, double p, double q) |
|
|
|
{ |
|
|
|
if (!IsValidParameterSet(location, scale, skew, p, q)) |
|
|
|
{ |
|
|
|
throw new ArgumentException(Resources.InvalidDistributionParameters); |
|
|
|
} |
|
|
|
|
|
|
|
return Samples(SystemRandomSource.Default, location, scale, skew, p, q); |
|
|
|
SamplesUnchecked(rnd, values, location, scale, skew, p, q); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Generates a sample from the Skew Generalized 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="skew">The skew, 1 > λ > -1</param>
|
|
|
|
/// <param name="p">First parameter that controls kurtosis. Range: p > 0</param>
|
|
|
|
/// <param name="q">Second parameter that controls kurtosis. Range: q > 0</param>
|
|
|
|
/// <returns>a sample from the distribution.</returns>
|
|
|
|
public static double Sample(double location, double scale, double skew, double p, double q) |
|
|
|
{ |
|
|
|
if (!IsValidParameterSet(location, scale, skew, p, q)) |
|
|
|
@ -545,31 +599,43 @@ namespace MathNet.Numerics.Distributions |
|
|
|
return SampleUnchecked(SystemRandomSource.Default, location, scale, skew, p, q); |
|
|
|
} |
|
|
|
|
|
|
|
static double SampleUnchecked(System.Random rnd, double location, double scale, double skew, double p, double q) |
|
|
|
/// <summary>
|
|
|
|
/// Generates a sequence of samples from the Skew Generalized t-distribution using inverse transform.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="location">The location (μ) of the distribution.</param>
|
|
|
|
/// <param name="scale">The scale (σ) of the distribution. Range: σ > 0.</param>
|
|
|
|
/// <param name="skew">The skew, 1 > λ > -1</param>
|
|
|
|
/// <param name="p">First parameter that controls kurtosis. Range: p > 0</param>
|
|
|
|
/// <param name="q">Second parameter that controls kurtosis. Range: q > 0</param>
|
|
|
|
/// <returns>a sequence of samples from the distribution.</returns>
|
|
|
|
public static IEnumerable<double> Samples(double location, double scale, double skew, double p, double q) |
|
|
|
{ |
|
|
|
var u = ContinuousUniform.Sample(rnd, 0, 1); |
|
|
|
return InvCDF(location, scale, skew, p, q, u); |
|
|
|
} |
|
|
|
if (!IsValidParameterSet(location, scale, skew, p, q)) |
|
|
|
{ |
|
|
|
throw new ArgumentException(Resources.InvalidDistributionParameters); |
|
|
|
} |
|
|
|
|
|
|
|
public double Sample() |
|
|
|
{ |
|
|
|
return SampleUnchecked(SystemRandomSource.Default, Location, Scale, Skew, P, Q); |
|
|
|
return SamplesUnchecked(SystemRandomSource.Default, location, scale, skew, p, q); |
|
|
|
} |
|
|
|
|
|
|
|
public void Samples(double[] values) |
|
|
|
/// <summary>
|
|
|
|
/// Fills an array with samples from the Skew Generalized t-distribution using inverse transform.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="values">The array to fill with the samples.</param>
|
|
|
|
/// <param name="location">The location (μ) of the distribution.</param>
|
|
|
|
/// <param name="scale">The scale (σ) of the distribution. Range: σ > 0.</param>
|
|
|
|
/// <param name="skew">The skew, 1 > λ > -1</param>
|
|
|
|
/// <param name="p">First parameter that controls kurtosis. Range: p > 0</param>
|
|
|
|
/// <param name="q">Second parameter that controls kurtosis. Range: q > 0</param>
|
|
|
|
/// <returns>a sequence of samples from the distribution.</returns>
|
|
|
|
public static void Samples(double[] values, double location, double scale, double skew, double p, double q) |
|
|
|
{ |
|
|
|
if (values == null) |
|
|
|
return; |
|
|
|
|
|
|
|
for (int i = 0; i < values.Length; i++) |
|
|
|
if (!IsValidParameterSet(location, scale, skew, p, q)) |
|
|
|
{ |
|
|
|
values[i] = Sample(); |
|
|
|
throw new ArgumentException(Resources.InvalidDistributionParameters); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public IEnumerable<double> Samples() |
|
|
|
{ |
|
|
|
return Samples(); |
|
|
|
SamplesUnchecked(SystemRandomSource.Default, values, location, scale, skew, p, q); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|