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.opengamma.analytics.math.interpolation.LogLinearInterpolator1D.java

@Override
public double firstDerivative(final Interpolator1DDataBundle model, final Double value) {
    Validate.notNull(value, "value");
    Validate.notNull(model, "data bundle");
    final InterpolationBoundedValues boundedValues = model.getBoundedValues(value);
    final Double x1 = boundedValues.getLowerBoundKey();
    final Double y1 = boundedValues.getLowerBoundValue();
    if (model.getLowerBoundIndex(value) == model.size() - 1) {
        return 0.;
    }//from w ww.  j  a  v  a 2 s.com
    final Double x2 = boundedValues.getHigherBoundKey();
    final Double y2 = boundedValues.getHigherBoundValue();
    return Math.pow(y2 / y1, (value - x1) / (x2 - x1)) * y1 * Math.log(y2 / y1) / (x2 - x1);
}

From source file:ch.unil.genescore.vegas.DistributionMethods.java

public static double normalInversionUpperTailApprox(double p) {
    // approximates tail integral of normal distribution function:: only use for very low values; below 10^-14
    double lp = Math.log(p);
    double diff = 1;
    double a1 = 1;
    double a = 1;
    while (diff > 0.001) {

        a = Math.sqrt((-lp - Math.log(Math.sqrt(2 * Math.PI)) - Math.log(a1)) * 2);
        diff = Math.abs(a - a1);/*  ww w .ja v a  2s .  c  o  m*/
        a1 = a;

    }
    return (a);
}

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

/**
 * {@inheritDoc}//from   w w  w . j a  v a2  s  . com
 * @throws IllegalArgumentException If the value of $x$ is not consistent with the limit (e.g. the limit is $x > a$ and $x$ is
 * less than $a$
 */
@Override
public double transform(final double x) {
    Validate.isTrue(_sign * x >= _sign * _limit, "x not in limit");
    if (x == _limit) {
        return -EXP_MAX;
    }
    final double r = _sign * (x - _limit);
    if (r > EXP_MAX) {
        return r;
    }
    return Math.log(Math.exp(r) - 1);
}

From source file:de.biomedical_imaging.traJ.features.Asymmetry3Feature.java

/**
 * @return Returns an double array with the following elements [0]=Asymmetry
 *///from  ww w  .  j a v  a2s.c o m
@Override
public double[] evaluate() {
    Array2DRowRealMatrix gyr = RadiusGyrationTensor2D.getRadiusOfGyrationTensor(t);
    EigenDecomposition eigdec = new EigenDecomposition(gyr);
    double e1 = eigdec.getRealEigenvalue(0);
    double e2 = eigdec.getRealEigenvalue(1);
    double asym = -1 * Math.log(1 - Math.pow(e1 - e2, 2) / (2 * Math.pow(e1 + e2, 2)));
    result = new double[] { asym };

    return result;
}

From source file:master.steppers.TauLeapingStepper.java

/**
 * Generate appropriate random state change according to Gillespie's
 * tau-leaping algorithm./*from  w  w  w .j  av  a2 s  . com*/
 *
 * @param reaction
 * @param state PopulationState to modify.
 * @param model
 * @param calcLogP
 * @param thisdt
 */
public void leap(Reaction reaction, PopulationState state, Model model, boolean calcLogP, double thisdt) {

    // Draw number of reactions to fire within time tau:
    double rho = reaction.getPropensity() * thisdt;
    double q = Randomizer.nextPoisson(rho);

    if (calcLogP) {
        if (rho > 0)
            stepLogP += -rho + q * Math.log(rho / thisdt) - Gamma.logGamma(q + 1);
    }

    // Implement reactions:
    state.implementReaction(reaction, q);

    // Increment event counter:
    eventCount += q;

}

From source file:net.sourceforge.jencrypt.lib.Utils.java

public static String humanReadableByteCount(long bytes) {
    int unit = 1024;
    if (bytes < unit)
        return bytes + " B";
    int exp = (int) (Math.log(bytes) / Math.log(unit));
    String pre = "kMGTPE".charAt(exp - 1) + "";
    return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
}

From source file:com.thesmartweb.swebrank.TFIDF.java

/**
 * Method to calculate idf score/*from w  w  w .  ja v  a 2s.  com*/
 * @param allwordsList all the words
 * @param termToCheck the term to check for
 * @param NumberOfDocs the number of documents we analyze
 * @return the idf score
 */
public double idfCalculator(List<List<String>> allwordsList, String termToCheck, int NumberOfDocs) {
    double count = 0;
    for (List<String> wordList : allwordsList) {
        for (String s : wordList) {
            if (s.equalsIgnoreCase(termToCheck)) {
                count++;
                break;
            }
        }

    }

    double output = 1 + Math.log(NumberOfDocs / (1 + count));
    return output;
}

From source file:edu.scripps.fl.curves.CurveFit.java

public static void fit(Curve curve) {
    log.debug("Fitting Curve: " + curve);
    double y[] = (double[]) ConvertUtils.convert(curve.getResponses(), double[].class);
    double x[] = (double[]) ConvertUtils.convert(curve.getConcentrations(), double[].class);
    for (int ii = 0; ii < x.length; ii++)
        x[ii] = Math.log10(x[ii]);
    // max, min and range
    double minY = Double.MAX_VALUE;
    double maxY = -Double.MAX_VALUE;
    double maxResp = y[y.length - 1];
    for (int i = 0; i < y.length; i++) {
        minY = Math.min(minY, y[i]);
        maxY = Math.max(maxY, y[i]);
    }/*from  w w w.j  a  va 2 s .  c  o  m*/
    curve.setResponseMin(minY);
    curve.setResponseMax(maxY);
    curve.setResponseRange(maxY - minY);
    curve.setMaxResponse(maxResp);
    // fit
    boolean flags[] = null;
    Map maps[] = null;
    double fitValues[] = null;
    Object fitResults[] = HillFit.doHill(x, y, null, HillConstants.FIT_ITER_NO, HillConstants.P4_FIT);
    if (fitResults != null) {
        flags = (boolean[]) fitResults[0];
        fitValues = (double[]) fitResults[1];
        maps = (Map[]) fitResults[2];
    }
    if (fitValues != null) {
        curve.setYZero(fitValues[6]);
        curve.setLogEC50(fitValues[0]);
        curve.setYInflection(fitValues[1]);
        curve.setHillSlope(fitValues[2]);
        curve.setR2(fitValues[3]);

        double ec50 = 1000000D * Math.exp(Math.log(10D) * curve.getLogEC50());
        double testEC50 = Math.pow(10, curve.getLogEC50());
        Double ic50 = null;
        double logIC50 = BatchHill.iccalc(curve.getYZero(), curve.getYInflection(), curve.getLogEC50(),
                curve.getHillSlope(), 50D);
        if (logIC50 < 0.0D)
            ic50 = 1000000D * Math.exp(Math.log(10D) * logIC50);
        int dn = Math.max(1, x.length - 4);
        double df = dn;
        double p = HillStat.calcPValue(curve.getYZero(), curve.getYInflection(), curve.getLogEC50(),
                curve.getHillSlope(), x, y, flags);
        int mask = 0;
        for (int i = 0; i < x.length; i++)
            if (!flags[i])
                mask++;
        double ss = HillStat.calcHillDeviation(curve.getLogEC50(), curve.getYZero(), curve.getYInflection(),
                curve.getHillSlope(), flags, null, x, y);
        curve.setEC50(ec50);
        curve.setIC50(ic50);
        curve.setPHill(p);
        curve.setSYX(ss / df);
        for (int ii = 0; ii < flags.length; ii++) {
            if (flags[ii] == true) {
                curve.setMasked(true);
                break;
            }
        }
    } else {
        curve.setLogEC50(null);
        curve.setHillSlope(null);
        curve.setR2(null);
        curve.setYInflection(null);
        curve.setYZero(null);
        curve.setEC50(null);
        curve.setIC50(null);
        curve.setPHill(null);
        curve.setSYX(null);
        curve.setMasked(false);
        flags = new boolean[x.length];
    }
    // masks
    List<Boolean> masks = new ArrayList<Boolean>(flags.length);
    CollectionUtils.addAll(masks, (Boolean[]) ConvertUtils.convert(flags, Boolean[].class));
    curve.setMask(masks);
    // classify
    curveClassification(curve, y, x, flags);
    // rank
    double rank = -BatchHill.calcRank(curve.getCurveClass(), curve.getMaxResponse(), curve.getResponseRange());
    curve.setRank(rank);
}

From source file:ec.edu.chyc.manejopersonal.util.ServerUtils.java

/***
 * Muestra el tamao de un archivo en una forma amigable (B, KB, MB, GB, TB,
 * PB, EB. Obtenido y modificado para quitar los formatos con "i" (KiB, MiB,
 * KiB, etc)://from   w  ww  .  j a va  2 s. co  m
 * https://stackoverflow.com/questions/3758606/how-to-convert-byte-size-into-human-readable-format-in-java
 *
 * @param bytes Tamao en bytes.
 * @return Texto indicando el tamao en formato amigable.
 */
public static String humanReadableByteCount(long bytes) {
    int unit = 1024;
    if (bytes < unit) {
        return bytes + " B";
    }
    int exp = (int) (Math.log(bytes) / Math.log(unit));
    String pre = ("KMGTPE").charAt(exp - 1) + "";
    return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
}

From source file:edu.asu.ca.kaushik.algorithms.randomized.lll.TwoStageSimpleMT.java

private int twoStageSimpleBound(int t, int k, int v) {
    double kChooset = CombinatoricsUtils.binomialCoefficientDouble(k, t);
    double vpowt = Math.pow(v, t);
    double denom = Math.log(vpowt / (vpowt - 1));
    double nume = Math.log(kChooset * vpowt * denom);
    return (int) Math.ceil(nume / denom);
}