30 lines
1.2 KiB
C#
30 lines
1.2 KiB
C#
using System.Numerics;
|
|
|
|
namespace FastRng.Distributions;
|
|
|
|
public sealed class StudentTNu1<TNum> : Distribution<TNum> where TNum : IFloatingPointIeee754<TNum>
|
|
{
|
|
private static readonly TNum HALF = TNum.CreateChecked(0.5f);
|
|
private static readonly TNum TWO = TNum.CreateChecked(2f);
|
|
private static readonly TNum NU = TNum.One;
|
|
private static readonly TNum START = TNum.Zero;
|
|
private static readonly TNum COMPRESS = TNum.One;
|
|
private static readonly TNum CONSTANT = TNum.CreateChecked(3.14190548592729f);
|
|
|
|
private static readonly TNum DIVIDEND;
|
|
private static readonly TNum DIVISOR;
|
|
private static readonly TNum EXPONENT;
|
|
|
|
static StudentTNu1()
|
|
{
|
|
DIVIDEND = MathToolsFloatingPoint<TNum>.Gamma((NU + TNum.One) * HALF);
|
|
DIVISOR = TNum.Sqrt(NU * TNum.Pi) * MathToolsFloatingPoint<TNum>.Gamma(NU * HALF);
|
|
EXPONENT = -((NU + TNum.One) * HALF);
|
|
}
|
|
|
|
public StudentTNu1(IRandom<TNum> rng) : base(rng)
|
|
{
|
|
}
|
|
|
|
private protected override TNum ShapeFunction(TNum x) => CONSTANT * TNum.Pow((DIVIDEND / DIVISOR) * TNum.Pow( TNum.One + TNum.Pow(START + x * COMPRESS, TWO) / NU, EXPONENT), COMPRESS);
|
|
} |