shared.stat.util
Class Combinatorics

java.lang.Object
  extended by shared.stat.util.Combinatorics

public class Combinatorics
extends Object

A collection of useful static methods for combinatorics.


Field Summary
protected static double[] GammaLnCoefficients
          A lookup table of coefficients in support of gammaLn(double).
 
Method Summary
static double gamma(double x)
          The gamma function.
static double gammaLn(double x)
          The log-gamma function.
protected static void orderedPartition(DynamicObjectArray<int[]> acc, int[] sizes, int nsizes, int nremaining)
          A helper method in support of orderedPartition(int, int, int).
static int[][] orderedPartition(int n)
          A facade for orderedPartition(int, int, int).
static int[][] orderedPartition(int n, int npartsLower, int npartsUpper)
          Calculates all ordered partitions of an n element set into at least npartsLower parts and at most (exclusive) npartsUpper parts.
protected static void partition(DynamicObjectArray<int[]> acc, int[] sizes, int nsizes, int currentSize, int nremaining)
          A helper method in support of partition(int, int, int).
static int[][] partition(int n)
          A facade for partition(int, int, int).
static int[][] partition(int n, int npartsLower, int npartsUpper)
          Calculates all partitions of an n element set into at least npartsLower parts and at most (exclusive) npartsUpper parts.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GammaLnCoefficients

protected static final double[] GammaLnCoefficients
A lookup table of coefficients in support of gammaLn(double).

Method Detail

partition

public static final int[][] partition(int n)
A facade for partition(int, int, int).

Parameters:
n - the number of elements.
Returns:
the partitions.

partition

public static final int[][] partition(int n,
                                      int npartsLower,
                                      int npartsUpper)
Calculates all partitions of an n element set into at least npartsLower parts and at most (exclusive) npartsUpper parts.

Parameters:
n - the number of elements.
npartsLower - the lower bound on the number of parts.
npartsUpper - the upper bound (exclusive) on the number of parts.
Returns:
the partitions.

partition

protected static final void partition(DynamicObjectArray<int[]> acc,
                                      int[] sizes,
                                      int nsizes,
                                      int currentSize,
                                      int nremaining)
A helper method in support of partition(int, int, int).

Parameters:
acc - the partition accumulator.
sizes - the partition sizes.
nsizes - the number of parts so far.
currentSize - the part size so far.
nremaining - the number of remaining elements.

orderedPartition

public static final int[][] orderedPartition(int n)
A facade for orderedPartition(int, int, int).

Parameters:
n - the number of elements.
Returns:
the ordered partitions.

orderedPartition

public static final int[][] orderedPartition(int n,
                                             int npartsLower,
                                             int npartsUpper)
Calculates all ordered partitions of an n element set into at least npartsLower parts and at most (exclusive) npartsUpper parts.

Parameters:
n - the number of elements.
npartsLower - the lower bound on the number of parts.
npartsUpper - the upper bound (exclusive) on the number of parts.
Returns:
the ordered partitions.

orderedPartition

protected static final void orderedPartition(DynamicObjectArray<int[]> acc,
                                             int[] sizes,
                                             int nsizes,
                                             int nremaining)
A helper method in support of orderedPartition(int, int, int).

Parameters:
acc - the ordered partition accumulator.
sizes - the ordered partition sizes.
nsizes - the number of parts so far.
nremaining - the number of remaining elements.

gamma

public static final double gamma(double x)
The gamma function.

Parameters:
x - the input value.
Returns:
the gamma function evaluation.

gammaLn

public static final double gammaLn(double x)
The log-gamma function.

Parameters:
x - the input value.
Returns:
the log-gamma function evaluation.