public static long binomialCoefficient(final int n, final int k) throws NotPositiveException, NumberIsTooLargeException, MathArithmeticException { return CombinatoricsUtils.binomialCoefficient(n, k);
return FastMath.log(binomialCoefficient(n,k));
/** * @param vector vector whose dot product with hashed vectors is to be maximized * @return indices of partitions containing candidates to check */ int[] getCandidateIndices(float[] vector) { int mainIndex = getIndexFor(vector); // Simple cases int numHashes = getNumHashes(); if (numHashes == maxBitsDiffering) { return allIndices; } if (maxBitsDiffering == 0) { return new int[] { mainIndex }; } // Other cases int howMany = 0; for (int i = 0; i <= maxBitsDiffering; i++) { howMany += (int) CombinatoricsUtils.binomialCoefficient(numHashes, i); } int[] result = new int[howMany]; System.arraycopy(candidateIndicesPrototype, 0, result, 0, howMany); for (int i = 0; i < howMany; i++) { result[i] ^= mainIndex; } return result; }
return binomialCoefficient(n,k);
numPartitionsToTry += CombinatoricsUtils.binomialCoefficient(numHashes, bitsDiffering); int[] offsetPerBitsActive = new int[numHashes + 1]; for (int i = 1; i <= numHashes; i++) { offsetPerBitsActive[i] = offsetPerBitsActive[i-1] + (int) CombinatoricsUtils.binomialCoefficient(numHashes, i-1);
for (int i = 0; i < dp1; i++){ for(int j = 0; j <= i; j++){ coeff[i][j] = (int) CombinatoricsUtils.binomialCoefficient(i, j);
return (1l << (n - 1)) - 1l; } else if (k == n - 1) { return binomialCoefficient(n, 2); } else { for (int j = 1; j <= k; ++j) { sign = -sign; sum += sign * binomialCoefficient(k, j) * ArithmeticUtils.pow(j, n); if (sum < 0) {
return binomialCoefficient(n, n - k);
private static void doTestHashesBits(double sampleRate, int numCores, int numHashes, int maxBitsDiffering) { LocalitySensitiveHash lsh = new LocalitySensitiveHash(sampleRate, 10, numCores); assertEquals(numHashes, lsh.getNumHashes()); assertEquals(1L << numHashes, lsh.getNumPartitions()); assertEquals(maxBitsDiffering, lsh.getMaxBitsDiffering()); if (sampleRate == 1.0) { assertEquals(lsh.getMaxBitsDiffering(), lsh.getNumHashes()); } long partitionsToTry = 0; for (int i = 0; i <= maxBitsDiffering; i++) { partitionsToTry += CombinatoricsUtils.binomialCoefficient(numHashes, i); } if (numHashes < LocalitySensitiveHash.MAX_HASHES) { assertLessOrEqual((double) partitionsToTry / (1 << numHashes), sampleRate); } }
/** * Calculates the number of <code>k</code> sized multisubsets that can be * formed in a set of size <code>n</code>. See * <a href="https://en.wikipedia.org/wiki/Combination# * Number_of_combinations_with_repetition">Wikipedia</a> for a description. * * @param n The size of the set to create subsets from. * @param k The size of the multisubsets. * @return The number of multisubsets. */ static long multichoose(int n, int k) { return CombinatoricsUtils.binomialCoefficient(n + k - 1, k); }
public static long binomialCoefficient(final int n, final int k) throws NotPositiveException, NumberIsTooLargeException, MathArithmeticException { return CombinatoricsUtils.binomialCoefficient(n, k);
@Override public Object doWork(Object... values) throws IOException { if(2 != values.length){ throw new IOException(String.format(Locale.ROOT,"%s(...) only works with 2 values but %d were provided", constructingFactory.getFunctionName(getClass()), values.length)); } int set = ((Number)values[0]).intValue(); int subset = ((Number)values[1]).intValue(); return CombinatoricsUtils.binomialCoefficient(set, subset); } }
public static long binomialCoefficient(final int n, final int k) throws NotPositiveException, NumberIsTooLargeException, MathArithmeticException { return CombinatoricsUtils.binomialCoefficient(n, k);
for (int i = 0; i < dp1; i++){ for(int j = 0; j <= i; j++){ coeff[i][j] = (int) CombinatoricsUtils.binomialCoefficient(i, j);
@Test public void testHetAltDepthDistribution() throws Exception { final int N = 6; final double p = 0.5; final List<ArrayList<Double>> distribution = TheoreticalSensitivity.hetAltDepthDistribution(N); for (int n = 0; n < N - 1; n++) { for (int m = 0; m <= n; m++) { final long binomialCoefficient = CombinatoricsUtils.binomialCoefficient(n, m); Assert.assertEquals(distribution.get(n).get(m), binomialCoefficient * Math.pow(p, n)); } } }
for (int i = 0; i < dp1; i++){ for(int j = 0; j <= i; j++){ coeff[i][j] = (int) CombinatoricsUtils.binomialCoefficient(i, j);
private DoubleMatrix getDiffMatrix(int m, int k) { ArgChecker.isTrue(k < m, "difference order too high"); double[][] data = new double[m][m]; if (m == 0) { return DoubleMatrix.copyOf(data); } int[] coeff = new int[k + 1]; int sign = 1; for (int i = k; i >= 0; i--) { coeff[i] = (int) (sign * binomialCoefficient(k, i)); sign *= -1; } for (int i = k; i < m; i++) { for (int j = 0; j < k + 1; j++) { data[i][j + i - k] = coeff[j]; } } DoubleMatrix d = DoubleMatrix.copyOf(data); DoubleMatrix dt = _algebra.getTranspose(d); return (DoubleMatrix) _algebra.multiply(dt, d); }
/** * get the k^th order difference matrix, D, which acts on a vector, x, of length m to produce the k^th order * difference vector. The first k rows of D are set to zero - because of this D_1 * D_1 != D_2<p> * For example, for x = {x1,x2,....xn}, D_1 * x = {0, x2-x1, x3-x2,...., xn - x(n-1)} and * D_2 * x = {0,0, x3-2*x2+x1,....,xn-2*x(n-1)+x(n-2)} etc * @param m Length of the vector * @param k Difference order. Require m > k * @return The k^th order difference matrix */ public static DoubleMatrix getDifferenceMatrix(int m, int k) { ArgChecker.notNegativeOrZero(m, "m"); ArgChecker.notNegative(k, "k"); ArgChecker.isTrue(k < m, "Difference order too high, require m > k, but have: m = {} and k = {}", m, k); if (k == 0) { return DoubleMatrix.identity(m); } int[] coeff = new int[k + 1]; int sign = 1; for (int i = k; i >= 0; i--) { coeff[i] = (int) (sign * binomialCoefficient(k, i)); sign = -sign; } double[][] data = new double[m][m]; for (int i = k; i < m; i++) { for (int j = 0; j < k + 1; j++) { data[i][j + i - k] = coeff[j]; } } return DoubleMatrix.ofUnsafe(data); }