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

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

Introduction

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

Prototype

public static double asinh(double a) 

Source Link

Document

Compute the inverse hyperbolic sine of a number.

Usage

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

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

From source file:net.sf.dsp4j.octave.packages.signal_1_0_11.Cheby1.java

private Cheby1(int n, double Rp, double[] W, boolean digital, boolean stop) {
    super(W, digital, stop);

    if (Rp < 0) {
        throw new IllegalArgumentException("cheby1: passband ripple must be positive decibels");
    }/*from w  ww.j av  a  2 s .c  om*/

    this.Rp = Rp;

    //## Generate splane poles and zeros for the chebyshev type 1 filter
    final double C = 1; //# default cutoff frequency
    final double epsilon = FastMath.sqrt(FastMath.pow(10, (Rp / 10)) - 1);
    final double v0 = FastMath.asinh(1 / epsilon) / n;
    pole = new Complex[n];
    for (int i = 0; i < n; i++) {
        final Complex p = new Complex(0, FastMath.PI * (2.0 * i - n + 1.0) / (2.0 * n)).exp(); //TODO richtig ???
        pole[i] = new Complex(-FastMath.sinh(v0) * p.getReal())
                .add(IMAG_ONE.multiply(FastMath.cosh(v0)).multiply(p.getImaginary()));
    }
    zero = new Complex[0];

    //## compensate for amplitude at s=0
    Complex gainC = OctaveBuildIn.prod(OctaveBuildIn.neg(pole));
    //## if n is even, the ripple starts low, but if n is odd the ripple
    //## starts high. We must adjust the s=0 amplitude to compensate.
    if (n % 2 == 0) {
        gainC = gainC.divide(FastMath.pow(10, Rp / 20));
    }
    gain = gainC.getReal();
}

From source file:gamlss.distributions.JSUo.java

/**
 * Set z and r arrays.//from w  ww. j a  va2s  .c o  m
 * @param y - response variable
 */
private void setInterimArrays(final ArrayRealVector y) {
    muV = distributionParameters.get(DistributionSettings.MU);
    sigmaV = distributionParameters.get(DistributionSettings.SIGMA);
    nuV = distributionParameters.get(DistributionSettings.NU);
    tauV = distributionParameters.get(DistributionSettings.TAU);

    size = y.getDimension();
    z = new double[size];
    r = new double[size];
    for (int i = 0; i < size; i++) {

        //z <- (y-mu)/sigma
        z[i] = (y.getEntry(i) - muV.getEntry(i)) / sigmaV.getEntry(i);

        //r <- nu + tau*asinh(z)
        r[i] = nuV.getEntry(i) + tauV.getEntry(i) * FastMath.asinh(z[i]);
    }
}

From source file:lambertmrev.Lambert.java

public double x2tof2(double x, int N, double m_lambda) {
    double a = 1.0 / (1.0 - x * x);
    double tof;//  www. j a  va2s  .  c o m
    if (a > 0) //ellipse
    {
        double alfa = 2.0 * FastMath.acos(x);
        double beta = 2.0 * FastMath.asin(FastMath.sqrt(m_lambda * m_lambda / a));
        if (m_lambda < 0.0)
            beta = -beta;
        tof = ((a * FastMath.sqrt(a)
                * ((alfa - FastMath.sin(alfa)) - (beta - FastMath.sin(beta)) + 2.0 * FastMath.PI * N)) / 2.0);
    } else {
        double alfa = 2.0 * FastMath.acosh(x);
        double beta = 2.0 * FastMath.asinh(FastMath.sqrt(-m_lambda * m_lambda / a));
        if (m_lambda < 0.0)
            beta = -beta;
        tof = (-a * FastMath.sqrt(-a) * ((beta - FastMath.sinh(beta)) - (alfa - FastMath.sinh(alfa))) / 2.0);
    }
    return tof;
}

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

/**
 * Returns the hyperbolic arc sine of the number.
 * //from   w w w.j a va2s . c  om
 * @param a the number
 * @return the hyperbolic arc sine of the number
 * @see FastMath#asinh(double)
 */
public static Number asinh(Number a) {
    return FastMath.asinh(a.doubleValue());
}

From source file:gamlss.distributions.JSUo.java

/** Computes the probability density function (PDF) of this 
 * distribution evaluated at the specified point x.
 * @param x - value of response variable
 * @param mu - value of mu distribution parameter
 * @param sigma - value of sigma distribution parameter
 * @param nu - value of nu distribution parameter
 * @param tau - value of tau distribution parameter
 * @param isLog  - logical, whether to take log of the function or not
 * @return value of probability density function
 *//*from   ww  w. ja v  a  2s . c  o  m*/
public final double dJSUo(final double x, final double mu, final double sigma, final double nu,
        final double tau, final boolean isLog) {

    // {  if (any(sigma <= 0))stop(paste("sigma must be positive",))
    if (sigma < 0) {
        System.err.println("sigma must be positive");
        return -1.0;
    }
    //if (any(tau < 0))  stop(paste("tau must be positive", "\n", ""))
    if (tau < 0) {
        System.err.println("nu must be positive");
        return -1.0;
    }

    //z <- (x-mu)/sigma
    final double z = (x - mu) / sigma;

    //r <- nu + tau*asinh(z)
    final double r = nu + tau * FastMath.asinh(z);

    //loglik <- -log(sigma)+ log(tau)- 
    //.5*log(z*z+1) -.5*log(2*pi)-.5*r*r
    double out = -FastMath.log(sigma) + FastMath.log(tau) - 0.5 * FastMath.log(z * z + 1)
            - 0.5 * FastMath.log(2 * FastMath.PI) - 0.5 * r * r;

    //if(log==FALSE) ft  <- exp(loglik) else ft <- loglik
    if (!isLog) {
        out = FastMath.exp(out);
    }
    return out;
}

From source file:gamlss.distributions.JSUo.java

/** Computes the cumulative distribution 
 * function P(X <= q) for a random variable X .
 * whose values are distributed according to this distribution
 * @param q - value of quantile/* www  .ja  va  2s  . c  om*/
 * @param mu - value of mu distribution parameter
 * @param sigma - value of sigma distribution parameter
 * @param nu - value of nu distribution parameter 
 * @param tau - value of tau distribution parameter 
 * @param lowerTail - logical, if TRUE (default), probabilities
 *  are P[X <= x] otherwise, P[X > x].
 * @param isLog - logical, if TRUE, probabilities p are given as log(p)
 * @return value of cumulative probability function values P(X <= q)
 */
public final double pJSUo(final double q, final double mu, final double sigma, final double nu,
        final double tau, final boolean lowerTail, final boolean isLog) {

    // {  if (any(sigma <= 0))stop(paste("sigma must be positive",))
    if (sigma < 0) {
        System.err.println("sigma must be positive");
        return -1.0;
    }
    //if (any(tau < 0))  stop(paste("tau must be positive", "\n", ""))
    if (tau < 0) {
        System.err.println("nu must be positive");
        return -1.0;
    }

    //z <- (x-mu)/sigma
    //r <- nu + tau*asinh(z)
    final double r = nu + tau * FastMath.asinh((q - mu) / sigma);

    //p <- pNO(r,0,1)
    double out = noDist.cumulativeProbability(r);

    //if(lower.tail==TRUE) p  <- p else  p <- 1-p
    //if(log.p==FALSE) p  <- p else  p <- log(p)
    if (!lowerTail) {
        if (isLog) {
            out = FastMath.log(1 - out);
        } else {
            out = 1 - out;
        }
    } else if (isLog) {
        out = FastMath.log(out);
    }
    return out;
}

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

@Override
public void asinh(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.asinh(x);
    if (order > 0) {
        // the nth order derivative of asinh has the form:
        // dn(asinh(x)/dxn = P_n(x) / [x^2 + 1]^((2n-1)/2)
        // where P_n(x) is a degree n-1 polynomial with same parity as n-1
        // P_1(x) = 1, P_2(x) = -x, P_3(x) = 2x^2 - 1 ...
        // the general recurrence relation for P_n is:
        // P_n(x) = (x^2+1) P_(n-1)'(x) - (2n-3) x P_(n-1)(x)
        // 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];
        p[0] = 1;/*from   ww  w  .j a  va2s  .  c  o  m*/
        final double x2 = x * x;
        final double f = 1.0 / (1 + x2);
        double coeff = FastMath.sqrt(f);
        function[1] = coeff * p[0];
        for (int n = 2; n <= order; ++n) {

            // update and evaluate polynomial P_n(x)
            double v = 0;
            p[n - 1] = (1 - n) * p[n - 2];
            for (int k = n - 1; k >= 0; k -= 2) {
                v = (v * x2) + p[k];
                if (k > 2) {
                    p[k - 2] = ((k - 1) * p[k - 1]) + ((k - (2 * n)) * p[k - 3]);
                } else if (k == 2) {
                    p[0] = p[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  w w w  . ja va 2s.  com
@StrictLoops
public void asinh(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.asinh(x);
    if (order > 0) {
        // the nth order derivative of asinh has the form:
        // dn(asinh(x)/dxn = P_n(x) / [x^2 + 1]^((2n-1)/2)
        // where P_n(x) is a degree n-1 polynomial with same parity as n-1
        // P_1(x) = 1, P_2(x) = -x, P_3(x) = 2x^2 - 1 ...
        // the general recurrence relation for P_n is:
        // P_n(x) = (x^2+1) P_(n-1)'(x) - (2n-3) x P_(n-1)(x)
        // 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];
        p[0] = 1;
        final double x2 = x * x;
        final double f = 1.0 / (1 + x2);
        double coeff = FastMath.sqrt(f);
        function[1] = coeff * p[0];
        for (int n = 2; n <= order; ++n) {

            // update and evaluate polynomial P_n(x)
            double v = 0;
            p[n - 1] = (1 - n) * p[n - 2];
            for (int k = n - 1; k >= 0; k -= 2) {
                v = (v * x2) + p[k];
                if (k > 2) {
                    p[k - 2] = ((k - 1) * p[k - 1]) + ((k - (2 * n)) * p[k - 3]);
                } else if (k == 2) {
                    p[0] = p[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 asinhInt() {
    try {//w  w w  .  j  a va  2s  . co  m
        Expression expression = getExpressionWithFunctionContext("asinh(16)");
        assertEquals(ExpressionType.DOUBLE, expression.getExpressionType());
        assertEquals(FastMath.asinh(16), expression.evaluateNumerical(), 1e-15);
    } catch (ExpressionException e) {
        assertNotNull(e.getMessage());
    }
}