Example usage for java.lang Math log10

List of usage examples for java.lang Math log10

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static double log10(double a) 

Source Link

Document

Returns the base 10 logarithm of a double value.

Usage

From source file:org.nd4j.linalg.util.BigDecimalMath.java

/**
 * Raise to an integer power and round.//from   w  w w . ja v  a 2  s .c  o m
 *
 * @param x The base.
 * @param n The exponent.
 * @return x^n.
 */
static public BigDecimal powRound(final BigDecimal x, final int n) {
    /* The relative error in the result is n times the relative error in the input.
     * The estimation is slightly optimistic due to the integer rounding of the logarithm.
     */
    MathContext mc = new MathContext(x.precision() - (int) Math.log10((double) (Math.abs(n))));
    return x.pow(n, mc);
}

From source file:netdecoder.NetDecoder.java

public Map<String, Double> computeImpactScore(Map<String, Node> controlNetwork,
        Map<String, Node> diseaseNetwork) {

    Map<String, Map<String, Double>> flowInNetworks = getFlowInNetworks(controlNetwork, diseaseNetwork);

    Map<String, Double> scores = new LinkedHashMap();
    Map<String, Double> sources = NetDecoderUtils.getSources(diseaseNetwork);
    for (String gene : flowInNetworks.keySet()) {
        //for (String path_dir : candidateGenes) {
        if (!(sources.containsKey(gene) || gene.equals("s") || gene.equals("t"))) {
            if (controlNetwork.containsKey(gene) && diseaseNetwork.containsKey(gene)) {
                double numRI = rewiredInteractions(gene, controlNetwork, diseaseNetwork);
                int numCC = correlationChange(gene, controlNetwork, diseaseNetwork);
                //double score = Math.log10((Math.abs(flowInNetworks.get(path_dir).get("difference")) * numRI * numCC));
                double score = flowInNetworks.get(gene).get("difference") * numRI * numCC;
                scores.put(gene, score);
                //System.out.println(path_dir + "\t" + score +"\t"  + numRI + "\t" + numCC + "\t" + flowInNetworks.get(path_dir).get("difference"));
            }//w ww.j  a v  a 2s .c  o  m
        }
    }
    Map<String, Double> sortedScores = NetworkFlow.sortByValues(scores);
    List<String> aux = new ArrayList(sortedScores.keySet());
    List<String> topGenes_down = aux.subList(0, 20);
    List<String> topGenes_up = aux.subList(aux.size() - 20, aux.size());
    List<String> topGenes = new ArrayList(topGenes_down);
    topGenes.addAll(topGenes_up);
    Map<String, Double> topGenesScores = new LinkedHashMap();
    for (String g : topGenes) {
        //topGenesScores.put(g, Math.log10(sortedScores.get(g)));
        if (sortedScores.get(g) > 0) {
            topGenesScores.put(g, Math.log10(sortedScores.get(g)));
        } else {
            double tmp = -Math.log10(Math.abs(sortedScores.get(g)));
            topGenesScores.put(g, tmp);
        }
    }
    return topGenesScores;
}

From source file:org.broadinstitute.gatk.tools.walkers.genotyper.afcalc.AFCalcUnitTest.java

@Test(enabled = true, dataProvider = "Models")
public void testNoPrior(final AFCalc model) {
    for (int REF_PL = 10; REF_PL <= 20; REF_PL += 10) {
        final Genotype AB = makePL(Arrays.asList(A, C), REF_PL, 0, 10000);

        final double[] flatPriors = new double[] { 0.0, 0.0, 0.0 };
        final double[] noPriors = new double[3];
        // test that function computeAlleleFrequency correctly operates when the flat prior option is set
        // computeAlleleFrequencyPriors takes linear priors
        final ArrayList<Double> inputPrior = new ArrayList<Double>();
        inputPrior.add(1.0 / 3);// w w w  .jav  a 2 s.c o  m
        inputPrior.add(1.0 / 3);
        UnifiedGenotypingEngine.computeAlleleFrequencyPriors(2, noPriors, 0.0, inputPrior);

        GetGLsTest cfgFlatPrior = new GetGLsTest(model, 1, Arrays.asList(AB), flatPriors, "flatPrior");
        GetGLsTest cfgNoPrior = new GetGLsTest(model, 1, Arrays.asList(AB), flatPriors, "noPrior");
        final AFCalcResult resultTrackerFlat = cfgFlatPrior.execute();
        final AFCalcResult resultTrackerNoPrior = cfgNoPrior.execute();

        final double pRefWithNoPrior = AB.getLikelihoods().getAsVector()[0];
        final double pHetWithNoPrior = AB.getLikelihoods().getAsVector()[1] - Math.log10(0.5);
        final double nonRefPost = Math.pow(10, pHetWithNoPrior)
                / (Math.pow(10, pRefWithNoPrior) + Math.pow(10, pHetWithNoPrior));
        final double log10NonRefPost = Math.log10(nonRefPost);

        if (!Double.isInfinite(log10NonRefPost)) {
            // check that the no-prior and flat-prior constructions yield same result
            Assert.assertEquals(resultTrackerFlat.getLog10PosteriorOfAFGT0(),
                    resultTrackerNoPrior.getLog10PosteriorOfAFGT0());
        }

    }
}

From source file:org.broadinstitute.sting.gatk.walkers.genotyper.afcalc.AFCalcUnitTest.java

@Test(enabled = true, dataProvider = "Models")
public void testNoPrior(final AFCalc model) {
    for (int REF_PL = 10; REF_PL <= 20; REF_PL += 10) {
        final Genotype AB = makePL(Arrays.asList(A, C), REF_PL, 0, 10000);

        final double[] flatPriors = new double[] { 0.0, 0.0, 0.0 };
        final double[] noPriors = new double[3];
        // test that function computeAlleleFrequency correctly operates when the flat prior option is set
        // computeAlleleFrequencyPriors takes linear priors
        final ArrayList<Double> inputPrior = new ArrayList<Double>();
        inputPrior.add(1.0 / 3);//from w w  w. j  ava2s. com
        inputPrior.add(1.0 / 3);
        UnifiedGenotyperEngine.computeAlleleFrequencyPriors(2, noPriors, 0.0, inputPrior);

        GetGLsTest cfgFlatPrior = new GetGLsTest(model, 1, Arrays.asList(AB), flatPriors, "flatPrior");
        GetGLsTest cfgNoPrior = new GetGLsTest(model, 1, Arrays.asList(AB), flatPriors, "noPrior");
        final AFCalcResult resultTrackerFlat = cfgFlatPrior.execute();
        final AFCalcResult resultTrackerNoPrior = cfgNoPrior.execute();

        final double pRefWithNoPrior = AB.getLikelihoods().getAsVector()[0];
        final double pHetWithNoPrior = AB.getLikelihoods().getAsVector()[1] - Math.log10(0.5);
        final double nonRefPost = Math.pow(10, pHetWithNoPrior)
                / (Math.pow(10, pRefWithNoPrior) + Math.pow(10, pHetWithNoPrior));
        final double log10NonRefPost = Math.log10(nonRefPost);

        if (!Double.isInfinite(log10NonRefPost)) {
            // check that the no-prior and flat-prior constructions yield same result
            Assert.assertEquals(resultTrackerFlat.getLog10PosteriorOfAFGT0(),
                    resultTrackerNoPrior.getLog10PosteriorOfAFGT0());
        }

    }
}

From source file:ui.server.GetTables.java

private List<Coordinate<Double, Double, Double>> makeKdVsTemplateLength(String anAptamerType,
        boolean negativeLog10) {
    List<Coordinate<Double, Double, Double>> rm = new ArrayList<Coordinate<Double, Double, Double>>();
    String q = makeKdVsTemplateLengthQuery(anAptamerType) + "&cursor";
    URLReader ur = new URLReader(FreebaseCredentials.getScheme(), FreebaseCredentials.getHost(),
            FreebaseCredentials.getPath(), q, FreebaseCredentials.getKey());
    JSONObject rc = ur.getJSON();/*from   w  w  w  . j  a v  a2  s.  c  o m*/
    try {
        JSONArray r = rc.getJSONArray("result");
        boolean lf = true;
        while (lf) {
            String cursorVal = rc.getString("cursor").replace("\"", "");
            r: for (int i = 0; i < r.length(); i++) {
                JSONObject ja = r.getJSONObject(i);
                // get the best kd
                Double kd_val = -1.0;
                JSONArray outs = ja.getJSONArray("/base/aptamer/experiment/has_outcome");
                for (int j = 0; j < outs.length(); j++) {
                    JSONObject anInteraction = outs.getJSONObject(j);
                    JSONArray kds = anInteraction
                            .getJSONArray("/base/aptamer/interaction/has_dissociation_constant");
                    List<Double> tmpKds = new ArrayList<Double>();
                    for (int k = 0; k < kds.length(); k++) {
                        JSONObject currKd = kds.getJSONObject(j);
                        String kd = currKd.getString("/base/aptamer/dissociation_constant/has_value");
                        String kd_tmp = currKd
                                .getString("/base/aptamer/dissociation_constant/has_temporary_string_value")
                                .replace("\"", "");
                        Double aKd = -1.0;
                        try {
                            aKd = Double.parseDouble(kd);
                        } catch (NumberFormatException e) {
                            try {
                                aKd = Double.parseDouble(kd_tmp);
                            } catch (NumberFormatException e2) {
                                aKd = -1.0;
                            }
                        }

                        if (negativeLog10 == true) {
                            if (aKd > 0.0) {
                                Double x = (-1) * Math.log10(aKd);
                                tmpKds.add(x);
                            }
                        } else {
                            tmpKds.add(aKd);
                        }
                    }
                    //find the best kd
                    kd_val = StatUtils.getMin(tmpKds);
                    //now get the template length
                    List<Double> templateLengths = new ArrayList<Double>();
                    JSONArray ecArr = anInteraction
                            .getJSONArray("/base/aptamer/experiment/has_experimetal_conditions");
                    for (int w = 0; w < ecArr.length(); w++) {
                        JSONObject anEc = ecArr.getJSONObject(w);
                        String aTemplate = null;
                        try {
                            aTemplate = anEc
                                    .getJSONArray("/base/aptamer/selex_conditions/has_template_sequence")
                                    .getString(0);
                        } catch (JSONException e) {
                            continue r;
                        }
                        Pattern p = Pattern.compile("\\w+\\-N(\\d+)\\-\\w+");
                        Matcher m = p.matcher(aTemplate);
                        if (m.matches()) {
                            String length = m.group(1);
                            try {
                                templateLengths.add(Double.parseDouble(length));
                            } catch (NumberFormatException e) {
                                continue r;
                            }
                        }
                    }

                } //for

                /*
                 * JSONArray kds = ja .getJSONArray(
                 * "/base/aptamer/interaction/has_dissociation_constant");
                 * List<Double> tmpKds = new ArrayList<Double>(); for (int j
                 * = 0; j < kds.length(); j++) { JSONObject currKd =
                 * kds.getJSONObject(j); String kd = currKd
                 * .getString("/base/aptamer/dissociation_constant/has_value"
                 * ); String kd_tmp = currKd .getString(
                 * "/base/aptamer/dissociation_constant/has_temporary_string_value"
                 * ) .replace("\"", ""); Double aKd = -1.0; try { aKd =
                 * Double.parseDouble(kd); } catch (NumberFormatException e)
                 * { try { aKd = Double.parseDouble(kd_tmp); } catch
                 * (NumberFormatException e2) { aKd = -1.0; } } if
                 * (negativeLog10 == true) { if (aKd > 0.0) { Double x =
                 * (-1) * Math.log10(aKd); tmpKds.add(x); } } else {
                 * tmpKds.add(aKd); } } // now store only the average or the
                 * best kd Double kd_val = -1.0; if (bestKdOnly) { if
                 * (tmpKds.size() > 1) { kd_val = StatUtils.getMin(tmpKds);
                 * } else { kd_val = StatUtils.getMin(tmpKds); } } else {
                 * kd_val = StatUtils.computeAverage(tmpKds); }
                 */

                /*
                 * pmid = ja.getJSONArray(
                 * "/base/aptamer/experiment/pubmed_id") .getString(0); if
                 * (pmid != null && pmid.length() > 0) { if
                 * (!pubmeds.containsKey(pmid)) { // get the year PubmedInfo
                 * pi = new PubmedInfo(pmid); year =
                 * pi.getPublicationYear(); pubmeds.put(pmid, pi); } else {
                 * year = pubmeds.get(pmid).getPublicationYear(); } } }
                 * catch (JSONException e) { continue r; }
                 */
                // get the template length

            } // for
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:de.bund.bfr.knime.pmm.common.chart.Plotable.java

public static Double inverseTransform(Double value, String transform) {
    if (value == null) {
        return null;
    } else if (transform.equals(ChartConstants.NO_TRANSFORM)) {
        return value;
    } else if (transform.equals(ChartConstants.SQRT_TRANSFORM)) {
        return value * value;
    } else if (transform.equals(ChartConstants.LOG_TRANSFORM)) {
        return Math.exp(value);
    } else if (transform.equals(ChartConstants.LOG10_TRANSFORM)) {
        return Math.pow(10.0, value);
    } else if (transform.equals(ChartConstants.EXP_TRANSFORM)) {
        return Math.log(value);
    } else if (transform.equals(ChartConstants.EXP10_TRANSFORM)) {
        return Math.log10(value);
    } else if (transform.equals(ChartConstants.DIVX_TRANSFORM)) {
        return 1 / value;
    } else if (transform.equals(ChartConstants.DIVX2_TRANSFORM)) {
        return 1 / Math.sqrt(value);
    }/*  w  w  w .ja  va2 s  . c o m*/

    return null;
}

From source file:org.broadinstitute.gatk.tools.walkers.genotyper.afcalc.AFCalcUnitTest.java

@Test(enabled = true && !DEBUG_ONLY, dataProvider = "Models")
public void testBiallelicPriors(final AFCalc model) {

    for (int REF_PL = 10; REF_PL <= 20; REF_PL += 10) {
        final Genotype AB = makePL(Arrays.asList(A, C), REF_PL, 0, 10000);

        for (int log10NonRefPrior = 1; log10NonRefPrior < 10 * REF_PL; log10NonRefPrior += 1) {
            final double refPrior = 1 - QualityUtils.qualToErrorProb(log10NonRefPrior);
            final double nonRefPrior = (1 - refPrior) / 2;
            final double[] priors = MathUtils.normalizeFromLog10(
                    MathUtils.toLog10(new double[] { refPrior, nonRefPrior, nonRefPrior }), true);
            if (!Double.isInfinite(priors[1])) {
                GetGLsTest cfg = new GetGLsTest(model, 1, Arrays.asList(AB), priors,
                        "pNonRef" + log10NonRefPrior);
                final AFCalcResult resultTracker = cfg.execute();
                final int actualAC = resultTracker.getAlleleCountsOfMLE()[0];

                final double pRefWithPrior = AB.getLikelihoods().getAsVector()[0] + priors[0];
                final double pHetWithPrior = AB.getLikelihoods().getAsVector()[1] + priors[1] - Math.log10(0.5);
                final double nonRefPost = Math.pow(10, pHetWithPrior)
                        / (Math.pow(10, pRefWithPrior) + Math.pow(10, pHetWithPrior));
                final double log10NonRefPost = Math.log10(nonRefPost);

                if (!Double.isInfinite(log10NonRefPost))
                    Assert.assertEquals(resultTracker.getLog10PosteriorOfAFGT0(), log10NonRefPost, 1e-2);

                if (nonRefPost >= 0.9)
                    Assert.assertTrue(resultTracker.isPolymorphic(C, -1));

                final int expectedMLEAC = 1; // the MLE is independent of the prior
                Assert.assertEquals(actualAC, expectedMLEAC, "actual AC with priors " + log10NonRefPrior
                        + " not expected " + expectedMLEAC + " priors " + Utils.join(",", priors));
            }/*from ww w.  j av  a  2 s .c om*/
        }
    }
}

From source file:org.nd4j.linalg.util.BigDecimalMath.java

/**
 * Trigonometric sine./*w  w w.  j av  a  2 s .co m*/
 *
 * @param x The argument in radians.
 * @return sin(x) in the range -1 to 1.
 */
static public BigDecimal sin(final BigDecimal x) {
    if (x.compareTo(BigDecimal.ZERO) < 0) {
        return sin(x.negate()).negate();
    } else if (x.compareTo(BigDecimal.ZERO) == 0) {
        return BigDecimal.ZERO;
    } else {
        /* reduce modulo 2pi
         */
        BigDecimal res = mod2pi(x);
        double errpi = 0.5 * Math.abs(x.ulp().doubleValue());
        int val = 2 + err2prec(FastMath.PI, errpi);
        MathContext mc = new MathContext(val);
        BigDecimal p = pi(mc);
        mc = new MathContext(x.precision());
        if (res.compareTo(p) > 0) {
            /* pi<x<=2pi: sin(x)= - sin(x-pi)
             */
            return sin(subtractRound(res, p)).negate();
        } else if (res.multiply(new BigDecimal("2")).compareTo(p) > 0) {
            /* pi/2<x<=pi: sin(x)= sin(pi-x)
             */
            return sin(subtractRound(p, res));
        } else {
            /* for the range 0<=x<Pi/2 one could use sin(2x)=2sin(x)cos(x)
             * to split this further. Here, use the sine up to pi/4 and the cosine higher up.
             */
            if (res.multiply(new BigDecimal("4")).compareTo(p) > 0) {
                /* x>pi/4: sin(x) = cos(pi/2-x)
                 */
                return cos(subtractRound(p.divide(new BigDecimal("2")), res));
            } else {
                /* Simple Taylor expansion, sum_{i=1..infinity} (-1)^(..)res^(2i+1)/(2i+1)! */
                BigDecimal resul = res;
                /* x^i */
                BigDecimal xpowi = res;
                /* 2i+1 factorial */
                BigInteger ifac = BigInteger.ONE;
                /* The error in the result is set by the error in x itself.
                 */
                double xUlpDbl = res.ulp().doubleValue();
                /* The error in the result is set by the error in x itself.
                 * We need at most k terms to squeeze x^(2k+1)/(2k+1)! below this value.
                 * x^(2k+1) < x.ulp; (2k+1)*log10(x) < -x.precision; 2k*log10(x)< -x.precision;
                 * 2k*(-log10(x)) > x.precision; 2k*log10(1/x) > x.precision
                 */
                int k = (int) (res.precision() / Math.log10(1.0 / res.doubleValue())) / 2;
                MathContext mcTay = new MathContext(err2prec(res.doubleValue(), xUlpDbl / k));
                for (int i = 1;; i++) {
                    /* TBD: at which precision will 2*i or 2*i+1 overflow?
                     */
                    ifac = ifac.multiply(new BigInteger("" + (2 * i)));
                    ifac = ifac.multiply(new BigInteger("" + (2 * i + 1)));
                    xpowi = xpowi.multiply(res).multiply(res).negate();
                    BigDecimal corr = xpowi.divide(new BigDecimal(ifac), mcTay);
                    resul = resul.add(corr);
                    if (corr.abs().doubleValue() < 0.5 * xUlpDbl) {
                        break;
                    }
                }
                /* The error in the result is set by the error in x itself.
                 */
                mc = new MathContext(res.precision());
                return resul.round(mc);
            }
        }
    } /* sin */
}

From source file:org.florescu.android.rangeseekbar.RangeSeekBar.java

/**
 * Converts a normalized value to a Number object in the value space between absolute minimum and maximum.
 *///from ww  w .  j  a va 2s .com
@SuppressWarnings("unchecked")
private T normalizedToValue(double normalized) {
    double v = absoluteMinValuePrim + normalized * (absoluteMaxValuePrim - absoluteMinValuePrim);
    switch (rangeType) {
    case LINEAR:
        return (T) numberType.toNumber(Math.round(v / step) * step);
    case GENERATED:
    case PREDEFINED:
        if (predefinedRangeValues == null)
            return (T) numberType.toNumber(0);
        int index = (int) (normalized * (predefinedRangeValues.size() - 1));
        if (index >= predefinedRangeValues.size())
            index = predefinedRangeValues.size() - 1;
        return predefinedRangeValues.get(index);
    case CUBIC:
        int minAddition = 0;
        int minimumAllowedValue = (int) Math.pow(10, minimumCubicStepDigits - 1);
        if (absoluteMinValue.doubleValue() < minimumAllowedValue) {
            if (normalized == 0) {
                return (T) numberType.toNumber(0);
            }
            minAddition = minimumAllowedValue;
        }
        double rawValue = Math.pow(normalized * cubicMultiplier, 3) + absoluteMinValue.doubleValue()
                + minAddition;
        int round = (int) Math.max(Math.pow(10, (int) Math.log10(rawValue) - 1), minimumAllowedValue);
        return (T) numberType.toNumber(((int) rawValue / round) * round);
    }
    return (T) numberType.toNumber(Math.round(v / step) * step);
}

From source file:uk.ac.diamond.scisoft.analysis.rcp.views.HistogramView.java

private void histrogramUIUpdate() {
    if (!hasData()) {
        System.err.println("No data available in histogram view!");
        return;//from w  w w.j a va  2  s.co  m
    }
    double max = data.max().doubleValue();
    double min = data.min().doubleValue();
    double step = max - min;
    if (step != 0) {
        int prec = (int) Math.ceil(-Math.log10(step / 100));
        int wide = (int) Math.ceil(Math.log10(Math.max(Math.abs(max), Math.abs(min))));
        if (wide <= 0)
            wide = 2;
        if (prec <= 0)
            prec = 1;
        spnRangeStart.setFormat(prec + wide, prec);
        spnRangeStop.setFormat(prec + wide, prec);
    }
    spnRangeStart.setMaximum(max);
    spnRangeStart.setMinimum(min);
    spnRangeStop.setMaximum(max);
    spnRangeStop.setMinimum(min);

    // Set the values from the max and min which were specified by the colour table (this persists locked values)
    spnRangeStop.setDouble(currentMaxMin.max);
    spnRangeStart.setDouble(currentMaxMin.min);

    // Now the slider positions need to be calculated
    double minProportion = (currentMaxMin.min - min) / step;
    sldMinValue.setSelection((int) Math.floor((sldMinValue.getMaximum() * minProportion)));
    double maxProportion = (currentMaxMin.max - min) / step;
    sldMaxValue.setSelection((int) Math.floor((sldMinValue.getMaximum() * maxProportion)));

    spnRangeStart.setEnabled(true);
    spnRangeStop.setEnabled(true);
    sldMinValue.setEnabled(true);
    sldMaxValue.setEnabled(true);

    updateHistogramGraph(currentMaxMin.min, currentMaxMin.max);
    buildGradientImage();
}