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

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

Introduction

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

Prototype

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

Source Link

Document

Returns the natural log 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:mastodon.algorithms.MHLinearAlgorithm.java

private void setupIterations() {
    //choose how many iterations to allocate to each "round" of pruning
    stepIterations = new double[maxPrunedSpeciesCount];
    for (int i = minPrunedSpeciesCount - 1; i < maxPrunedSpeciesCount; i++) {
        stepIterations[i] = ArithmeticUtils.binomialCoefficientLog(bts.getTaxaCount(), i + 1);
    }//ww  w  . j ava 2 s.  co m
    double sum = 0.0;
    for (double d : stepIterations) {
        sum += d;
    }

    //      if ((iterations[0] / sum * totalIterations) > bts.getTaxaCount()) {
    //         double temp = iterations[0];
    //         iterations[0] = bts.getTaxaCount();       
    //         for(int i = minPrunedSpeciesCount; i < maxPrunedSpeciesCount; i++) {   //might want to fill in spots below minPrun.. with 0's
    //            //need to check if temp gives the correct solution here but it's a "lost hope function" anyway
    //            iterations[i] = iterations[i] / (sum - temp) * (totalIterations - bts.getTaxaCount());
    //         }
    //      } else {
    for (int i = minPrunedSpeciesCount - 1; i < maxPrunedSpeciesCount; i++) {
        stepIterations[i] = (int) (stepIterations[i] / sum * totalIterations);
    }
    //      }
}

From source file:mastodon.algorithms.SALinearAlgorithm.java

private void setupIterations() {
    //choose how many iterations to allocate to each "round" of pruning
    stepIterations = new double[maxPrunedSpeciesCount];
    for (int i = minPrunedSpeciesCount - 1; i < maxPrunedSpeciesCount; i++) {
        stepIterations[i] = ArithmeticUtils.binomialCoefficientLog(bts.getTaxaCount(), i + 1);
    }//from w  w  w  . j  ava 2  s  .  com
    double sum = 0.0;
    for (double d : stepIterations) {
        sum += d;
    }

    for (int i = minPrunedSpeciesCount - 1; i < maxPrunedSpeciesCount; i++) {
        stepIterations[i] = (int) (stepIterations[i] / sum * totalIterations);
    }

}