Java Code Examples for org.apache.commons.math3.util.CombinatoricsUtils#binomialCoefficientDouble()

The following examples show how to use org.apache.commons.math3.util.CombinatoricsUtils#binomialCoefficientDouble() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Binominal.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected double compute(double value1, double value2) {

	// special case for handling missing values
	if (Double.isNaN(value1) || Double.isNaN(value2) || Double.isInfinite(value1) || Double.isInfinite(value2)) {
		return Double.NaN;
	}

	int v1 = (int) value1;
	int v2 = (int) value2;

	if (v1 < 0 || v2 < 0) {
		throw new FunctionInputException("expression_parser.function_non_negative", getFunctionName());
	}
	// This is the common definition for the case for k > n.
	if (v2 > v1) {
		return 0;
	} else {
		return CombinatoricsUtils.binomialCoefficientDouble(v1, v2);
	}
}
 
Example 2
Source File: MoebiusTransformOWAValueFunction.java    From AILibs with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public double transform(final double nominator, final double denominator) {
	if ((int) nominator >= this.k) {
		return CombinatoricsUtils.binomialCoefficientDouble((int) nominator, this.k) / CombinatoricsUtils.binomialCoefficientDouble((int) denominator, this.k);
	} else {
		return 0;
	}
}
 
Example 3
Source File: PascalDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public double probability(int x) {
    double ret;
    if (x < 0) {
        ret = 0.0;
    } else {
        ret = CombinatoricsUtils.binomialCoefficientDouble(x +
              numberOfSuccesses - 1, numberOfSuccesses - 1) *
              FastMath.pow(probabilityOfSuccess, numberOfSuccesses) *
              FastMath.pow(1.0 - probabilityOfSuccess, x);
    }
    return ret;
}
 
Example 4
Source File: PascalDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public double probability(int x) {
    double ret;
    if (x < 0) {
        ret = 0.0;
    } else {
        ret = CombinatoricsUtils.binomialCoefficientDouble(x +
              numberOfSuccesses - 1, numberOfSuccesses - 1) *
              FastMath.pow(probabilityOfSuccess, numberOfSuccesses) *
              FastMath.pow(1.0 - probabilityOfSuccess, x);
    }
    return ret;
}
 
Example 5
Source File: PascalDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public double probability(int x) {
    double ret;
    if (x < 0) {
        ret = 0.0;
    } else {
        ret = CombinatoricsUtils.binomialCoefficientDouble(x +
              numberOfSuccesses - 1, numberOfSuccesses - 1) *
              FastMath.pow(probabilityOfSuccess, numberOfSuccesses) *
              FastMath.pow(1.0 - probabilityOfSuccess, x);
    }
    return ret;
}