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.v2soft.misto.Providers.MapnikProvider.java

@Override
public TileInfo getTileInfoByLocation(Location location, int zoom) {
    TileInfo res = new TileInfo();
    res.setHeight(TILE_SIZE);//from   w ww. j  av a 2 s .  c o m
    res.setWidth(TILE_SIZE);
    res.setZoom(zoom);
    res.setLatitude((int) Math.floor((1 - Math.log(Math.tan(location.getLatitude() * Math.PI / 180)
            + 1 / Math.cos(location.getLatitude() * Math.PI / 180)) / Math.PI) / 2 * (1 << zoom)));
    double longitude = Math.floor((location.getLongitude() + 180) * worldTilesCount(zoom) / 360);
    res.setLongitude((int) longitude);
    return res;
}

From source file:dkpro.similarity.algorithms.vsm.NormalizedGoogleDistanceLikeComparator.java

@Override
public double getSimilarity(String term1, String term2) throws SimilarityException {
    Vector v1 = sourceA.getVector(term1);

    if (v1 == null) {
        // The first index usually contains the terms which have quite short concept
        // vectors. If a term concept vector is not found, there is no need to load
        // the heavy-weight document concept vector.
        if (log.isDebugEnabled()) {
            log.debug("Cutting short on term [" + term1 + "] without concept vector");
        }//from www . j a  v a 2  s.  c o  m
        return 0.0;
    }

    Vector v2 = sourceB.getVector(term2);
    if (v2 == null) {
        return 0.0;
    }

    long freq1 = 0;
    long freq2 = 0;
    long freq1and2 = 0;
    for (int i = 0; i < v1.size(); i++) {
        if (v1.get(i) > 0 && v2.get(i) > 0) {
            freq1and2++;
            freq1++;
            freq2++;
        } else if (v1.get(i) > 0) {
            freq1++;
        } else if (v2.get(i) > 0) {
            freq2++;
        }
    }

    System.out.println(freq1);
    System.out.println(freq2);
    System.out.println(freq1and2);

    double logMax = Math.max(Math.log(freq1), Math.log(freq2));
    double logMin = Math.min(Math.log(freq1), Math.log(freq2));
    double logM = Math.log(v1.size());

    return (logMax - Math.log(freq1and2)) / (logM - logMin);
}

From source file:de.unijena.bioinf.IsotopePatternAnalysis.scoring.NormDistributedIntDiffScorer.java

@Override
public double score(Spectrum<Peak> measuredSpectrum, Spectrum<Peak> theoretical,
        Normalization usedNormalization, Ms2Experiment experiment, MeasurementProfile profile) {
    if (measuredSpectrum.size() > theoretical.size())
        throw new IllegalArgumentException("Theoretical spectrum is smaller than measured spectrum");
    // remove peaks from theoretical pattern until the length of both spectra is equal
    final MutableSpectrum<Peak> theoreticalSpectrum = new SimpleMutableSpectrum(theoretical);
    while (measuredSpectrum.size() < theoreticalSpectrum.size()) {
        theoreticalSpectrum.removePeakAt(theoreticalSpectrum.size() - 1);
    }//from  w w w  . j a v a 2 s .c o m
    Spectrums.normalize(theoreticalSpectrum, usedNormalization);
    final double maxIntensity = Spectrums.getMaximalIntensity(measuredSpectrum);
    double score = 0d;
    for (int i = 0; i < theoreticalSpectrum.size(); ++i) {
        final double measuredIntensity = measuredSpectrum.getIntensityAt(i);
        final double theoreticalIntensity = theoreticalSpectrum.getIntensityAt(i);
        final double sd = intensityDependency.getValueAt(measuredIntensity);
        score += Math.log(Erf.erfc(Math.abs(measuredIntensity - theoreticalIntensity) / (root2div2 * sd)));
    }
    return score;
}

From source file:com.compomics.pepshell.view.statistics.RatioStatisticsScatterplotPane.java

@Override
public void setGraphData(PepshellProtein aPepshellProtein) {
    List<XYLineAnnotation> annotations = new ArrayList<>();
    XYSeriesCollection allExperiments = new XYSeriesCollection();
    for (Experiment anExperiment : experiments) {
        int proteinIndex = anExperiment.getProteins().indexOf(aPepshellProtein);
        if (proteinIndex != -1) {
            XYSeries anExperimentSeries = new XYSeries(anExperiment.getExperimentName());
            PepshellProtein experimentPepshellProtein = anExperiment.getProteins().get(proteinIndex);
            for (PeptideGroup aGroup : experimentPepshellProtein.getPeptideGroups()) {
                PeptideInterface shortestPeptide = aGroup.getRepresentativePeptide();

                if (shortestPeptide instanceof QuantedPeptide
                        && ((QuantedPeptide) shortestPeptide).getRatio() != null) {
                    Double value = Math.log(((QuantedPeptide) shortestPeptide).getRatio()) / Math.log(2);
                    //Double value = ((QuantedPeptide) shortestPeptide).getRatio();                          
                    if (value == Double.NEGATIVE_INFINITY) {
                        value = 0.0;/*from   ww  w  .  java2 s . c o  m*/
                    }
                    double barWithErrors = (shortestPeptide.getEndProteinMatch()
                            + shortestPeptide.getBeginningProteinMatch()) / 2;
                    double error = Math.log(((QuantedPeptide) shortestPeptide).getStandardError())
                            / Math.log(2);
                    //double error =((QuantedPeptide) shortestPeptide).getStandardError();
                    XYLineAnnotation vertical = new XYLineAnnotation(barWithErrors, value - error,
                            barWithErrors, value + error, new BasicStroke(), Color.black);
                    XYLineAnnotation horizontalUpper = new XYLineAnnotation(value + error - 0.25, value + error,
                            value + error + 0.25, value + error, new BasicStroke(), Color.black);
                    XYLineAnnotation horizontalLower = new XYLineAnnotation(value - error - 0.25, value - error,
                            value - error + 0.25, value - error, new BasicStroke(), Color.black);

                    annotations.add(vertical);
                    annotations.add(horizontalUpper);
                    annotations.add(horizontalLower);

                    for (int i = shortestPeptide.getBeginningProteinMatch(); i < shortestPeptide
                            .getEndProteinMatch(); i++) {
                        anExperimentSeries.add(i, value);
                    }
                }

            }
            allExperiments.addSeries(anExperimentSeries);

        }
    }
    JFreeChart ratioChart = ChartFactory.createHistogram(
            "ratio for " + aPepshellProtein.getVisibleAccession() + " over all experiments", "peptide start",
            "log^2 ratio", allExperiments, PlotOrientation.VERTICAL, true, true, false);
    chart.setChart(ratioChart);
    for (XYLineAnnotation anAnnotation : annotations) {
        ((XYPlot) ratioChart.getPlot()).addAnnotation(anAnnotation);
    }
    prettifyChart(ratioChart);
}

From source file:edu.stanford.rsl.conrad.segmentation.HistogramFeatureExtractor.java

public double[] extractHistogramFeatures(double[] hist) {

    double histSum = 0.0;
    double AveGreyVal, Variance, StandardDev, Entropy = 0.0;
    double tmp;/*from  w ww. ja  va2  s  .  com*/
    double accum = 0.0;
    double accum2 = 0.0;
    double accum3 = 0.0;
    double accum4 = 0.0;
    double len = hist.length;
    double[] feature = new double[7];

    // calculate mean grey value of histogram
    for (int i = 0; i < len; i++) {
        histSum += hist[i];
    }
    AveGreyVal = histSum / len;
    // write mean grey value in feature array
    feature[0] = AveGreyVal;

    // Normalize histogram, that is makes the sum of all bins equal to 1.
    double[] normalizedHist = new double[hist.length];
    for (int i = 0; i < hist.length; i++) {
        normalizedHist[i] = hist[i] / histSum;
    }

    // calculate variance of histogram
    for (int i = 0; i < len; i++) {
        tmp = normalizedHist[i] - AveGreyVal;
        accum += tmp * tmp;
        accum2 += tmp;
    }
    Variance = (accum - (accum2 * accum2 / len)) / (len - 1);
    StandardDev = Math.sqrt(Variance);
    // write standard deviation in feature array
    feature[1] = StandardDev;

    // calculate entropy of histogram
    for (int i = 0; i < len; i++) {
        if (normalizedHist[i] > 0) {
            tmp = normalizedHist[i] / histSum;
            Entropy -= tmp * (Math.log(tmp) / Math.log(2));
        }
    }
    feature[2] = Entropy;

    // calculate coefficient of variance of histogram and write it in
    // feature array
    feature[3] = (StandardDev / AveGreyVal) * 100.0;

    // calculate skewness of histogram
    for (int i = 0; i < len; i++) {
        accum3 += FastMath.pow((normalizedHist[i] - AveGreyVal), 3.0);

    }
    accum3 /= Variance * Math.sqrt(Variance);
    // write skewness in feature array
    feature[4] = (len / ((len - 1.0) * (len - 2))) * accum3;

    // calculate kurtosis of histogram
    for (int i = 0; i < len; i++) {
        accum4 += FastMath.pow((normalizedHist[i] - AveGreyVal), 4.0);
    }
    accum4 /= FastMath.pow(StandardDev, 4.0);

    double coeffs = (len * (len + 1)) / ((len - 1) * (len - 2) * (len - 3));
    double termTwo = (3 * FastMath.pow((len - 1), 2.0)) / ((len - 2) * (len - 3));
    // write kurtosis in feature array
    feature[5] = (coeffs * accum4) - termTwo;

    return feature;
}

From source file:eu.amidst.core.exponentialfamily.EF_Gamma.java

/**
 * {@inheritDoc}// w  w  w  .  ja  va 2  s .  c  o  m
 */
@Override
public SufficientStatistics getSufficientStatistics(double val) {
    SufficientStatistics vec = this.createZeroSufficientStatistics();
    vec.set(LOGX, Math.log(val));
    vec.set(INVX, val);
    return vec;
}

From source file:ch.algotrader.option.SABR.java

private static double vol(double forward, double strike, double years, double a, double b, double r, double v) {

    if (Math.abs(forward - strike) <= 0.001) { // ATM vol

        double term1 = a / Math.pow(forward, (1 - b));
        double term2 = ((1 - b) * (1 - b) / 24 * a * a / Math.pow(forward, (2 - 2 * b))
                + r * b * a * v / 4 / Math.pow(forward, (1 - b)) + (2 - 3 * r * r) * v * v / 24);
        return term1 * (1 + term2 * years);

    } else { // Non-ATM vol

        double fk = forward * strike;
        double z = v / a * Math.pow(fk, ((1 - b) / 2)) * Math.log(forward / strike);
        double x = Math.log((Math.sqrt(1 - 2 * r * z + z * z) + z - r) / (1 - r));
        double term1 = a / Math.pow(fk, ((1 - b) / 2))
                / (1 + (1 - b) * (1 - b) / 24 * Math.pow(Math.log(forward / strike), 2)
                        + Math.pow((1 - b), 4) / 1920 * Math.pow(Math.log(forward / strike), 4));

        double term2;
        if (Math.abs(x - z) < 1e-10) {
            term2 = 1;/*w  w w.j  ava2 s  .  c om*/
        } else {
            term2 = z / x;
        }

        double term3 = 1 + (Math.pow((1 - b), 2) / 24 * a * a / Math.pow(fk, (1 - b))
                + r * b * v * a / 4 / Math.pow(fk, ((1 - b) / 2)) + (2 - 3 * r * r) / 24 * v * v) * years;
        return term1 * term2 * term3;
    }
}

From source file:geogebra.kernel.statistics.AlgoRandomBinomial.java

private int randomBinomialTRS(int n, double p) {

    if (p > 0.5)
        return n - randomBinomialTRS(n, 1 - p);

    if (n * p < 10)
        return randomBinomial(n, p);

    double spq = Math.sqrt(n * p * (1 - p));

    double b = 1.15 + 2.53 * spq;
    double a = -0.0873 + 0.0248 * b + 0.01 * p;
    double c = n * p + 0.5;
    double v_r = 0.92 - 4.2 / b;

    double us = 0;
    double v = 0;

    while (true) {

        int k = -1;
        while (k < 0 || k > n) {
            double u = Math.random() - 0.5;
            v = Math.random();// w  w w .jav a2  s  .c  om
            us = 0.5 - Math.abs(u);
            k = (int) Math.floor((2 * a / us + b) * u + c);
            if (us >= 0.07 && v < v_r)
                return k;
        }

        double alpha = (2.83 + 5.1 / b) * spq;
        double lpq = Math.log(p / (1 - p));
        int m = (int) Math.floor((n + 1) * p);
        double h = logOfKFactorial(m) + logOfKFactorial((n - m));

        v = v * alpha / (a / (us * us) + b);

        if (v <= h - logOfKFactorial(k) - logOfKFactorial(n - k) + (k - m) * lpq)
            return k;
    }

}

From source file:com.opengamma.analytics.math.interpolation.ExponentialExtrapolator1D.java

private Double rightExtrapolate(final Interpolator1DDataBundle data, final Double value) {
    Validate.notNull(data, "data");
    Validate.notNull(value, "value");
    final double x = data.lastKey();
    final double y = data.lastValue();
    final double m = Math.log(y) / x;
    return Math.exp(m * value);
}

From source file:com.qaant.optionModels.QWhaley.java

private void wWhaley() {

    pModelName = "Whaley QAANT";
    modelNumber = 2;//www.j av a 2s .c o  m
    tipoEjercicio = AMERICAN;

    //     q=(tipoContrato==STOCK) ? dividendRate:rate; 
    //q: si es una accion q es el dividendo, si es un futuro q se toma la rate para descontar el valor futr a presente 
    //Se hace este reemplazo para poder usar la misma form en STOCK y FUTURO

    double xx;

    switch (tipoContrato) {
    case STOCK:
        q = dividendRate;
        b = rate;
        break;

    case FUTURES:
        q = rate;
        b = 0;
        break;
    }
    double vlt2 = volatModel * volatModel;
    double VltSqrDayYear = volatModel * sqrDayYear;
    double h = 1 - z; //descuento para valor presente

    double alfa = 2 * rate / vlt2;
    double beta = 2 * (b - q) / vlt2;

    double lambda = (-(beta - 1) + cpFlag * Math.sqrt((beta - 1) * (beta - 1) + 4 * alfa / h)) / 2;

    double eex = Math.exp(-q * dayYear);//descuento por dividendos

    double s1 = strike;
    double zz = 1 / Math.sqrt(2 * Math.PI);
    double zerror = 1;
    do {
        double d1 = (Math.log(s1 / strike) + ((rate - q) + vlt2 / 2) * dayYear) / VltSqrDayYear;
        xx = (1 - eex * new NormalDistribution().cumulativeProbability(cpFlag * d1));

        double corr = s1 / lambda * xx;

        QBlackScholes option = new QBlackScholes(tipoContrato, s1, volatModel, dividendRate, callPut, strike,
                daysToExpiration, rate, 0);

        double mBlackScholes = option.getPrima();
        double rhs = mBlackScholes + cpFlag * corr;

        double lhs = cpFlag * (s1 - strike);
        zerror = lhs - rhs;
        double nd1 = zz * Math.exp(-0.5 * d1 * d1); //standard normal prob?
        double slope = cpFlag * (1 - 1 / lambda) * xx + 1 / lambda * (eex * nd1) * 1 / VltSqrDayYear;
        s1 = s1 - zerror / slope;

    } while (Math.abs(zerror) > 0.000001);

    double a = cpFlag * s1 / lambda * xx;

    switch (callPut) {
    case CALL: //Call
        if (underlyingValue >= s1) {
            prima = underlyingValue - strike;
        } else {
            prima += a * Math.pow((underlyingValue / s1), lambda);
        }
        break;

    case PUT: //Put
        if (underlyingValue <= s1) {
            prima = strike - underlyingValue;
        } else {
            prima += a * Math.pow((underlyingValue / s1), lambda);
        }
        //prima=10.1;
        break;
    }
}