Example usage for org.apache.commons.math3.util FastMath atanh

List of usage examples for org.apache.commons.math3.util FastMath atanh

Introduction

In this page you can find the example usage for org.apache.commons.math3.util FastMath atanh.

Prototype

public static double atanh(double a) 

Source Link

Document

Compute the inverse hyperbolic tangent of a number.

Usage

From source file:com.rapidminer.tools.expression.internal.function.trigonometric.ArcHyperbolicTangent.java

@Override
protected double compute(double value) {
    return Double.isNaN(value) ? Double.NaN : FastMath.atanh(value);
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.tree.NumberArithmetic.java

/**
 * Returns the hyperbolic arc tangent of the number.
 * //w w w .j  av  a  2s .  c  om
 * @param a the number
 * @return the hyperbolic arc tangent of the number
 * @see FastMath#atanh(double)
 */
public static Number atanh(Number a) {
    return FastMath.atanh(a.doubleValue());
}

From source file:de.tuberlin.uebb.jbop.example.DSCompilerOnlyCompose.java

@Override
public void atanh(final double[] operand, final double[] result) {

    // create the function value and derivatives
    final double[] function = new double[1 + order];
    final double x = operand[0];
    function[0] = FastMath.atanh(x);
    if (order > 0) {
        // the nth order derivative of atanh has the form:
        // dn(atanh(x)/dxn = Q_n(x) / (1 - x^2)^n
        // where Q_n(x) is a degree n-1 polynomial with same parity as n-1
        // Q_1(x) = 1, Q_2(x) = 2x, Q_3(x) = 6x^2 + 2 ...
        // the general recurrence relation for Q_n is:
        // Q_n(x) = (1-x^2) Q_(n-1)'(x) + 2(n-1) x Q_(n-1)(x)
        // as per polynomial parity, we can store coefficients of both Q_(n-1) and Q_n in the same array
        final double[] q = new double[order];
        q[0] = 1;// www . ja  v a2 s .  c o m
        final double x2 = x * x;
        final double f = 1.0 / (1 - x2);
        double coeff = f;
        function[1] = coeff * q[0];
        for (int n = 2; n <= order; ++n) {

            // update and evaluate polynomial Q_n(x)
            double v = 0;
            q[n - 1] = n * q[n - 2];
            for (int k = n - 1; k >= 0; k -= 2) {
                v = (v * x2) + q[k];
                if (k > 2) {
                    q[k - 2] = ((k - 1) * q[k - 1]) + ((((2 * n) - k) + 1) * q[k - 3]);
                } else if (k == 2) {
                    q[0] = q[1];
                }
            }
            if ((n & 0x1) == 0) {
                v *= x;
            }

            coeff *= f;
            function[n] = coeff * v;

        }
    }

    // apply function composition
    compose(operand, function, result);

}

From source file:de.tuberlin.uebb.jbop.example.DSCompiler.java

@Override
@Optimizable/*from   www .j  a  v a2 s . co  m*/
@StrictLoops
public void atanh(final double[] operand, final double[] result) {

    // create the function value and derivatives
    final double[] function = new double[1 + order];
    final double x = operand[0];
    function[0] = FastMath.atanh(x);
    if (order > 0) {
        // the nth order derivative of atanh has the form:
        // dn(atanh(x)/dxn = Q_n(x) / (1 - x^2)^n
        // where Q_n(x) is a degree n-1 polynomial with same parity as n-1
        // Q_1(x) = 1, Q_2(x) = 2x, Q_3(x) = 6x^2 + 2 ...
        // the general recurrence relation for Q_n is:
        // Q_n(x) = (1-x^2) Q_(n-1)'(x) + 2(n-1) x Q_(n-1)(x)
        // as per polynomial parity, we can store coefficients of both Q_(n-1) and Q_n in the same array
        final double[] q = new double[order];
        q[0] = 1;
        final double x2 = x * x;
        final double f = 1.0 / (1 - x2);
        double coeff = f;
        function[1] = coeff * q[0];
        for (int n = 2; n <= order; ++n) {

            // update and evaluate polynomial Q_n(x)
            double v = 0;
            q[n - 1] = n * q[n - 2];
            for (int k = n - 1; k >= 0; k -= 2) {
                v = (v * x2) + q[k];
                if (k > 2) {
                    q[k - 2] = ((k - 1) * q[k - 1]) + ((((2 * n) - k) + 1) * q[k - 3]);
                } else if (k == 2) {
                    q[0] = q[1];
                }
            }
            if ((n & 0x1) == 0) {
                v *= x;
            }

            coeff *= f;
            function[n] = coeff * v;

        }
    }

    // apply function composition
    compose(operand, function, result);

}

From source file:com.rapidminer.tools.expression.internal.function.AntlrParserTrigonometricTest.java

@Test
public void atanhInt() {
    try {//from   w  ww  .  j av a 2 s.  c o  m
        Expression expression = getExpressionWithFunctionContext("atanh(16)");
        assertEquals(ExpressionType.DOUBLE, expression.getExpressionType());
        assertEquals(FastMath.atanh(16), expression.evaluateNumerical(), 1e-15);
    } catch (ExpressionException e) {
        assertNotNull(e.getMessage());
    }
}

From source file:com.rapidminer.tools.expression.internal.function.AntlrParserTrigonometricTest.java

@Test
public void atanhDouble() {
    try {//  w  ww . j  av a 2s  .  com
        Expression expression = getExpressionWithFunctionContext("atanh(33.3)");
        assertEquals(ExpressionType.DOUBLE, expression.getExpressionType());
        assertEquals(FastMath.atanh(33.3), expression.evaluateNumerical(), 1e-15);
    } catch (ExpressionException e) {
        assertNotNull(e.getMessage());
    }
}

From source file:com.rapidminer.tools.expression.internal.function.AntlrParserTrigonometricTest.java

@Test
public void atanhNegative() {
    try {/* w w  w.j av a  2  s .c o  m*/
        Expression expression = getExpressionWithFunctionContext("atanh(-10)");
        assertEquals(ExpressionType.DOUBLE, expression.getExpressionType());
        assertEquals(FastMath.atanh(-10), expression.evaluateNumerical(), 1e-15);
    } catch (ExpressionException e) {
        assertNotNull(e.getMessage());
    }
}

From source file:com.rapidminer.tools.expression.internal.function.AntlrParserTrigonometricTest.java

@Test
public void atanhNull() {
    try {//w ww .j av  a  2 s.  c  om
        Expression expression = getExpressionWithFunctionContext("atanh(0)");
        assertEquals(ExpressionType.DOUBLE, expression.getExpressionType());
        assertEquals(FastMath.atanh(0), expression.evaluateNumerical(), 1e-15);
    } catch (ExpressionException e) {
        assertNotNull(e.getMessage());
    }
}

From source file:com.rapidminer.tools.expression.internal.function.AntlrParserTrigonometricTest.java

@Test
public void atanhNinety() {
    try {//from w  w w .j  a  va  2  s . c  om
        Expression expression = getExpressionWithFunctionContext("atanh(90)");
        assertEquals(ExpressionType.DOUBLE, expression.getExpressionType());
        assertEquals(FastMath.atanh(90), expression.evaluateNumerical(), 1e-15);
    } catch (ExpressionException e) {
        assertNotNull(e.getMessage());
    }
}

From source file:com.rapidminer.tools.expression.internal.function.AntlrParserTrigonometricTest.java

@Test
public void atanhPi() {
    try {/*from   w  w  w  .  j a va  2 s.  c o m*/
        Expression expression = getExpressionWithFunctionContext("atanh(pi)");
        assertEquals(ExpressionType.DOUBLE, expression.getExpressionType());
        assertEquals(FastMath.atanh(Math.PI), expression.evaluateNumerical(), 1e-15);
    } catch (ExpressionException e) {
        assertNotNull(e.getMessage());
    }
}