本文整理汇总了Java中org.apache.commons.math3.util.CombinatoricsUtils.factorial方法的典型用法代码示例。如果您正苦于以下问题:Java CombinatoricsUtils.factorial方法的具体用法?Java CombinatoricsUtils.factorial怎么用?Java CombinatoricsUtils.factorial使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.util.CombinatoricsUtils
的用法示例。
在下文中一共展示了CombinatoricsUtils.factorial方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
}
}
示例2: 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 (Δx, Δy, ...)
* @return value of the Taylor expansion at x + Δx, y + Δ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;
}
示例3: testReciprocal
import org.apache.commons.math3.util.CombinatoricsUtils; //导入方法依赖的package包/类
@Test
public void testReciprocal() {
for (double x = 0.1; x < 1.2; x += 0.1) {
DerivativeStructure r = new DerivativeStructure(1, 6, 0, x).reciprocal();
Assert.assertEquals(1 / x, r.getValue(), 1.0e-15);
for (int i = 1; i < r.getOrder(); ++i) {
double expected = ArithmeticUtils.pow(-1, i) * CombinatoricsUtils.factorial(i) /
FastMath.pow(x, i + 1);
Assert.assertEquals(expected, r.getPartialDerivative(i), 1.0e-15 * FastMath.abs(expected));
}
}
}
示例4: testLog
import org.apache.commons.math3.util.CombinatoricsUtils; //导入方法依赖的package包/类
@Override
@Test
public void testLog() {
double[] epsilon = new double[] { 1.0e-16, 1.0e-16, 3.0e-14, 7.0e-13, 3.0e-11 };
for (int maxOrder = 0; maxOrder < 5; ++maxOrder) {
for (double x = 0.1; x < 1.2; x += 0.001) {
DerivativeStructure log = new DerivativeStructure(1, maxOrder, 0, x).log();
Assert.assertEquals(FastMath.log(x), log.getValue(), epsilon[0]);
for (int n = 1; n <= maxOrder; ++n) {
double refDer = -CombinatoricsUtils.factorial(n - 1) / FastMath.pow(-x, n);
Assert.assertEquals(refDer, log.getPartialDerivative(n), epsilon[n]);
}
}
}
}
示例5: eventsArrivalProbability
import org.apache.commons.math3.util.CombinatoricsUtils; //导入方法依赖的package包/类
/**
* Gets the probability to arrive {@link #getK() K} events in the current time,
* considering the expected average arrival time {@link #getLambda() lambda}.
* It computes the Probability Mass Function (PMF) of the Poisson distribution.
* @return
* @see <a href="https://en.wikipedia.org/wiki/Poisson_distribution">Poisson distribution</a>
*/
public double eventsArrivalProbability(){
return (Math.pow(getLambda(), k) * Math.exp(-getLambda())) / CombinatoricsUtils.factorial(k);
}