当前位置: 首页>>代码示例>>Java>>正文


Java CombinatoricsUtils类代码示例

本文整理汇总了Java中org.apache.commons.math3.util.CombinatoricsUtils的典型用法代码示例。如果您正苦于以下问题:Java CombinatoricsUtils类的具体用法?Java CombinatoricsUtils怎么用?Java CombinatoricsUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CombinatoricsUtils类属于org.apache.commons.math3.util包,在下文中一共展示了CombinatoricsUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: compute

import org.apache.commons.math3.util.CombinatoricsUtils; //导入依赖的package包/类
@Override
protected double compute(double value1, double value2) {

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

	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);
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:19,代码来源:Binominal.java

示例2: getCandidateIndices

import org.apache.commons.math3.util.CombinatoricsUtils; //导入依赖的package包/类
/**
 * @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;
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:27,代码来源:LocalitySensitiveHash.java

示例3: doTestHashesBits

import org.apache.commons.math3.util.CombinatoricsUtils; //导入依赖的package包/类
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);
  }
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:17,代码来源:LocalitySensitiveHashTest.java

示例4: Orthogonality

import org.apache.commons.math3.util.CombinatoricsUtils; //导入依赖的package包/类
/**
 * Tests if orthogonality relation regarding a fixed l holds true for all l between 0 and 5.
 */
@Test
@DisplayName("Test Orthogonality (l)")
public void testOrthogonalityL() {
    final double dx = 1e-4;
    for (int l1=0;l1<=5;l1++) {
        for (int l2=0;l2<=5;l2++) {
            for (int m=0;m<=l1 && m<=l2;m++) {
                final AssociatedLegendrePolynomial alp1 = new AssociatedLegendrePolynomial(l1,m);
                final AssociatedLegendrePolynomial alp2 = new AssociatedLegendrePolynomial(l2,m);
                double result = 0.0;
                final double expected = (2.0)/(2*l1+1) * ((double)CombinatoricsUtils.factorial(l1+m)/(double)CombinatoricsUtils.factorial(l1-m)) * MathHelper.kronecker(l1,l2);
                for (double x = -1.0; x <= 1.0; x+=dx) {
                    result += (alp1.value(x) * alp2.value(x)) * dx;
                }
                assertEquals(expected, result,  1e-3);
            }
        }

    }
}
 
开发者ID:vitrivr,项目名称:cineast,代码行数:24,代码来源:AssociatedLegendrePolynomialTest.java

示例5: taylor

import org.apache.commons.math3.util.CombinatoricsUtils; //导入依赖的package包/类
/** Evaluate Taylor expansion of a derivative structure.
 * @param ds array holding the derivative structure
 * @param dsOffset offset of the derivative structure in its array
 * @param delta parameters offsets (&Delta;x, &Delta;y, ...)
 * @return value of the Taylor expansion at x + &Delta;x, y + &Delta;y, ...
 * @throws MathArithmeticException if factorials becomes too large
 */
public double taylor(final double[] ds, final int dsOffset, final double ... delta)
   throws MathArithmeticException {
    double value = 0;
    for (int i = getSize() - 1; i >= 0; --i) {
        final int[] orders = getPartialDerivativeOrders(i);
        double term = ds[dsOffset + i];
        for (int k = 0; k < orders.length; ++k) {
            if (orders[k] > 0) {
                try {
                    term *= FastMath.pow(delta[k], orders[k]) /
                    CombinatoricsUtils.factorial(orders[k]);
                } catch (NotPositiveException e) {
                    // this cannot happen
                    throw new MathInternalError(e);
                }
            }
        }
        value += term;
    }
    return value;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:29,代码来源:DSCompiler.java

示例6: fisherPValue

import org.apache.commons.math3.util.CombinatoricsUtils; //导入依赖的package包/类
/**
 * Compute the p-value corresponding to the computed Fisher g-value.
 * A lower value implies a pattern match, but a decision can only
 * be made once a reasonable threshold is set.
 *
 * @return  the p-value corresponding to the Fisher g-value test.
 */
private double fisherPValue() {

    int N = periodogram.length;
    double fisherG = fisherG();

    int upperLimit = (int) Math.floor(1/fisherG);

    double[] values = new double[upperLimit];
    for(int k=0; k < upperLimit; k++) {
        double binomialCo = CombinatoricsUtils.binomialCoefficientDouble(N, k+1);
        values[k] = Math.pow(-1, k) * binomialCo * Math.pow((1-(k+1)*fisherG), N-1);
    }

    fisherPValue = new Sum().evaluate(values);
    return fisherPValue;

}
 
开发者ID:bcbwilla,项目名称:FourierMC,代码行数:25,代码来源:PatternDetection.java

示例7: BinomialModelFunctionGradient

import org.apache.commons.math3.util.CombinatoricsUtils; //导入依赖的package包/类
public BinomialModelFunctionGradient(double[] histogram, int trials, boolean zeroTruncated)
{
	super(histogram, trials, zeroTruncated);

	// We could ignore the first p value as it is always zero:
	//p = Arrays.copyOfRange(p, 1, p.length);
	// BUT then we would have to override the getP() method since this has 
	// an offset of 1 and assumes the index of p is X.

	final int n = trials;
	nC = new long[n + 1];
	for (int k = 0; k <= n; k++)
	{
		nC[k] = CombinatoricsUtils.binomialCoefficient(n, k);
	}
}
 
开发者ID:aherbert,项目名称:GDSC-SMLM,代码行数:17,代码来源:BinomialFitter.java

示例8: generate

import org.apache.commons.math3.util.CombinatoricsUtils; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public GaussianQuadratureData generate(int n) {
  ArgChecker.isTrue(n > 0, "n > 0");
  Pair<DoubleFunction1D, DoubleFunction1D>[] polynomials = JACOBI.getPolynomialsAndFirstDerivative(n, _alpha, _beta);
  Pair<DoubleFunction1D, DoubleFunction1D> pair = polynomials[n];
  DoubleFunction1D previous = polynomials[n - 1].getFirst();
  DoubleFunction1D function = pair.getFirst();
  DoubleFunction1D derivative = pair.getSecond();
  double[] x = new double[n];
  double[] w = new double[n];
  double root = 0;
  for (int i = 0; i < n; i++) {
    double d = 2 * n + _c;
    root = getInitialRootGuess(root, i, n, x);
    root = ROOT_FINDER.getRoot(function, derivative, root);
    x[i] = root;
    w[i] =
        GAMMA_FUNCTION.applyAsDouble(_alpha + n) * GAMMA_FUNCTION.applyAsDouble(_beta + n) /
            CombinatoricsUtils.factorialDouble(n) / GAMMA_FUNCTION.applyAsDouble(n + _c + 1) * d *
            Math.pow(2, _c)
            / (derivative.applyAsDouble(root) * previous.applyAsDouble(root));
  }
  return new GaussianQuadratureData(x, w);
}
 
开发者ID:OpenGamma,项目名称:Strata,代码行数:28,代码来源:GaussJacobiWeightAndAbscissaFunction.java

示例9: generate

import org.apache.commons.math3.util.CombinatoricsUtils; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public GaussianQuadratureData generate(int n) {
  ArgChecker.isTrue(n > 0);
  Pair<DoubleFunction1D, DoubleFunction1D>[] polynomials = LAGUERRE.getPolynomialsAndFirstDerivative(n, _alpha);
  Pair<DoubleFunction1D, DoubleFunction1D> pair = polynomials[n];
  DoubleFunction1D p1 = polynomials[n - 1].getFirst();
  DoubleFunction1D function = pair.getFirst();
  DoubleFunction1D derivative = pair.getSecond();
  double[] x = new double[n];
  double[] w = new double[n];
  double root = 0;
  for (int i = 0; i < n; i++) {
    root = ROOT_FINDER.getRoot(function, derivative, getInitialRootGuess(root, i, n, x));
    x[i] = root;
    w[i] =
        -GAMMA_FUNCTION.applyAsDouble(_alpha + n) / CombinatoricsUtils.factorialDouble(n) /
            (derivative.applyAsDouble(root) * p1.applyAsDouble(root));
  }
  return new GaussianQuadratureData(x, w);
}
 
开发者ID:OpenGamma,项目名称:Strata,代码行数:24,代码来源:GaussLaguerreWeightAndAbscissaFunction.java

示例10: calLogCompoundDens

import org.apache.commons.math3.util.CombinatoricsUtils; //导入依赖的package包/类
private static double calLogCompoundDens(RealVector betas, RealVector betaDens, int n, int k) {
	double logComb = CombinatoricsUtils.binomialCoefficientLog(n,k);
	int nBetas = betas.getDimension();
	RealVector dens = new ArrayRealVector(nBetas);
	for (int i = 0; i < nBetas; i++) {
		dens.setEntry(i, betaDens.getEntry(i) * FastMath.pow(betas.getEntry(i), k)
				* FastMath.pow(1 - betas.getEntry(i), n - k));
	}
	double prob = integSimpson(betas,dens);
	double logProb=(prob==0)?-1000:FastMath.log(prob); // avoid -Inf
	return logComb+logProb;
}
 
开发者ID:jasminezhoulab,项目名称:CancerLocator,代码行数:13,代码来源:CancerLocator.java

示例11: createRadialPolynomial

import org.apache.commons.math3.util.CombinatoricsUtils; //导入依赖的package包/类
/**
 * Creates and returns a new radial polynomial (R_nm) given two moments.
 *
 * @param n 1st moment (order) of the radial polynomial.
 * @param m 2nd moment (repetition) of the radial polynomial.
 * @return PolynomialFunction representing R_nm
 * @throws ArithmeticException If orders are to large and calculation of binomial coefficients fail.
 */
public static PolynomialFunction createRadialPolynomial(final int n, int m) {
    m = Math.abs(m); /* Make sure that m is positive. */
    String id = n + "-" + m; /* Construct ID for cache lookup. */

    /* Try to retrieve the function from cache. */
    if (RADIAL_FUNCTION_CACHE.containsKey(id)) {
        return RADIAL_FUNCTION_CACHE.get(id);
    }

    /* Initialize coefficients. */
    double[] coefficients = new double[n + 1];

    /* Now check if Polynomial 0 (for n-|m| = odd) .*/
    if ((n - m) % 2 != 0) {
      return new PolynomialFunction(coefficients); /* If (n-m) != even, return 0 function. */
    }
    int s_max = (n - m) / 2;

    double sign = -1.0;
    for (int s = 0; s <= s_max; ++s) {
        int position = n - 2 * s;
        long a = CombinatoricsUtils.binomialCoefficient(n-s, s);
        long b = CombinatoricsUtils.binomialCoefficient(n-2*s, s_max - s);
        coefficients[position] = (FastMath.pow(sign,s) * a * b);
    }

    PolynomialFunction function = new PolynomialFunction(coefficients);
    RADIAL_FUNCTION_CACHE.put(id, function);
    return function;
}
 
开发者ID:vitrivr,项目名称:cineast,代码行数:39,代码来源:PolynomialFunctionFactory.java

示例12: probability

import org.apache.commons.math3.util.CombinatoricsUtils; //导入依赖的package包/类
/** {@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;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:14,代码来源:PascalDistribution.java

示例13: logProbability

import org.apache.commons.math3.util.CombinatoricsUtils; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public double logProbability(int x) {
    double ret;
    if (x < 0) {
        ret = Double.NEGATIVE_INFINITY;
    } else {
        ret = CombinatoricsUtils.binomialCoefficientLog(x +
              numberOfSuccesses - 1, numberOfSuccesses - 1) +
              logProbabilityOfSuccess * numberOfSuccesses +
              log1mProbabilityOfSuccess * x;
    }
    return ret;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:15,代码来源:PascalDistribution.java

示例14: testWithCompleteGraph

import org.apache.commons.math3.util.CombinatoricsUtils; //导入依赖的package包/类
@Test
public void testWithCompleteGraph() throws Exception {
	// all vertex pairs are linked
	long expectedCount = CombinatoricsUtils.binomialCoefficient((int) completeGraphVertexCount, 2);

	// the intersection includes every vertex
	long expectedDistinctNeighborCount = completeGraphVertexCount;

	// the union only excludes the two vertices from the similarity score
	long expectedSharedNeighborCount = completeGraphVertexCount - 2;

	validate(completeGraph, expectedCount, expectedDistinctNeighborCount, expectedSharedNeighborCount);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:14,代码来源:JaccardIndexTest.java

示例15: testWithStarGraph

import org.apache.commons.math3.util.CombinatoricsUtils; //导入依赖的package包/类
@Test
public void testWithStarGraph() throws Exception {
	// all leaf vertices form a triplet with all other leaf vertices;
	// only the center vertex is excluded
	long expectedCount = CombinatoricsUtils.binomialCoefficient((int) starGraphVertexCount - 1, 2);

	// the intersection includes only the center vertex
	long expectedDistinctNeighborCount = 1;

	// the union includes only the center vertex
	long expectedSharedNeighborCount = 1;

	validate(starGraph, expectedCount, expectedDistinctNeighborCount, expectedSharedNeighborCount);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:15,代码来源:JaccardIndexTest.java


注:本文中的org.apache.commons.math3.util.CombinatoricsUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。