本文整理汇总了Java中org.apache.commons.math3.util.FastMath.tanh方法的典型用法代码示例。如果您正苦于以下问题:Java FastMath.tanh方法的具体用法?Java FastMath.tanh怎么用?Java FastMath.tanh使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.util.FastMath
的用法示例。
在下文中一共展示了FastMath.tanh方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: derivative
import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
public UnivariateFunction derivative() {
return new UnivariateFunction() {
/** {@inheritDoc} */
public double value(double x) {
final double tanhX = FastMath.tanh(x);
return 1 - tanhX * tanhX;
}
};
}
示例2: value
import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
public double value(double x) {
return FastMath.tanh(x);
}
示例3: tanh
import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
public SparseGradient tanh() {
final double t = FastMath.tanh(value);
return new SparseGradient(t, 1 - t * t, derivatives);
}
示例4: tanh
import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/** Compute hyperbolic tangent of a derivative structure.
* @param operand array holding the operand
* @param operandOffset offset of the operand in its array
* @param result array where result must be stored (for
* hyperbolic tangent the result array <em>cannot</em> be the input
* array)
* @param resultOffset offset of the result in its array
*/
public void tanh(final double[] operand, final int operandOffset,
final double[] result, final int resultOffset) {
// create the function value and derivatives
final double[] function = new double[1 + order];
final double t = FastMath.tanh(operand[operandOffset]);
function[0] = t;
if (order > 0) {
// the nth order derivative of tanh has the form:
// dn(tanh(x)/dxn = P_n(tanh(x))
// where P_n(t) is a degree n+1 polynomial with same parity as n+1
// P_0(t) = t, P_1(t) = 1 - t^2, P_2(t) = -2 t (1 - t^2) ...
// the general recurrence relation for P_n is:
// P_n(x) = (1-t^2) P_(n-1)'(t)
// as per polynomial parity, we can store coefficients of both P_(n-1) and P_n in the same array
final double[] p = new double[order + 2];
p[1] = 1;
final double t2 = t * t;
for (int n = 1; n <= order; ++n) {
// update and evaluate polynomial P_n(t)
double v = 0;
p[n + 1] = -n * p[n];
for (int k = n + 1; k >= 0; k -= 2) {
v = v * t2 + p[k];
if (k > 2) {
p[k - 2] = (k - 1) * p[k - 1] - (k - 3) * p[k - 3];
} else if (k == 2) {
p[0] = p[1];
}
}
if ((n & 0x1) == 0) {
v *= t;
}
function[n] = v;
}
}
// apply function composition
compose(operand, operandOffset, function, result, resultOffset);
}