Example usage for org.apache.commons.math3.util CombinatoricsUtils binomialCoefficientDouble

List of usage examples for org.apache.commons.math3.util CombinatoricsUtils binomialCoefficientDouble

Introduction

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

Prototype

public static double binomialCoefficientDouble(final int n, final int k)
        throws NotPositiveException, NumberIsTooLargeException, MathArithmeticException 

Source Link

Document

Returns a double 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:edu.asu.ca.kaushik.algorithms.permvector.utils.SCPHF.java

public static int SCPHF_LLL(int t, int k, int v) {
    double covP = 1.0d;

    for (int i = 1; i < t; i++) {
        covP = covP * (1.0d - 1 / Math.pow(v, i));
    }//w  w  w .  j  av  a  2  s  . c om

    double q = 1.0d - covP;

    double d = CombinatoricsUtils.binomialCoefficientDouble(k, t)
            - CombinatoricsUtils.binomialCoefficientDouble(k - t, t);

    return (int) Math.ceil((1 + Math.log(d)) / (-Math.log(q)));
}

From source file:edu.asu.ca.kaushik.algorithms.permvector.utils.CPHF.java

/**
 * A covering perfect hash family CPHF(n;k,v^t,t).
 * @param n//  w  ww  .  ja va2s  .  com
 * @param k
 * @param v
 * @param t
 */
public static int CPHF_LLL(int t, int k, int v) {
    double vTot = Math.pow(v, t);
    double nume = 1.0d;
    for (int i = 1; i < t; i++) {
        nume = nume * (vTot - Math.pow(v, i));
    }

    double dnom = Math.pow(vTot - 1.0d, t - 1);

    double q = 1.0d - nume / dnom;

    double d = CombinatoricsUtils.binomialCoefficientDouble(k, t)
            - CombinatoricsUtils.binomialCoefficientDouble(k - t, t);

    return (int) Math.ceil((1 + Math.log(d)) / (-Math.log(q)));
}

From source file:edu.asu.ca.kaushik.algorithms.structures.ColGrIterator2.java

/**
 * Memory efficient ColGrIterator. Generates the column groups on the fly.
 * Hence does not require huge memory. But takes a lot of time.
 * @param t//from  w ww. j  a  v  a2 s .  c  o  m
 * @param k
 */
public ColGrIterator2(int t, int k) {
    assert (t <= k);

    this.t = t;
    this.k = k;
    this.numGroups = (long) CombinatoricsUtils.binomialCoefficientDouble(k, t);
    this.count = 1;
    this.cols = new int[t];
    this.initiateCols();
}

From source file:it.unibo.alchemist.model.implementations.conditions.GenericMoleculePresentInNeighborhood.java

@Override
public double getPropensityConditioning() {
    double res = 0;
    for (final INode<T> n : env.getNeighborhood(getNode()).getNeighbors()) {
        res += CombinatoricsUtils.binomialCoefficientDouble(n.getConcentration(getMolecule()).intValue(),
                getQuantity().intValue());
    }/*from   w  w w . j a v  a  2  s.c o  m*/
    return res;
}

From source file:it.unibo.alchemist.model.implementations.conditions.BiomolPresentInEnv.java

@Override
public double getPropensityConditioning() {
    final double totalQuantity = getTotalQuantity();
    if (totalQuantity < getQuantity()) {
        return 0;
    }/*from w  ww  .  j a  va 2  s  .  co  m*/
    return CombinatoricsUtils.binomialCoefficientDouble((int) FastMath.round(totalQuantity),
            (int) FastMath.round(getQuantity()));
}

From source file:edu.asu.ca.kaushik.algorithms.randomized.lll.TwoStageSimpleMT.java

private int twoStageSimpleBound(int t, int k, int v) {
    double kChooset = CombinatoricsUtils.binomialCoefficientDouble(k, t);
    double vpowt = Math.pow(v, t);
    double denom = Math.log(vpowt / (vpowt - 1));
    double nume = Math.log(kChooset * vpowt * denom);
    return (int) Math.ceil(nume / denom);
}

From source file:com.rapidminer.tools.expression.internal.function.statistical.Binominal.java

@Override
protected double compute(double value1, double value2) {

    // special case for handling missing values
    if (Double.isNaN(value1) || Double.isNaN(value2)) {
        return Double.NaN;
    }//from  ww  w.  j  a va2s  .c  o m

    if (value1 < 0 || value2 < 0) {
        throw new FunctionInputException("expression_parser.function_non_negative", getFunctionName());
    }
    // This is the common definition for the case for k > n.
    if (value2 > value1) {
        return 0;
    } else {
        return CombinatoricsUtils.binomialCoefficientDouble((int) value1, (int) value2);
    }
}

From source file:dsp.unige.figures.FEC.java

/**
 * returns the error probability//from  www .ja  va2s  .c o m
 * @param gammaB avg. bit energy (Eb/N0)
 * @param n FEC block length
 * @param k   information bits in block
 * @param t FEC correction capability
 * @return the error probability
 */
public static double getBlockCodePE(double gammaB, int n, int k, int t) {
    return CombinatoricsUtils.binomialCoefficientDouble(n - 1, t)
            * Math.pow(Q(Math.sqrt(2 * (double) k / (double) n * gammaB)), t + 1);
}

From source file:edu.asu.ca.kaushik.algorithms.twostage.TwoStageColoring.java

@Override
protected int partialArraySize(int t, int k, int v) {
    double vpowt = Math.pow(v, t);
    double n1 = Math.ceil(
            Math.log(CombinatoricsUtils.binomialCoefficientDouble(k, t) * vpowt * Math.log(vpowt / (vpowt - 1)))
                    / Math.log(vpowt / (vpowt - 1)));
    double denom = Math.log(1 - (1 / vpowt));
    double n = (Math.log(this.times) + n1 * denom) / denom;
    return (int) Math.ceil(n);
}

From source file:edu.asu.ca.kaushik.algorithms.twostage.TwoStageOnlineGreedy.java

@Override
protected int partialArraySize(int t, int k, int v) {
    //Side effect; bad style
    this.second = new ListCA(t, k, v);
    this.t = t;//from  ww w . j a va  2 s .c  o m
    this.k = k;
    this.v = v;

    // function proper
    double vpowt = Math.pow(v, t);
    double n1 = Math.ceil(
            Math.log(CombinatoricsUtils.binomialCoefficientDouble(k, t) * vpowt * Math.log(vpowt / (vpowt - 1)))
                    / Math.log(vpowt / (vpowt - 1)));
    double denom = Math.log(1 - (1 / vpowt));
    double n = (Math.log(this.times) + n1 * denom) / denom;
    return (int) Math.ceil(n);
}