nr
Class SpecialFunctions

java.lang.Object
  extended by nr.SpecialFunctions

public class SpecialFunctions
extends java.lang.Object

Some useful functions

Author:
Daniel Wachsstock

Method Summary
static double chisq(double x, double n)
          chi square distribution.
static double logGamma(double x)
          Returns the natural logarithm of the gamma function.
static double randomExponential(double n)
          sum of n random exponentials.
static double randomGaussian(double dev)
          random gaussian with a given standard deviation
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

randomGaussian

public static double randomGaussian(double dev)
random gaussian with a given standard deviation


randomExponential

public static double randomExponential(double n)
sum of n random exponentials. The gamma deviate from Numerical Recipes section 7.3. Adds n random deviates with probability distribution p(x) = exp(-x)

Parameters:
n - the number of exponentials to add. A double, for flexibility with the rest of the program. If n does not represent an integer, for small n uses floor(n); for large n uses a function approximation that effectively interpolates between floor(n) and floor(n)+1.
Throws:
java.lang.IllegalArgumentException - if n < 1

chisq

public static double chisq(double x,
                           double n)
chi square distribution. Probability of a chi-square-distributed statistic (probability that the sum of the squares of n normally distributed random deviates with mean 0 and variance 1 exceeds a value x. The higher x is, the lower chisq is.

Parameters:
x - the sum-of-squares
n - the "degrees of freedom": the number of sums-of-squares minus the number of fitted parameters.
Throws:
java.lang.IllegalArgumentException - if x < 0 or n <= 0
java.lang.ArithmeticException - if the function cannot be estimated

logGamma

public static double logGamma(double x)
                       throws java.lang.ArithmeticException
Returns the natural logarithm of the gamma function. Copied from the CERN COLT package. n! is exp (logGamma (n+1))

Implementation:

Some code taken and adapted from the Java 2D Graph Package 2.4, which in turn is a port from the Cephes 2.2 Math Library (C). Most Cephes code (missing from the 2D Graph Package) directly ported.

Parameters:
x - the argument to the function
Throws:
java.lang.ArithmeticException - if the function overflows