Exemple #1
0
        public double Pdf(double x)
        {
            double df2 = (df + 1) / 2;

            // Ln( Г((df + 1) / 2) / Г(df / 2) )
            double term1 = GammaFunction.LogValue(df2) - GammaFunction.LogValue(df / 2);

            // Ln( (1 + x^2 / df) ^ (-(df + 1) / 2) )
            double term2 = Log(1 + x.Sqr() / df) * -df2;

            return(Exp(term1 + term2) / Sqrt(PI * df));
        }
        public void GammaFunctionLogValue()
        {
            var comparer = new AbsoluteEqualityComparer(0.0001);

            for (int i = 0; i < knownX.Length; i++)
            {
                double expected = Math.Log(knownY[i]);
                double actual   = GammaFunction.LogValue(knownX[i]);

                output.WriteLine($"X = {knownX[i]}");
                output.WriteLine($"Expected = {expected}");
                output.WriteLine($"Actual   = {actual}");
                output.WriteLine("");

                Assert.Equal(expected, actual, comparer);
            }
        }