Added float implementations

This commit is contained in:
Thorsten Sommer 2020-11-01 00:08:30 +01:00
parent d4e4e2c1c9
commit 74da81e833
12 changed files with 204 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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))));
}
}

View File

@ -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));
}
}

View File

@ -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);
}
}

View File

@ -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)));
}
}