Example usage for org.apache.commons.math3.util ArithmeticUtils binomialCoefficient

List of usage examples for org.apache.commons.math3.util ArithmeticUtils binomialCoefficient

Introduction

In this page you can find the example usage for org.apache.commons.math3.util ArithmeticUtils binomialCoefficient.

Prototype

public static long binomialCoefficient(final int n, final int k)
        throws NotPositiveException, NumberIsTooLargeException, MathArithmeticException 

Source Link

Document

Returns an exact representation of the <a href="http://mathworld.wolfram.com/BinomialCoefficient.html"> Binomial Coefficient</a>, " n choose k ", the number of k -element subsets that can be selected from an n -element set.

Usage

From source file:it.drwolf.ridire.index.cwb.scripts.CWBCorpusBuilder.java

public void calculateN() {
    int ret = 0;//from   w  ww  .j  a  v  a2 s.  c  o m
    if (this.getN() < 1) {
        return;
    }
    for (int k = 1; k <= this.getN(); k++) {
        ret += ArithmeticUtils.binomialCoefficient(this.getN(), k);
    }
    this.setLfNumber(ret);
}

From source file:flexflux.analyses.randomConditions.RandomConditions.java

public RandomConditions(int numberSimulations, ListOfInputRandomParameters inputRandomParameters,
        double gaussianMean, double gaussianStd, int minInputs, int maxInputs, ConstraintType type) {

    super(null);/*from   w ww. j  a v a 2s  .co  m*/

    this.numberSimulations = numberSimulations;
    this.inputRandomParameters = inputRandomParameters;
    this.gaussianMean = gaussianMean;
    this.gaussianStd = gaussianStd;
    this.type = type;

    if (minInputs > inputRandomParameters.size()) {
        minInputs = inputRandomParameters.size();
    }

    if (maxInputs > inputRandomParameters.size()) {
        maxInputs = inputRandomParameters.size();
    }

    this.minInputs = minInputs;
    this.maxInputs = maxInputs;

    // Calcul du nombre de combinaisons
    for (int i = minInputs; i <= maxInputs; i++) {
        try {
            numberOfCombinations += ArithmeticUtils.binomialCoefficient(inputRandomParameters.size(), i);
        } catch (MathArithmeticException e) {
            // TODO Auto-generated catch block
            numberOfCombinations = Long.MAX_VALUE;
            break;
        }
    }

    System.err.println("Number of combinations : " + numberOfCombinations);

    if (numberOfCombinations < numberSimulations) {
        System.err.println("Number of combinations (" + numberSimulations
                + ")< number of simulations : we can't have non redundant simulations");
        inputs = null;
        return;
    }

    inputs = new HashSet<String>();

    for (InputRandomParameters irp : inputRandomParameters) {
        inputs.add(irp.getId());
    }

    threads = new ArrayList<ThreadRandomConditions>();

}

From source file:edu.oregonstate.eecs.mcplan.util.Fn.java

/**
 * Computes the multinomial coefficient n multichoose k[], which is the
 * number of ways of putting n objects into m boxes such that each box
 * contains k_i objects.//from  w  w w  . j ava2  s .  co m
 * 
 * This implementation is exact, but beware of overflow.
 * 
 * This is a naive implementation using the definition of the multinomial
 * coefficient in terms of binomial coefficients. There are probably
 * much faster ways to do this.
 * 
 * @param n
 * @param k
 * @return
 */
public static int multinomialCoefficient(final int n, final int[] k) {
    int top = k[0];
    int product = 1; // k[0] choose k[0]
    for (int i = 1; i < k.length; ++i) {
        top += k[i];
        product *= ArithmeticUtils.binomialCoefficient(top, k[i]);
    }
    return product;
}

From source file:edu.oregonstate.eecs.mcplan.util.Fn.java

public static int multinomialTermCount(final int n, final int m) {
    return (int) ArithmeticUtils.binomialCoefficient(n + m - 1, n);
}

From source file:org.moeaframework.util.RotationMatrixBuilderTest.java

/**
 * Tests if the {@code rotateK} method produces valid rotation matrices.
 *///  www .  j av  a 2 s . c  o m
@Test
public void testRotateK() {
    for (int n = 2; n < N; n++) {
        for (int k = 0; k <= ArithmeticUtils.binomialCoefficient(n, 2); k++) {
            RotationMatrixBuilder builder = new RotationMatrixBuilder(n);
            builder.rotateK(k);

            for (int i = 0; i < 100; i++) {
                testRotationMatrix(builder.withRandomThetas().create());
            }
        }
    }
}

From source file:org.moeaframework.util.RotationMatrixBuilderTest.java

/**
 * Tests if the {@code rotateK} method produces valid rotation matrices.
 *//*from   w w w. ja  v a2s .co m*/
@Test
public void testRotateAll() {
    for (int n = 2; n < N; n++) {
        for (int k = 0; k <= ArithmeticUtils.binomialCoefficient(n, 2); k++) {
            RotationMatrixBuilder builder = new RotationMatrixBuilder(n);
            builder.rotateAll();

            for (int i = 0; i < 100; i++) {
                testRotationMatrix(builder.withThetas(Math.PI / 4).create());
            }
        }
    }
}