Example usage for java.lang Math log

List of usage examples for java.lang Math log

Introduction

In this page you can find the example usage for java.lang Math log.

Prototype

@HotSpotIntrinsicCandidate
public static double log(double a) 

Source Link

Document

Returns the natural logarithm (base e) of a double value.

Usage

From source file:com.itemanalysis.psychometrics.irt.estimation.ItemParamPriorLogNormal.java

/**
 * Only compute part of the log of the density that depends on the parameter
 * @param p Argument of log density function (an item parameter value)
 * @return/*from www  . ja  v a  2 s  .com*/
 */
public double logDensity(double p) {
    //Check for value outside limits of distribution
    if (zeroDensity(p)) {
        return Double.MIN_VALUE;
    }
    double value = Math.log(p) - parameters[0];
    value *= value;
    value /= -2.0 * variance;
    value -= Math.log(p);

    return value;
}

From source file:beast.math.distributions.InverseGammaDistribution.java

/**
 * the natural log of the probability density function of the distribution
 *
 * @param x     argument//w  w  w  .  j  av  a 2s  . com
 * @param shape shape parameter
 * @param scale scale parameter
 * @return log pdf value
 */
public static double logPdf(double x, double shape, double scale, double factor) {
    if (x <= 0)
        return Double.NEGATIVE_INFINITY;

    return factor - (scale / x) - (shape + 1) * Math.log(x) + shape * Math.log(scale) - Gamma.logGamma(shape);
    //        return  factor + shape*Math.log(scale) - (shape + 1)*Math.log(x) - (scale/x) - GammaFunction.lnGamma(shape);
}

From source file:com.opengamma.analytics.math.statistics.distribution.NonCentralChiSquaredDistribution.java

private double getFraserApproxCDF(final double x) {
    final double s = Math.sqrt(_lambdaOverTwo * 2.0);
    final double mu = Math.sqrt(x);
    double z;/*from   w  w w . j a  v  a2s .  c  o m*/
    if (Double.doubleToLongBits(mu) == Double.doubleToLongBits(s)) {
        z = (1 - _dofOverTwo * 2.0) / 2 / s;
    } else {
        z = mu - s - (_dofOverTwo * 2.0 - 1) / 2 * (Math.log(mu) - Math.log(s)) / (mu - s);
    }
    return (new NormalDistribution(0, 1)).getCDF(z);
}

From source file:com.opengamma.strata.math.impl.statistics.distribution.NonCentralChiSquaredDistribution.java

private double getFraserApproxCDF(double x) {
    double s = Math.sqrt(_lambdaOverTwo * 2.0);
    double mu = Math.sqrt(x);
    double z;/*from ww  w.j a va  2  s .  c  o m*/
    if (Double.doubleToLongBits(mu) == Double.doubleToLongBits(s)) {
        z = (1 - _dofOverTwo * 2.0) / 2 / s;
    } else {
        z = mu - s - (_dofOverTwo * 2.0 - 1) / 2 * (Math.log(mu) - Math.log(s)) / (mu - s);
    }
    return (new NormalDistribution(0, 1)).getCDF(z);
}

From source file:com.opengamma.analytics.financial.model.option.pricing.analytic.SimpleChooserOptionModel.java

/**
 * {@inheritDoc}/*w  ww  .  j a va 2  s.c om*/
 */
@Override
public Function1D<StandardOptionDataBundle, Double> getPricingFunction(
        final SimpleChooserOptionDefinition definition) {
    Validate.notNull(definition);
    final Function1D<StandardOptionDataBundle, Double> pricingFunction = new Function1D<StandardOptionDataBundle, Double>() {

        @SuppressWarnings("synthetic-access")
        @Override
        public Double evaluate(final StandardOptionDataBundle data) {
            Validate.notNull(data);
            final double s = data.getSpot();
            final double k = definition.getUnderlyingStrike();
            final double t1 = definition.getTimeToExpiry(data.getDate());
            final double t2 = DateUtils.getDifferenceInYears(data.getDate(),
                    definition.getUnderlyingExpiry().getExpiry());
            final double b = data.getCostOfCarry();
            final double r = data.getInterestRate(t1);
            final double sigma = data.getVolatility(t1, k);
            final double sigmaT1 = sigma * Math.sqrt(t1);
            final double sigmaT2 = sigma * Math.sqrt(t2);
            final double sigmaSq = sigma * sigma / 2.;
            final double logSK = Math.log(s / k);
            final double bT2 = b * t2;
            final double d = getD(logSK, bT2, sigmaSq * t2, sigmaT2);
            final double y = getD(logSK, bT2, sigmaSq * t1, sigmaT1);
            final double df1 = getDF(r, b, t2);
            final double df2 = getDF(r, 0, t2);
            return s * df1 * (NORMAL.getCDF(d) - NORMAL.getCDF(-y))
                    - k * df2 * (NORMAL.getCDF(d - sigmaT2) - NORMAL.getCDF(-y + sigmaT1));
        }

    };
    return pricingFunction;
}

From source file:com.opengamma.analytics.financial.model.option.pricing.fourier.FourierModelGreeks.java

public double[] getGreeks(final BlackFunctionData data, final EuropeanVanillaOption option,
        final MartingaleCharacteristicExponent ce, final double alpha, final double limitTolerance) {
    Validate.notNull(data, "data");
    Validate.notNull(option, "option");
    Validate.notNull(ce, "characteristic exponent");
    Validate.isTrue(limitTolerance > 0, "limit tolerance must be > 0");
    Validate.isTrue(alpha <= ce.getLargestAlpha() && alpha >= ce.getSmallestAlpha(),
            "The value of alpha is not valid for the Characteristic Exponent and will most likely lead to mispricing. Choose a value between "
                    + ce.getSmallestAlpha() + " and " + ce.getLargestAlpha());

    final EuropeanCallFourierTransform psi = new EuropeanCallFourierTransform(ce);
    final double strike = option.getStrike();
    final double t = option.getTimeToExpiry();
    final double forward = data.getForward();
    final double discountFactor = data.getDiscountFactor();
    final Function1D<ComplexNumber, ComplexNumber> characteristicFunction = psi.getFunction(t);
    final double xMax = LIMIT_CALCULATOR.solve(characteristicFunction, alpha, limitTolerance);

    double kappa = Math.log(strike / forward);
    int n = ce.getCharacteristicExponentAdjoint(MINUS_I, 1.0).length; //TODO have method like getNumberOfparameters 

    Function1D<ComplexNumber, ComplexNumber[]> adjointFuncs = ce.getAdjointFunction(t);
    double[] res = new double[n - 1];

    //TODO This is inefficient as a call to ajointFuncs.evaluate(z), will return several values (the value of the characteristic function and its derivatives), but only one
    // of these values is used by each of the the integraters - a parallel quadrature scheme would be good here 
    for (int i = 0; i < n - 1; i++) {
        final Function1D<Double, Double> func = getIntegrandFunction(adjointFuncs, alpha, kappa, i + 1);
        final double integral = Math.exp(-alpha * Math.log(strike / forward))
                * _integrator.integrate(func, 0.0, xMax) / Math.PI;
        res[i] = discountFactor * forward * integral;
    }/* w  w  w. ja  va 2s. c o m*/
    return res;
}

From source file:com.opengamma.analytics.financial.model.volatility.smile.function.SVIVolatilityFunction.java

@Override
public Function1D<SVIFormulaData, double[]> getVolatilityAdjointFunction(final EuropeanVanillaOption option,
        final double forward) {
    Validate.notNull(option, "option");
    Validate.isTrue(forward > 0, "Need forward >= 0");
    final double strike = option.getStrike();
    Validate.isTrue(strike > 0, "Need strike >= 0");
    final double kappa = Math.log(strike / forward);

    return new Function1D<SVIFormulaData, double[]>() {
        @SuppressWarnings("synthetic-access")
        @Override/*w  ww.  j  a  v a  2  s  .  c  o m*/
        public double[] evaluate(final SVIFormulaData data) {
            return getVolatilityAdjoint(forward, strike, kappa, data);
        }
    };
}

From source file:gedi.lfc.gui.LfcMapper.java

private double pToLfc(double p) {
    return Math.log(p / (1 - p)) / Math.log(2);
}

From source file:com.wwidesigner.modelling.PlotPlayingRanges.java

/**
 * Return true if f is a tonic or dominant in the key fLow.
 * @param f/*from   ww  w .j  a v  a  2 s .  c  o  m*/
 * @param fLow
 */
protected static boolean isMarker(double f, double fLow) {
    double logNote = Math.log(f / fLow) / Constants.LOG2;
    int octaves = (int) logNote;
    double semitones = 12.0 * (logNote - (double) octaves);
    if (semitones < 0.5 || semitones > 11.5) {
        return true;
    }
    if (6.5 < semitones && semitones < 7.5) {
        return true;
    }
    return false;
}

From source file:com.itemanalysis.psychometrics.cfa.MaximumLikelihoodEstimation.java

public double value(double[] argument) {
    model.setParameters(argument);//from w  w w.j a va2 s.  c o  m

    //            Linesearch method in QNMinimizer is causing NaN values after repeated calls to here
    //            Next libe is for monitoring values when called from line search
    //            No problem occurs with CGMinimizer
    //            System.out.println("valueAt: " + argument[0] + " " + argument[1]);
    SIGMA = model.getImpliedCovariance(argument);

    //compute determinant of SIGMA
    LUDecomposition SLUD = new LUDecomposition(SIGMA);
    double detSig = SLUD.getDeterminant();

    //compute inverse of SIGMA
    RealMatrix SIGMAinv = SLUD.getSolver().getInverse();
    RealMatrix VC_SIGMA_INV = varcov.multiply(SIGMAinv);
    double trace = VC_SIGMA_INV.getTrace();

    //convert number of items to double
    double p = Double.valueOf(model.getNumberOfItems()).doubleValue();

    //compute objective function
    F = Math.log(detSig) + trace - Math.log(detVc) - p;
    return F;
}