C# Class NSoft.NFramework.Numerics.SpecialFunctions

Exibir arquivo Open project: debop/NFramework

Public Methods

Method Description
Beta ( this xs, IEnumerable ys ) : IEnumerable

Beta Function

Beta ( double x, double y ) : double

Beta Function

BetaIncomplete ( double a, double b, double x ) : double

Returns the lower incomplete (unregularized) beta function I_x(a,b) = int(t^(a-1)*(1-t)^(b-1),t=0..x) for real a > 0, b > 0, 1 >= x >= 0.

BetaLn ( this xs, IEnumerable ys ) : IEnumerable

Log Beta Function

BetaLn ( double x, double y ) : double

Log Beta Function

BetaRegularized ( double a, double b, double x ) : double

Returns the regularized lower incomplete beta function I_x(a,b) = 1/Beta(a,b) * int(t^(a-1)*(1-t)^(b-1),t=0..x) for real a > 0, b > 0, 1 >= x >= 0.

BetaRegularized ( double a, double b, double x, int maxIteration ) : double

Returns the regularized lower incomplete beta function I_x(a,b) = 1/Beta(a,b) * int(t^(a-1)*(1-t)^(b-1),t=0..x) for real a > 0, b > 0, 1 >= x >= 0.

Binomial ( int n, int k ) : double

Computes the binomial coefficient: n choose k.

BinomialLn ( int n, int k ) : double

Computes the natural logarithm of the binomial coefficient: ln(n choose k).

DiGamma ( double x ) : double

Computes the Digamma function which is mathematically defined as the derivative of the logarithm of the gamma function. This implementation is based on Jose Bernardo Algorithm AS 103: Psi ( Digamma ) Function, Applied Statistics, Volume 25, Number 3, 1976, pages 315-317. Using the modifications as in Tom Minka's lightspeed toolbox.

DiGammaInv ( double p ) : double

Computes the inverse Digamma function: this is the inverse of the logarithm of the gamma function. This function will only return solutions that are positive.

This implementation is based on the bisection method.

Erf ( double x ) : double

Calculates the error function.

returns 1 if x == Double.PositiveInfinity. returns -1 if x == Double.NegativeInfinity.

ErfInv ( double z ) : double

Calculates the inverse error function evaluated at z.

Calculates the inverse error function evaluated at z.

returns Double.PositiveInfinity if z >= 1.0. returns Double.NegativeInfinity if z <= -1.0.

Erfc ( double x ) : double

Calculates the complementary error function.

returns 0 if x == Double.PositiveInfinity. returns 2 if x == Double.NegativeInfinity.

ErfcInv ( double z ) : double

Calculates the complementary inverse error function evaluated at z.

calculates the complementary inverse error function evaluated at z.

We have tested this implementation against the arbitrary precision mpmath library and found cases where we can only guarantee 9 significant figures correct. returns Double.PositiveInfinity if z <= 0.0. returns Double.NegativeInfinity if z >= 2.0.

ExponentialMinusOne ( double power ) : double

Numerically stable exponential minus one, i.e. x -> exp(x)-1

Factorial ( int x ) : double

Computes the factorial function x -> x! of an integer number > 0. The function can represent all number up to 22! exactly, all numbers up to 170! using a double representation. All larger values will overflow.

If you need to multiply or divide various such factorials, consider using the logarithmic version FactorialLn instead so you can add instead of multiply and subtract instead of divide, and then exponentiate the result using System.Math.Exp. This will also circumvent the problem that factorials become very large even for small parameters.

FactorialLn ( int x ) : double

Computes the logarithmic factorial function x -> ln(x!) of an integer number > 0.

GeneralHarmonic ( int n, double m ) : double

Compute the generalized harmonic number of order n of m. (1 + 1/2^m + 1/3^m + ... + 1/n^m)

Harmonic ( int t ) : double

Computes the t'th Harmonic number.

Hypotenuse ( System.Complex a, System.Complex b ) : System.Complex

Numerically stable hypotenuse of a right angle triangle, i.e. (a,b) -> sqrt(a^2 + b^2)

Hypotenuse ( double a, double b ) : double

Numerically stable hypotenuse of a right angle triangle, i.e. (a,b) -> sqrt(a^2 + b^2)

Hypotenuse ( float a, float b ) : float

Numerically stable hypotenuse of a right angle triangle, i.e. (a,b) -> sqrt(a^2 + b^2)

Logistic ( double p ) : double

Computes the logistic function. see: http://en.wikipedia.org/wiki/Logistic

Logit ( double p ) : double

Computes the logit function. see: http://en.wikipedia.org/wiki/Logit

Multinomial ( int n, int ni ) : double

Computes the multinomial coefficient: n choose n1, n2, n3, ...

Private Methods

Method Description
ErfImp ( double z, bool invert ) : double

Implementation of the error function.

ErfInvImpl ( double p, double q, double s ) : double

The implementation of the inverse error function.

EvaluatePolynomial ( double poly, double z ) : double

A helper function to evaluate polynomials fast.

IntializeFactorial ( ) : void
Series ( Func nextSummand ) : double

Numerically stable series summation

SpecialFunctions ( )

Method Details

Beta() public static method

Beta Function
public static Beta ( this xs, IEnumerable ys ) : IEnumerable
xs this
ys IEnumerable
return IEnumerable

Beta() public static method

Beta Function
public static Beta ( double x, double y ) : double
x double
y double
return double

BetaIncomplete() public static method

Returns the lower incomplete (unregularized) beta function I_x(a,b) = int(t^(a-1)*(1-t)^(b-1),t=0..x) for real a > 0, b > 0, 1 >= x >= 0.
public static BetaIncomplete ( double a, double b, double x ) : double
a double The first Beta parameter, a positive real number.
b double The second Beta parameter, a positive real number.
x double The upper limit of the integral.
return double

BetaLn() public static method

Log Beta Function
public static BetaLn ( this xs, IEnumerable ys ) : IEnumerable
xs this
ys IEnumerable
return IEnumerable

BetaLn() public static method

Log Beta Function
public static BetaLn ( double x, double y ) : double
x double
y double
return double

BetaRegularized() public static method

Returns the regularized lower incomplete beta function I_x(a,b) = 1/Beta(a,b) * int(t^(a-1)*(1-t)^(b-1),t=0..x) for real a > 0, b > 0, 1 >= x >= 0.
public static BetaRegularized ( double a, double b, double x ) : double
a double The first Beta parameter, a positive real number.
b double The second Beta parameter, a positive real number.
x double The upper limit of the integral.
return double

BetaRegularized() public static method

Returns the regularized lower incomplete beta function I_x(a,b) = 1/Beta(a,b) * int(t^(a-1)*(1-t)^(b-1),t=0..x) for real a > 0, b > 0, 1 >= x >= 0.
public static BetaRegularized ( double a, double b, double x, int maxIteration ) : double
a double The first Beta parameter, a positive real number.
b double The second Beta parameter, a positive real number.
x double The upper limit of the integral.
maxIteration int 최대 반복 횟수
return double

Binomial() public static method

Computes the binomial coefficient: n choose k.
public static Binomial ( int n, int k ) : double
n int A nonnegative value n.
k int A nonnegative value h.
return double

BinomialLn() public static method

Computes the natural logarithm of the binomial coefficient: ln(n choose k).
public static BinomialLn ( int n, int k ) : double
n int A nonnegative value n.
k int A nonnegative value h.
return double

DiGamma() public static method

Computes the Digamma function which is mathematically defined as the derivative of the logarithm of the gamma function. This implementation is based on Jose Bernardo Algorithm AS 103: Psi ( Digamma ) Function, Applied Statistics, Volume 25, Number 3, 1976, pages 315-317. Using the modifications as in Tom Minka's lightspeed toolbox.
public static DiGamma ( double x ) : double
x double The argument of the digamma function.
return double

DiGammaInv() public static method

Computes the inverse Digamma function: this is the inverse of the logarithm of the gamma function. This function will only return solutions that are positive.

This implementation is based on the bisection method.

public static DiGammaInv ( double p ) : double
p double The argument of the inverse digamma function.
return double

Erf() public static method

Calculates the error function.
returns 1 if x == Double.PositiveInfinity. returns -1 if x == Double.NegativeInfinity.
public static Erf ( double x ) : double
x double The value to evaluate.
return double

ErfInv() public static method

Calculates the inverse error function evaluated at z. Calculates the inverse error function evaluated at z.
returns Double.PositiveInfinity if z >= 1.0. returns Double.NegativeInfinity if z <= -1.0.
public static ErfInv ( double z ) : double
z double value to evaluate.
return double

Erfc() public static method

Calculates the complementary error function.
returns 0 if x == Double.PositiveInfinity. returns 2 if x == Double.NegativeInfinity.
public static Erfc ( double x ) : double
x double The value to evaluate.
return double

ErfcInv() public static method

Calculates the complementary inverse error function evaluated at z. calculates the complementary inverse error function evaluated at z.
We have tested this implementation against the arbitrary precision mpmath library and found cases where we can only guarantee 9 significant figures correct. returns Double.PositiveInfinity if z <= 0.0. returns Double.NegativeInfinity if z >= 2.0.
public static ErfcInv ( double z ) : double
z double value to evaluate.
return double

ExponentialMinusOne() public static method

Numerically stable exponential minus one, i.e. x -> exp(x)-1
public static ExponentialMinusOne ( double power ) : double
power double A number specifying a power.
return double

Factorial() public static method

Computes the factorial function x -> x! of an integer number > 0. The function can represent all number up to 22! exactly, all numbers up to 170! using a double representation. All larger values will overflow.
If you need to multiply or divide various such factorials, consider using the logarithmic version FactorialLn instead so you can add instead of multiply and subtract instead of divide, and then exponentiate the result using System.Math.Exp. This will also circumvent the problem that factorials become very large even for small parameters.
public static Factorial ( int x ) : double
x int
return double

FactorialLn() public static method

Computes the logarithmic factorial function x -> ln(x!) of an integer number > 0.
public static FactorialLn ( int x ) : double
x int
return double

GeneralHarmonic() public static method

Compute the generalized harmonic number of order n of m. (1 + 1/2^m + 1/3^m + ... + 1/n^m)
public static GeneralHarmonic ( int n, double m ) : double
n int The order parameter.
m double The power parameter.
return double

Harmonic() public static method

Computes the t'th Harmonic number.
public static Harmonic ( int t ) : double
t int The Harmonic number which needs to be computed.
return double

Hypotenuse() public static method

Numerically stable hypotenuse of a right angle triangle, i.e. (a,b) -> sqrt(a^2 + b^2)
public static Hypotenuse ( System.Complex a, System.Complex b ) : System.Complex
a System.Complex The length of side a of the triangle.
b System.Complex The length of side b of the triangle.
return System.Complex

Hypotenuse() public static method

Numerically stable hypotenuse of a right angle triangle, i.e. (a,b) -> sqrt(a^2 + b^2)
public static Hypotenuse ( double a, double b ) : double
a double The length of side a of the triangle.
b double The length of side b of the triangle.
return double

Hypotenuse() public static method

Numerically stable hypotenuse of a right angle triangle, i.e. (a,b) -> sqrt(a^2 + b^2)
public static Hypotenuse ( float a, float b ) : float
a float The length of side a of the triangle.
b float The length of side b of the triangle.
return float

Logistic() public static method

Computes the logistic function. see: http://en.wikipedia.org/wiki/Logistic
public static Logistic ( double p ) : double
p double The parameter for which to compute the logistic function.
return double

Logit() public static method

Computes the logit function. see: http://en.wikipedia.org/wiki/Logit
public static Logit ( double p ) : double
p double The parameter for which to compute the logit function. This number should be /// between 0 and 1.
return double

Multinomial() public static method

Computes the multinomial coefficient: n choose n1, n2, n3, ...
if is . If or any of the are negative. If the sum of all is not equal to .
public static Multinomial ( int n, int ni ) : double
n int A nonnegative value n.
ni int An array of nonnegative values that sum to .
return double