Documentation of 'jsat.math.SpecialMath' Java class
SpecialMath
jsat.math

Class SpecialMath



  • public class SpecialMath
    extends java.lang.Object
    This class provides static methods for computing accurate approximations to many special functions.

    All methods should return absolute differences of less than 10-9 for all reasonable values. Unreasonable values would be those in areas of high change (such as those approaching positive / negative infinity).
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static double EULER_MASCHERONI 
    • Constructor Summary

      Constructors 
      Constructor and Description
      SpecialMath() 
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static double bernoulli(int n)
      Computes an approximation to the n'th Bernoulli number Bn.
      static double beta(double z, double w)
      Computes the Beta function B(z,w)
      static double betaIncReg(double x, double a, double b)
      Computes the regularized incomplete beta function, Ix(a, b).
      static double digamma(double x)
      Computes the value of the digamma function, Ψ(x), which is the derivative of lnGamma(double).
      static double erf(double x) 
      static double erfc(double x) 
      static double gamma(double z)
      The gamma function is a generalization of the factorial function.
      static double gammaIncLow(double a, double z)
      Computes the lower incomplete gamma function, γ(a,z).
      static double gammaIncUp(double a, double z)
      Computes the incomplete gamma function, Γ(a,z).
      static double gammaP(double a, double z)
      Returns the regularized gamma function P(a,z) = γ(a,z)/Γ(a).
      static double gammaPSeries(double a, double z) 
      static double gammaQ(double a, double z)
      Computes the regularized gamma function Q(a,z) = Γ(a,z)/Γ(a).
      static double harmonic(double n)
      Computes the n'th harmonic number Hn.
      static double harmonic(double n, double m)
      Computes the generalized n'th harmonic number of the m'th order Hn(m).
      static double invBetaIncReg(double p, double a, double b)
      Computes the inverse of the incomplete beta function, Ip-1(a,b), such that Ix(a, b) = p.
      static double invErf(double x) 
      static double invErfc(double x) 
      static double invGammaP(double p, double a)
      Finds the value x such that P(a,x) = p.
      static double invXlnX(double y) 
      static double lnBeta(double z, double w) 
      static double lnGamma(double z)
      Computes the natural logarithm of gamma(double).
      static double reLnBn(int n)
      Computes the real part of the natural logarithm of the Bernoulli numbers.
      static double zeta(double x)
      Computes the Riemann zeta function ζ(x) for some value of x

      This method may return:
      Double.NaN for x = 1 (would be complex infinity)

      NOTE: This method is not yet complete in terms of accuracy.
      static double zeta(double x, double a)
      Implements the Hurwitz zeta function ζ(x, a)
      The relative error of this implementation is less than 1e-4 for most positive values of x, though is lower for negative values of x.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SpecialMath

        public SpecialMath()
    • Method Detail

      • invXlnX

        public static double invXlnX(double y)
      • gamma

        public static double gamma(double z)
        The gamma function is a generalization of the factorial function. This method provides the gamma function for values from -Infinity to Infinity.
        Special Values:
        • Double.NaN returned if z = 0 or z = Double.NEGATIVE_INFINITY
        Parameters:
        z - any real value
        Returns:
        Γ(z)
      • lnGamma

        public static double lnGamma(double z)
        Computes the natural logarithm of gamma(double). This method is more numerically stable than taking the log of the result of Γ(z).
        Special Values:
        • Double.POSITIVE_INFINITY returned if z ≤ 0
        • Double.NaN returned if z = Double.NEGATIVE_INFINITY
        Parameters:
        z - any real number value
        Returns:
        Log(Γ(z))
      • digamma

        public static double digamma(double x)
        Computes the value of the digamma function, Ψ(x), which is the derivative of lnGamma(double).

        This method may return:
        • Double.NaN for zero and negative integer values (would be complex infinity)

        This method should be accurate to an absolute difference of 10-14 for all values that are not near an asymptote.
        Parameters:
        x - the value to compute the digamma function at
        Returns:
        the value of Ψ(x)
      • zeta

        public static double zeta(double x)
        Computes the Riemann zeta function ζ(x) for some value of x

        This method may return:
        • Double.NaN for x = 1 (would be complex infinity)


        NOTE: This method is not yet complete in terms of accuracy.
        • For x < -0.5, the values returned will be of the correct magnitude - but are not very accurate
        • For x in [-0.5, 2.5], the values returned will be of reasonable accurate (absolute difference around 10-7), unless it is very close to 1
        • For x > 2.5, the result will be very accurate (absolute difference less than 10-14
        Parameters:
        x - a real valued input
        Returns:
        ζ(x)
      • zeta

        public static double zeta(double x,
                                  double a)
        Implements the Hurwitz zeta function ζ(x, a)
        The relative error of this implementation is less than 1e-4 for most positive values of x, though is lower for negative values of x. Accuracy improves as a increases.
        Parameters:
        x - the first argument of the Hurwitz zeta function/
        a - the second argument, must be positive in all cases.
        Returns:
        the value of ζ(x, a), or Double.NaN if the result would be a Complex Infinity
      • harmonic

        public static double harmonic(double n)
        Computes the n'th harmonic number Hn.
        Note that the relative error of this method is less than 10-6 for the entire range, and decreases as n increases.
        Parameters:
        n - any non-negative value
        Returns:
        the value of Hn, of Double.NaN if n < 0
      • harmonic

        public static double harmonic(double n,
                                      double m)
        Computes the generalized n'th harmonic number of the m'th order Hn(m).
        Parameters:
        n - any non-negative value
        m - the harmonic order
        Returns:
        the value of Hn(m)
      • reLnBn

        public static double reLnBn(int n)
        Computes the real part of the natural logarithm of the Bernoulli numbers.
        The Bernoulli zeros for odd n will return Double.NEGATIVE_INFINITY and for any value less than 0 will return Double.NaN.



        Currently only accurate to an absolute difference of 10-11
        Parameters:
        n - the integer Bernoulli value to obtain an approximation of
        Returns:
        Re(Log(Bn))
      • bernoulli

        public static double bernoulli(int n)
        Computes an approximation to the n'th Bernoulli number Bn. The Bernoulli numbers grow in value rapidly, and so the accuracy of this method decays quickly. n > 20 should have the correct order of magnitude, but may not have many significant figures. reLnBn(int) should be used instead when possible.
        Parameters:
        n - the bernoulli number to compute
        Returns:
        Bn
      • erf

        public static double erf(double x)
      • invErf

        public static double invErf(double x)
      • erfc

        public static double erfc(double x)
      • invErfc

        public static double invErfc(double x)
      • beta

        public static double beta(double z,
                                  double w)
        Computes the Beta function B(z,w)
        Parameters:
        z -
        w -
        Returns:
        B(z,w)
      • lnBeta

        public static double lnBeta(double z,
                                    double w)
      • betaIncReg

        public static double betaIncReg(double x,
                                        double a,
                                        double b)
        Computes the regularized incomplete beta function, Ix(a, b). The result of which is always in the range [0, 1]
        Parameters:
        x - any value in the range [0, 1]
        a - any value ≥ 0
        b - any value ≥ 0
        Returns:
        the result in a range of [0,1]
      • invBetaIncReg

        public static double invBetaIncReg(double p,
                                           double a,
                                           double b)
        Computes the inverse of the incomplete beta function, Ip-1(a,b), such that Ix(a, b) = p. The returned value, x, will always be in the range [0,1]. The input p, must also be in the range [0,1].
        Parameters:
        p - any value in the range [0,1]
        a - any value ≥ 0
        b - any value ≥ 0
        Returns:
        the value x, such that Ix(a, b) will return p.
      • gammaQ

        public static double gammaQ(double a,
                                    double z)
        Computes the regularized gamma function Q(a,z) = Γ(a,z)/Γ(a).
        This method is more numerically stable and accurate than computing it via the direct method, and is always in the range [0,1].

        Note: The this method returns Double.NaN for a<0, though real values of Q(a,z) do exist
        Parameters:
        a - any value ≥ 0
        z - any value > 0
        Returns:
        Q(a,z)
      • gammaPSeries

        public static double gammaPSeries(double a,
                                          double z)
      • gammaP

        public static double gammaP(double a,
                                    double z)
        Returns the regularized gamma function P(a,z) = γ(a,z)/Γ(a).
        This method is more numerically stable and accurate than computing it via the direct method, and is always in the range [0,1].

        Note: The this method returns Double.NaN for a<0, though real values of P(a,z) do exist
        Parameters:
        a - any value ≥ 0
        z - any value > 0
        Returns:
        P(a,z)
      • invGammaP

        public static double invGammaP(double p,
                                       double a)
        Finds the value x such that P(a,x) = p.
        Parameters:
        a - any real value
        p - and value in the range [0, 1]
        Returns:
        the inverse
      • gammaIncUp

        public static double gammaIncUp(double a,
                                        double z)
        Computes the incomplete gamma function, Γ(a,z).
        Returns Double.NaN for z ≤ 0
        Parameters:
        a - any value (-∞, ∞)
        z - any value > 0
        Returns:
        Γ(a,z)
      • gammaIncLow

        public static double gammaIncLow(double a,
                                         double z)
        Computes the lower incomplete gamma function, γ(a,z).
        Returns Double.NaN for z ≤ 0
        Parameters:
        a - any value (-∞, ∞)
        z - any value > 0
        Returns:
        γ(a,z)

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.