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:de.upb.wdqa.wdvd.revisiontags.SHA1Converter.java

private static String getBase(int base, byte[] bytes) {
    String result;/*w  w  w.j av a 2 s  .  c  o  m*/

    if (bytes != null) {
        if (bytes.length != 0) {
            BigInteger bi = new BigInteger(1, bytes);
            String tmp = bi.toString(base);

            int numberOfDigits = (int) Math.ceil(160.0 / (Math.log(base) / Math.log(2.0)));

            result = StringUtils.leftPad(tmp, numberOfDigits, '0');
        } else {
            result = "";
        }
    } else {
        result = null;
    }

    return result;
}

From source file:net.nicoulaj.benchmarks.math.DoubleLog.java

@GenerateMicroBenchmark
public void math(BlackHole hole) {
    for (int i = 0; i < data.length - 1; i++)
        hole.consume(Math.log(data[i]));
}

From source file:com.opengamma.analytics.math.minimization.SingleRangeLimitTransform.java

/**
 * {@inheritDoc}/*from   ww  w.ja va  2s. co m*/
 */
@Override
public double inverseTransform(final double y) {
    if (y > EXP_MAX) {
        return _limit + _sign * y;
    } else if (y < -EXP_MAX) {
        return _limit;
    }
    return _limit + _sign * Math.log(Math.exp(y) + 1);
}

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

public Function1D<Double, Double> getFunction(final BlackFunctionData data,
        final EuropeanVanillaOption option) {
    Validate.notNull(data, "data");
    Validate.notNull(option, "option");
    final double t = option.getTimeToExpiry();
    final Function1D<ComplexNumber, ComplexNumber> characteristicFunction = _ce.getFunction(t);
    final double k = Math.log(option.getStrike() / data.getForward());
    final double blackVol = data.getBlackVolatility();
    final CharacteristicExponent gaussian;
    final Function1D<ComplexNumber, ComplexNumber> gaussianFunction;
    if (_useVarianceReduction) {
        gaussian = new GaussianCharacteristicExponent(-0.5 * blackVol * blackVol, blackVol);
        gaussianFunction = gaussian.getFunction(t);
    } else {/*  w  ww  .  j  a  v  a  2 s  .  c  om*/
        gaussian = null;
        gaussianFunction = null;
    }
    return new Function1D<Double, Double>() {

        @Override
        public Double evaluate(final Double x) {
            @SuppressWarnings("synthetic-access")
            final ComplexNumber res = getIntegrand(x, characteristicFunction, gaussianFunction, k);
            return res.getReal();
        }
    };
}

From source file:gr.iti.mklab.reveal.forensics.maps.dwnoisevar.DWNoiseVarExtractor.java

public void getNoiseMap() throws IOException {

    BufferedImage img = inputImage;

    int imWidth, imHeight;
    if (img.getWidth() % 2 == 0) {
        imWidth = img.getWidth();//from   w w  w  .j  ava  2 s .  c o m
    } else {
        imWidth = (img.getWidth() - 1);
    }
    if (img.getHeight() % 2 == 0) {
        imHeight = img.getHeight();
    } else {
        imHeight = (img.getHeight() - 1);
    }

    int columnFilterScale = (int) (Math.log(imHeight) / Math.log(2)) - 1;
    int rowFilterScale = (int) (Math.log(imWidth) / Math.log(2)) - 1;

    double[][] imgYAsArray = new double[imWidth][imHeight];
    double[][] filteredImgYAsArray = new double[imWidth][imHeight / 2];
    double[][] doubleFilteredImgYAsArray = new double[imWidth / 2][imHeight / 2];
    double[] imgColumn, imgRow;
    Color tmpcolor;
    double R, G, B;

    for (int ii = 0; ii < imWidth; ii++) {
        for (int jj = 0; jj < imHeight; jj++) {
            tmpcolor = new Color(img.getRGB(ii, jj));
            R = tmpcolor.getRed();
            G = tmpcolor.getGreen();
            B = tmpcolor.getBlue();
            imgYAsArray[ii][jj] = 0.2989 * R + 0.5870 * G + 0.1140 * B;
        }
    }

    double[] waveletColumn;
    RealMatrix rm = new Array2DRowRealMatrix(imgYAsArray);
    for (int ii = 0; ii < imWidth; ii++) {
        try {
            imgColumn = new double[imHeight];
            imgColumn = rm.getRow(ii);
            //Long startTime1 = System.currentTimeMillis();  
            waveletColumn = DWT.transform(imgColumn, Wavelet.Daubechies, 8, columnFilterScale,
                    DWT.Direction.forward);
            System.arraycopy(waveletColumn, imHeight / 2, filteredImgYAsArray[ii], 0, imHeight / 2);
        } catch (Exception ex) {
            Logger.getLogger(DWNoiseVarExtractor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    double[] waveletRow;
    RealMatrix rm2 = new Array2DRowRealMatrix(filteredImgYAsArray);
    for (int jj = 0; jj < imHeight / 2; jj++) {
        try {
            imgRow = new double[imWidth];
            imgRow = rm2.getColumn(jj);
            waveletRow = DWT.transform(imgRow, Wavelet.Daubechies, 8, rowFilterScale, DWT.Direction.forward);
            for (int ii = 0; ii < imWidth / 2; ii++) {
                doubleFilteredImgYAsArray[ii][jj] = waveletRow[ii + imWidth / 2];
            }
        } catch (Exception ex) {
            Logger.getLogger(DWNoiseVarExtractor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    int blockSize = 8;
    double[][] blockNoiseVar = Util.blockNoiseVar(doubleFilteredImgYAsArray, blockSize);

    int medianFilterSize = 7;
    if (medianFilterSize > blockNoiseVar.length) {
        medianFilterSize = blockNoiseVar.length - 1;
    }
    if (medianFilterSize > blockNoiseVar[0].length) {
        medianFilterSize = blockNoiseVar[0].length - 1;
    }
    if (medianFilterSize < 5) {
        minNoiseValue = 0;
        maxNoiseValue = 0;
        noiseMap = new float[1][1];
        noiseMap[0][0] = 0;
        double[][] artificialOutput = new double[1][1];
        artificialOutput[0][0] = 0;
        BufferedImage outputImage = Util.visualizeWithJet(artificialOutput);
        displaySurface = outputImage;
        return;
    }

    float[][] outBlockMap = Util.medianFilterSingleChannelImage(blockNoiseVar, medianFilterSize);

    minNoiseValue = Util.minDouble2DArray(outBlockMap);
    maxNoiseValue = Util.maxDouble2DArray(outBlockMap);
    noiseMap = outBlockMap;
    double[][] normalizedMap = Util.normalizeIm(outBlockMap);
    BufferedImage outputImage = Util.visualizeWithJet(normalizedMap);
    // output
    displaySurface = outputImage;
}

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

/**
 * /*from   w  ww . j  a v  a2 s. c  o m*/
 * @param psi The characteristic function, not null
 * @param alpha The value of $\alpha$, not 0 or -1
 * @param tol The tolerance for the root
 * @return The root
 */
public double solve(final Function1D<ComplexNumber, ComplexNumber> psi, final double alpha, final double tol) {
    Validate.notNull(psi, "psi null");
    Validate.isTrue(alpha != 0.0 && alpha != -1.0, "alpha cannot be -1 or 0");
    Validate.isTrue(tol > 0.0, "need tol > 0");

    final double k = Math.log(tol)
            + Math.log(ComplexMathUtils.mod(psi.evaluate(new ComplexNumber(0.0, -(1 + alpha)))));
    final Function1D<Double, Double> f = new Function1D<Double, Double>() {
        @Override
        public Double evaluate(final Double x) {
            final ComplexNumber z = new ComplexNumber(x, -(1 + alpha));
            return Math.log(ComplexMathUtils.mod(psi.evaluate(z))) - k;
        }
    };
    double[] range = null;
    try {
        range = s_bracketRoot.getBracketedPoints(f, 0.0, 200.0);
    } catch (MathException e) {
        s_log.warn("Could not find integral limit. Using default of 500");
        return 500.0;
    }
    return s_root.getRoot(f, range[0], range[1]);
}

From source file:Methods.CalculusBisection.java

public static void bisection2(double xlower, double xupper, double decPoint) {//method used calculate root point acording the paramethers that enter the method and store the data in a global Stack

    S = new BidimensionalArrayStack();//Declaring a new Stack beeing sure is clear before using it
    Xlower = new BidimensionalArrayStack();
    Xupper = new BidimensionalArrayStack();
    double xnew, fxlower, fxupper, fxnew, diff;
    int iteration;

    fxlower = (Math.log(Math.abs(xlower + 1.0))) + 1.0;
    fxupper = (Math.log(xupper + 1.0)) + 1.0;
    iteration = 0;/*ww w  .j av a 2 s . co m*/

    do {
        iteration += 1;
        // determine xnew and f (xnew)
        xnew = (xlower + xupper) / 2.0;
        fxnew = (Math.log(Math.abs(xnew + 1.0))) + 1.0;
        System.out.println("Approx for iteration{}" + iteration + " is " + xnew);
        diff = Math.abs(xupper - xlower) / 2;
        Xlower.push(xlower, fxlower);//Inserting data in the Stack
        Xupper.push(xupper, fxupper);

        if (fxlower * fxnew > 0) {
            xlower = xnew;
            fxlower = fxnew;
        } else if (fxupper * fxnew > 0) {
            xupper = xnew;
            fxupper = fxnew;
        }
        S.push(xnew, fxnew);
    } while (diff > decPoint);
    System.out.println("root to six decimal places is " + xnew);
}

From source file:com.cloudera.hts.utils.math.MyFunc2.java

public double[] gradient(double t, double... parameters) {

    final double a = parameters[0];
    final double b = parameters[1];
    final double c = parameters[2];

    return new double[] { Math.exp(-c * t) * Math.pow(t, b),
            a * Math.exp(-c * t) * Math.pow(t, b) * Math.log(t), a * (-Math.exp(-c * t)) * Math.pow(t, b + 1) };
}

From source file:etomica.math.SpecialFunctions.java

/**
 * Returns the ln(gamma), the natural logarithm of the gamma function.
 * Lanczos approximation, with precision ~15 digits
 * coefficients from GSL (GNU Scientific Library) with g=7
 *//* ww  w.j  a  v  a 2  s . c o  m*/
public static double lnGamma(double x) {
    if (x < 0) {
        throw new IllegalArgumentException("x must not be negative");
    }
    if (x == 0) {
        return 0;
    }
    if (x < 0.5) {
        return Math.log(Math.PI / (Math.sin(Math.PI * x))) - lnGamma(1 - x);
    }
    double tmp = x + 7 - 0.5;
    double ser = 0.99999999999980993;
    for (int i = 7; i > -1; i--) {
        ser += lnGammaCoeff[i] / (x + i);
    }
    double y = lnsqrt2Pi + (x - 0.5) * Math.log(tmp) - tmp + Math.log(ser);
    return y;
}

From source file:com.opengamma.analytics.financial.model.interestrate.HullWhiteOneFactorInterestRateModel.java

@Override
public Function1D<HullWhiteOneFactorDataBundle, Double> getDiscountBondFunction(final ZonedDateTime time,
        final ZonedDateTime maturity) {
    Validate.notNull(time);//from www .  java2 s  .  c  o m
    Validate.notNull(maturity);
    return new Function1D<HullWhiteOneFactorDataBundle, Double>() {

        @Override
        public Double evaluate(final HullWhiteOneFactorDataBundle data) {
            Validate.notNull(data);
            final double t = DateUtils.getDifferenceInYears(data.getDate(), time);
            final double s = DateUtils.getDifferenceInYears(data.getDate(), maturity);
            final double rT = data.getShortRate(t);
            final double rs = data.getShortRate(s);
            final double pT = Math.exp(-rT * t);
            final double ps = Math.exp(-rs * s);
            final Double sigma = data.getShortRateVolatility(t);
            final double dt = s - t;
            final double speed = data.getReversionSpeed();
            final double b = (1 - Math.exp(-speed * dt)) / speed;
            final double upT = t + _delta;
            final double downT = t - _delta;
            final double dlnPdt = (-data.getShortRate(upT) * upT + data.getShortRate(downT) * downT)
                    / (2 * _delta);
            final double lnA = Math.log(ps / pT) - b * dlnPdt
                    - sigma * sigma * Math.pow(Math.exp(-speed * s) - Math.exp(-speed * t), 2)
                            * (Math.exp(2 * speed * t) - 1) / (4 * speed * speed * speed);
            return Math.exp(lnA - b * rT);
        }

    };
}