Java Code Examples for com.google.common.math.IntMath#binomial()

The following examples show how to use com.google.common.math.IntMath#binomial() . 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: GuavaMathUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public void should_calculate_binomial() {
    int result = IntMath.binomial(7, 3);
    assertThat(result, equalTo(35));
}
 
Example 2
Source File: GuavaIntMathUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public void whenPerformBinomialOnTwoIntegerValues_shouldReturnResultIfUnderInt() {
    int result = IntMath.binomial(6, 3);
    assertEquals(20, result);
}
 
Example 3
Source File: GuavaIntMathUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public void whenPerformBinomialOnTwoIntegerValues_shouldReturnIntMaxIfUnderInt() {
    int result = IntMath.binomial(Integer.MAX_VALUE, 3);
    assertEquals(Integer.MAX_VALUE, result);
}
 
Example 4
Source File: BgenGenotypeData.java    From systemsgenetics with GNU General Public License v3.0 2 votes vote down vote up
/**
	 * Return the number of probabilities for a sample with ploidy <i>r</i> and
	 * variant with <i>n</i> number of alleles - 1.
	 *
	 * @param r The ploidy of the sample.
	 * @param nMinOne The number of alleles for a variant - 1.
	 * @return The number of probabilities that are used.
	 */
	public static int numberOfProbabilitiesForPloidyAlleleCountCombination(int r, int nMinOne) {
//        return IntMath.factorial(r + nMinOne) /
//                (IntMath.factorial(r) * IntMath.factorial(nMinOne));
		return IntMath.binomial(nMinOne + r, r); // This is quicker
	}