From 74da81e8339b587e4ff8d32b502eabcd060e299b Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Sun, 1 Nov 2020 00:08:30 +0100 Subject: [PATCH] Added float implementations --- .../Float/Distributions/ExponentialLa10.cs | 12 +++++++++ FastRng/Float/Distributions/ExponentialLa5.cs | 12 +++++++++ FastRng/Float/Distributions/GammaA5B15.cs | 22 ++++++++++++++++ .../Distributions/InverseExponentialLa10.cs | 12 +++++++++ .../Distributions/InverseExponentialLa5.cs | 12 +++++++++ .../Float/Distributions/InverseGammaA3B05.cs | 23 +++++++++++++++++ FastRng/Float/Distributions/LaplaceB01M0.cs | 20 +++++++++++++++ FastRng/Float/Distributions/LaplaceB01M05.cs | 20 +++++++++++++++ FastRng/Float/Distributions/LogNormalS1M0.cs | 20 +++++++++++++++ FastRng/Float/Distributions/NormalS02M05.cs | 13 ++++++++++ FastRng/Float/Distributions/StudentTNu1.cs | 25 +++++++++++++++++++ FastRng/Float/Distributions/WeibullK05La1.cs | 13 ++++++++++ 12 files changed, 204 insertions(+) create mode 100644 FastRng/Float/Distributions/ExponentialLa10.cs create mode 100644 FastRng/Float/Distributions/ExponentialLa5.cs create mode 100644 FastRng/Float/Distributions/GammaA5B15.cs create mode 100644 FastRng/Float/Distributions/InverseExponentialLa10.cs create mode 100644 FastRng/Float/Distributions/InverseExponentialLa5.cs create mode 100644 FastRng/Float/Distributions/InverseGammaA3B05.cs create mode 100644 FastRng/Float/Distributions/LaplaceB01M0.cs create mode 100644 FastRng/Float/Distributions/LaplaceB01M05.cs create mode 100644 FastRng/Float/Distributions/LogNormalS1M0.cs create mode 100644 FastRng/Float/Distributions/NormalS02M05.cs create mode 100644 FastRng/Float/Distributions/StudentTNu1.cs create mode 100644 FastRng/Float/Distributions/WeibullK05La1.cs diff --git a/FastRng/Float/Distributions/ExponentialLa10.cs b/FastRng/Float/Distributions/ExponentialLa10.cs new file mode 100644 index 0000000..e2f83c2 --- /dev/null +++ b/FastRng/Float/Distributions/ExponentialLa10.cs @@ -0,0 +1,12 @@ +using System; + +namespace FastRng.Float.Distributions +{ + public sealed class ExponentialLa10 : Distribution + { + private const float LAMBDA = 10.0f; + private const float CONSTANT = 0.1106f; + + protected override float ShapeFunction(float x) => CONSTANT * LAMBDA * MathF.Exp(-LAMBDA * x); + } +} \ No newline at end of file diff --git a/FastRng/Float/Distributions/ExponentialLa5.cs b/FastRng/Float/Distributions/ExponentialLa5.cs new file mode 100644 index 0000000..3575aed --- /dev/null +++ b/FastRng/Float/Distributions/ExponentialLa5.cs @@ -0,0 +1,12 @@ +using System; + +namespace FastRng.Float.Distributions +{ + public sealed class ExponentialLa5 : Distribution + { + private const float LAMBDA = 5.0f; + private const float CONSTANT = 0.2103f; + + protected override float ShapeFunction(float x) => CONSTANT * LAMBDA * MathF.Exp(-LAMBDA * x); + } +} \ No newline at end of file diff --git a/FastRng/Float/Distributions/GammaA5B15.cs b/FastRng/Float/Distributions/GammaA5B15.cs new file mode 100644 index 0000000..86d55f6 --- /dev/null +++ b/FastRng/Float/Distributions/GammaA5B15.cs @@ -0,0 +1,22 @@ +using System; + +namespace FastRng.Float.Distributions +{ + public sealed class GammaA5B15 : Distribution + { + private const float ALPHA = 5.0f; + private const float BETA = 15.0f; + private const float CONSTANT = 0.341344210715475f; + + private static readonly float GAMMA_ALPHA; + private static readonly float BETA_TO_THE_ALPHA; + + static GammaA5B15() + { + GAMMA_ALPHA = MathTools.Gamma(ALPHA); + BETA_TO_THE_ALPHA = MathF.Pow(BETA, ALPHA); + } + + protected override float ShapeFunction(float x) => CONSTANT * ((BETA_TO_THE_ALPHA * MathF.Pow(x, ALPHA - 1.0f) * MathF.Exp(-BETA * x)) / GAMMA_ALPHA); + } +} \ No newline at end of file diff --git a/FastRng/Float/Distributions/InverseExponentialLa10.cs b/FastRng/Float/Distributions/InverseExponentialLa10.cs new file mode 100644 index 0000000..936cf51 --- /dev/null +++ b/FastRng/Float/Distributions/InverseExponentialLa10.cs @@ -0,0 +1,12 @@ +using System; + +namespace FastRng.Float.Distributions +{ + public sealed class InverseExponentialLa10 : Distribution + { + private const float LAMBDA = 10.0f; + private const float CONSTANT = 4.539992976248453e-06f; + + protected override float ShapeFunction(float x) => CONSTANT * LAMBDA * MathF.Exp(LAMBDA * x); + } +} \ No newline at end of file diff --git a/FastRng/Float/Distributions/InverseExponentialLa5.cs b/FastRng/Float/Distributions/InverseExponentialLa5.cs new file mode 100644 index 0000000..7705d62 --- /dev/null +++ b/FastRng/Float/Distributions/InverseExponentialLa5.cs @@ -0,0 +1,12 @@ +using System; + +namespace FastRng.Float.Distributions +{ + public sealed class InverseExponentialLa5 : Distribution + { + private const float LAMBDA = 5.0f; + private const float CONSTANT = 0.001347589399817f; + + protected override float ShapeFunction(float x) => CONSTANT * LAMBDA * MathF.Exp(LAMBDA * x); + } +} \ No newline at end of file diff --git a/FastRng/Float/Distributions/InverseGammaA3B05.cs b/FastRng/Float/Distributions/InverseGammaA3B05.cs new file mode 100644 index 0000000..b9a7678 --- /dev/null +++ b/FastRng/Float/Distributions/InverseGammaA3B05.cs @@ -0,0 +1,23 @@ +using System; + +namespace FastRng.Float.Distributions +{ + public sealed class InverseGammaA3B05 : Distribution + { + private const float ALPHA = 3.0f; + private const float BETA = 0.5f; + private const float CONSTANT = 0.213922656884911f; + + private static readonly float FACTOR_LEFT; + + static InverseGammaA3B05() + { + var gammaAlpha = MathTools.Gamma(ALPHA); + var betaToTheAlpha = MathF.Pow(BETA, ALPHA); + + FACTOR_LEFT = CONSTANT * (betaToTheAlpha / gammaAlpha); + } + + protected override float ShapeFunction(float x) => FACTOR_LEFT * MathF.Pow(x, -ALPHA - 1.0f) * MathF.Exp(-BETA / x); + } +} \ No newline at end of file diff --git a/FastRng/Float/Distributions/LaplaceB01M0.cs b/FastRng/Float/Distributions/LaplaceB01M0.cs new file mode 100644 index 0000000..6bdfc90 --- /dev/null +++ b/FastRng/Float/Distributions/LaplaceB01M0.cs @@ -0,0 +1,20 @@ +using System; + +namespace FastRng.Float.Distributions +{ + public sealed class LaplaceB01M0 : Distribution + { + private const float B = 0.1f; + private const float MU = 0.0f; + private const float CONSTANT = 0.221034183615129f; + + private static readonly float FACTOR_LEFT; + + static LaplaceB01M0() + { + FACTOR_LEFT = CONSTANT / (2.0f * B); + } + + protected override float ShapeFunction(float x) => FACTOR_LEFT * MathF.Exp(-MathF.Abs(x - MU) / B); + } +} \ No newline at end of file diff --git a/FastRng/Float/Distributions/LaplaceB01M05.cs b/FastRng/Float/Distributions/LaplaceB01M05.cs new file mode 100644 index 0000000..3bb4710 --- /dev/null +++ b/FastRng/Float/Distributions/LaplaceB01M05.cs @@ -0,0 +1,20 @@ +using System; + +namespace FastRng.Float.Distributions +{ + public sealed class LaplaceB01M05 : Distribution + { + private const float B = 0.1f; + private const float MU = 0.5f; + private const float CONSTANT = 0.2f; + + private static readonly float FACTOR_LEFT; + + static LaplaceB01M05() + { + FACTOR_LEFT = CONSTANT / (2.0f * B); + } + + protected override float ShapeFunction(float x) => FACTOR_LEFT * MathF.Exp(-MathF.Abs(x - MU) / B); + } +} \ No newline at end of file diff --git a/FastRng/Float/Distributions/LogNormalS1M0.cs b/FastRng/Float/Distributions/LogNormalS1M0.cs new file mode 100644 index 0000000..7ddfb10 --- /dev/null +++ b/FastRng/Float/Distributions/LogNormalS1M0.cs @@ -0,0 +1,20 @@ +using System; + +namespace FastRng.Float.Distributions +{ + public sealed class LogNormalS1M0 : Distribution + { + private const float SIGMA = 1.0f; + private const float MU = 0.0f; + private const float CONSTANT = 1.51998658387455f; + + private static readonly float FACTOR; + + static LogNormalS1M0() + { + FACTOR = SIGMA * MathF.Sqrt(2f * MathF.PI); + } + + protected override float ShapeFunction(float x) => (CONSTANT / (x * FACTOR)) * MathF.Exp( -(MathF.Pow(MathF.Log(x) - MU, 2f) / (2f * MathF.Pow(SIGMA, 2f)))); + } +} \ No newline at end of file diff --git a/FastRng/Float/Distributions/NormalS02M05.cs b/FastRng/Float/Distributions/NormalS02M05.cs new file mode 100644 index 0000000..7e3cac1 --- /dev/null +++ b/FastRng/Float/Distributions/NormalS02M05.cs @@ -0,0 +1,13 @@ +using System; + +namespace FastRng.Float.Distributions +{ + public sealed class NormalS02M05 : Distribution + { + private const float SQRT_2_PI = 2.506628275f; + private const float STDDEV = 0.2f; + private const float MEAN = 0.5f; + + protected override float ShapeFunction(float x) => 1.0f / (STDDEV * SQRT_2_PI) * MathF.Exp(-0.5f * MathF.Pow((x - MEAN) / STDDEV, 2.0f)); + } +} \ No newline at end of file diff --git a/FastRng/Float/Distributions/StudentTNu1.cs b/FastRng/Float/Distributions/StudentTNu1.cs new file mode 100644 index 0000000..8fb0910 --- /dev/null +++ b/FastRng/Float/Distributions/StudentTNu1.cs @@ -0,0 +1,25 @@ +using System; + +namespace FastRng.Float.Distributions +{ + public sealed class StudentTNu1 : Distribution + { + private const float NU = 1.0f; + private const float START = 0.0f; + private const float COMPRESS = 1.0f; + private const float CONSTANT = 3.14190548592729f; + + private static readonly float DIVIDEND; + private static readonly float DIVISOR; + private static readonly float EXPONENT; + + static StudentTNu1() + { + DIVIDEND = MathTools.Gamma((NU + 1.0f) * 0.5f); + DIVISOR = MathF.Sqrt(NU * MathF.PI) * MathTools.Gamma(NU * 0.5f); + EXPONENT = -((NU + 1.0f) * 0.5f); + } + + protected override float ShapeFunction(float x) => CONSTANT * MathF.Pow((DIVIDEND / DIVISOR) * MathF.Pow(1.0f + MathF.Pow(START + x * COMPRESS, 2f) / NU, EXPONENT), COMPRESS); + } +} \ No newline at end of file diff --git a/FastRng/Float/Distributions/WeibullK05La1.cs b/FastRng/Float/Distributions/WeibullK05La1.cs new file mode 100644 index 0000000..518447f --- /dev/null +++ b/FastRng/Float/Distributions/WeibullK05La1.cs @@ -0,0 +1,13 @@ +using System; + +namespace FastRng.Float.Distributions +{ + public sealed class WeibullK05La1 : Distribution + { + private const float K = 0.5f; + private const float LAMBDA = 1.0f; + private const float CONSTANT = 0.221034183615129f; + + protected override float ShapeFunction(float x) => CONSTANT * ( (K / LAMBDA) * MathF.Pow(x / LAMBDA, K - 1.0f) * MathF.Exp(-MathF.Pow(x/LAMBDA, K))); + } +} \ No newline at end of file