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.ncic.bioinfo.sparkseq.algorithms.utils.MathUtils.java

/**
 * Compute in a numerical correct way the quantity log10(1-x)
 *
 * Uses the approximation log10(1-x) = log10(1/x - 1) + log10(x) to avoid very quick underflow
 * in 1-x when x is very small/*from  w ww .j a  v  a  2 s. co m*/
 *
 * @param x a positive double value between 0.0 and 1.0
 * @return an estimate of log10(1-x)
 */
public static double log10OneMinusX(final double x) {
    if (x == 1.0)
        return Double.NEGATIVE_INFINITY;
    else if (x == 0.0)
        return 0.0;
    else {
        final double d = Math.log10(1 / x - 1) + Math.log10(x);
        return Double.isInfinite(d) || d > 0.0 ? 0.0 : d;
    }
}

From source file:org.broadinstitute.gatk.utils.MathUtils.java

/**
 * Compute in a numerical correct way the quantity log10(1-x)
 *
 * Uses the approximation log10(1-x) = log10(1/x - 1) + log10(x) to avoid very quick underflow
 * in 1-x when x is very small//w  ww .  j a v  a2s. com
 *
 * @param x a positive double value between 0.0 and 1.0
 * @return an estimate of log10(1-x)
 */
@Requires("x >= 0.0 && x <= 1.0")
@Ensures("result <= 0.0")
public static double log10OneMinusX(final double x) {
    if (x == 1.0)
        return Double.NEGATIVE_INFINITY;
    else if (x == 0.0)
        return 0.0;
    else {
        final double d = Math.log10(1 / x - 1) + Math.log10(x);
        return Double.isInfinite(d) || d > 0.0 ? 0.0 : d;
    }
}

From source file:give_me_coins.dashboard.MainScreen.java

static String readableHashSize(long size) {
    if (size <= 0)
        return String.valueOf(size);
    final String[] units = new String[] { "Kh/s", "Mh/s", "Gh/s", "Th/s", "Ph/s", "Eh/s" }; //we left ouh h/s because API puts dot at kh/s!!
    int digitGroups = (int) (Math.log10(size) / Math.log10(1000));
    return new DecimalFormat("#,##0.#").format(size / Math.pow(1000, digitGroups)) + " " + units[digitGroups];
}

From source file:netdecoder.NetDecoder.java

public Set<String> prioritizeHiddenProteins(Map<String, Node> controlNetwork, Map<String, Node> diseaseNetwork,
        String condition, int topHidden, RJava rJava, String filename, List<String> Rscripts)
        throws IOException {

    Map<String, Map<String, Double>> flowInNetworks = getFlowInNetworks(controlNetwork, diseaseNetwork);
    Map<String, Double> hiddenProteinsControl = NetDecoderUtils.getHiddenProteins(controlNetwork);
    Map<String, Double> hiddenProteinsDisease = NetDecoderUtils.getHiddenProteins(diseaseNetwork);
    Set<String> allHidden = new LinkedHashSet(hiddenProteinsControl.keySet());
    allHidden.addAll(hiddenProteinsDisease.keySet());
    Map<String, Double> flowDifference = NetDecoderUtils.getFlowDifference(flowInNetworks, allHidden);

    Map<String, Double> sortedScores = NetworkFlow.sortByValues(flowDifference);
    List<String> aux = new ArrayList(sortedScores.keySet());
    List<String> topGenes_down = aux.subList(0, topHidden);
    List<String> topGenes_up = aux.subList(aux.size() - topHidden, aux.size());
    List<String> topGenes = new ArrayList(topGenes_down);
    topGenes.addAll(topGenes_up);//  w  w w . j  av a2  s.  c o m
    Map<String, Double> topGenesScores = new LinkedHashMap();
    for (String g : topGenes) {
        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);
        }
    }
    String name = filename + "_HIDDEN";
    NetDecoderUtils.saveFlows(topGenesScores, name + ".txt");
    //rJava.plotHeatmapSH2(name, condition, topHidden, "Network routers", filename);
    String heatmap = rJava.createHeatmapSH2Script(name, condition, topHidden, "Network routers", filename);
    Rscripts.add(heatmap);
    //save network motifs for network routers here (downstream genes, network router is "from" in the edge): 
    Map<String, Double> totalFlowsDisease = NetDecoderUtils.getTotalFlow(diseaseNetwork);
    Map<String, Double> totalFlowsControl = NetDecoderUtils.getTotalFlow(controlNetwork);
    for (String gene : topGenesScores.keySet()) {
        if (controlNetwork.containsKey(gene)) {
            List<Edge> controlEdges = controlNetwork.get(gene).getEdges();
            Map<String, Node> cNet = NetDecoderUtils.createMotifNetworkRouters(gene, controlEdges);
            (new NetworkFlow()).saveSubNet(cNet, filename + "_" + gene + "_NR_Control.txt");

            Map<String, Double> controlDiff = getFlowDifference(flowInNetworks, cNet.keySet());
            Map<String, Double> controlTotal = getTotalFlowInProteins(totalFlowsControl, cNet.keySet());
            Map<String, Double> controlEdgesFlow = getEdgeFlow(cNet);
            NetDecoderUtils.saveFlows(controlTotal, filename + "_" + gene + "_NR_totalFlow_Control.txt");
            NetDecoderUtils.saveFlows(controlDiff, filename + "_" + gene + "_NR_flowDifference_Control.txt");
            NetDecoderUtils.saveFlows(controlEdgesFlow, filename + "_" + gene + "_NR_edge_flows_Control.txt");

            /*rJava.exportGML2(filename + "_" + gene + "_NR_Control",
                filename + "_" + gene + "_NR_totalFlow_Control",
                filename + "_" + gene + "_NR_flowDifference_Control");
                    
            rJava.plotDistribution(filename + "_" + gene + "_NR_edge_flows_Control", "Control");*/
            String gmlControl = rJava.createScriptExportGML2(filename + "_" + gene + "_NR_Control",
                    filename + "_" + gene + "_NR_totalFlow_Control",
                    filename + "_" + gene + "_NR_flowDifference_Control");

            String distrControl = rJava
                    .createDistributionScript(filename + "_" + gene + "_NR_edge_flows_Control", "Control");
            Rscripts.add(gmlControl);
            Rscripts.add(distrControl);
        }
        if (diseaseNetwork.containsKey(gene)) {
            List<Edge> diseaseEdges = diseaseNetwork.get(gene).getEdges();
            Map<String, Node> dNet = NetDecoderUtils.createMotifNetworkRouters(gene, diseaseEdges);
            (new NetworkFlow()).saveSubNet(dNet, filename + "_" + gene + "_NR_Disease.txt");

            Map<String, Double> diseaseDiff = getFlowDifference(flowInNetworks, dNet.keySet());
            Map<String, Double> diseaseTotal = getTotalFlowInProteins(totalFlowsDisease, dNet.keySet());
            Map<String, Double> diseaseEdgesFlow = getEdgeFlow(dNet);
            NetDecoderUtils.saveFlows(diseaseTotal, filename + "_" + gene + "_NR_totalFlow_Disease.txt");
            NetDecoderUtils.saveFlows(diseaseDiff, filename + "_" + gene + "_NR_flowDifference_Disease.txt");
            NetDecoderUtils.saveFlows(diseaseEdgesFlow, filename + "_" + gene + "_NR_edge_flows_Disease.txt");

            String gmlDisease = rJava.createScriptExportGML2(filename + "_" + gene + "_NR_Disease",
                    filename + "_" + gene + "_NR_totalFlow_Disease",
                    filename + "_" + gene + "_NR_flowDifference_Disease");

            String distrDisease = rJava
                    .createDistributionScript(filename + "_" + gene + "_NR_edge_flows_Disease", condition);

            Rscripts.add(gmlDisease);
            Rscripts.add(distrDisease);
        }
    }
    return topGenesScores.keySet();
}

From source file:org.esa.nest.gpf.ASARCalibrator.java

public void removeFactorsForCurrentTile(Band targetBand, Tile targetTile, String srcBandName)
        throws OperatorException {

    if (!srgrFlag) {
        return;//from   w  w  w.ja va 2s  .  c om
    }

    final Rectangle targetTileRectangle = targetTile.getRectangle();
    final int x0 = targetTileRectangle.x;
    final int y0 = targetTileRectangle.y;
    final int w = targetTileRectangle.width;
    final int h = targetTileRectangle.height;
    //System.out.println("x0 = " + x0 + ", y0 = " + y0 + ", w = " + w + ", h = " + h);

    final Band sourceBand = sourceProduct.getBand(srcBandName);
    final Tile sourceTile = calibrationOp.getSourceTile(sourceBand, targetTileRectangle);
    final ProductData srcData = sourceTile.getDataBuffer();
    final Unit.UnitType bandUnit = Unit.getUnitType(sourceBand);
    final ProductData trgData = targetTile.getDataBuffer();

    final String pol = OperatorUtils.getBandPolarization(targetBand.getName(), absRoot);
    int prodBand = 0;
    if (pol != null && mdsPolar[1] != null && mdsPolar[1].contains(pol)) {
        prodBand = 1;
    }

    final double[][] targetTileNewAntPat = new double[h][w];
    final double[][] targetTileSlantRange = new double[h][w];
    final double[][] targetTileOldAntPat = new double[h][w];

    final TiePointInterpolator slantRangeTPGInterp = new TiePointInterpolator(slantRangeTime);

    if (wideSwathProductFlag) {
        computeWideSwathAntennaPatternForCurrentTile(x0, y0, w, h, targetTileOldAntPat, targetTileNewAntPat,
                targetTileSlantRange, slantRangeTPGInterp);
    } else {
        computeSingleSwathAntennaPatternForCurrentTile(x0, y0, w, h, targetTileOldAntPat, targetTileNewAntPat,
                targetTileSlantRange, prodBand, slantRangeTPGInterp);
    }

    final int maxY = y0 + h;
    final int maxX = x0 + w;
    double gain, slantRange, v;
    for (int y = y0, yy = 0; y < maxY; ++y, ++yy) {
        for (int x = x0, xx = 0; x < maxX; ++x, ++xx) {
            v = srcData.getElemDoubleAt(sourceTile.getDataBufferIndex(x, y));
            gain = targetTileOldAntPat[yy][xx];
            slantRange = targetTileSlantRange[yy][xx];

            if (bandUnit == Unit.UnitType.AMPLITUDE) {
                v *= Math.sqrt(gain) * Math.pow(refSlantRange800km / slantRange, 0.5 * rangeSpreadingCompPower);
            } else if (bandUnit == Unit.UnitType.AMPLITUDE_DB) {
                v = Math.pow(10, v / 10.0) * Math.sqrt(gain)
                        * Math.pow(refSlantRange800km / slantRange, 0.5 * rangeSpreadingCompPower);
                v = 10.0 * Math.log10(v);
            } else if (bandUnit == Unit.UnitType.INTENSITY) {
                v *= gain * Math.pow(refSlantRange800km / slantRange, rangeSpreadingCompPower);
            } else if (bandUnit == Unit.UnitType.INTENSITY_DB) {
                v = Math.pow(10, v / 10.0) * gain
                        * Math.pow(refSlantRange800km / slantRange, rangeSpreadingCompPower);
                v = 10.0 * Math.log10(v);
            } else {
                throw new OperatorException("Unknown band unit");
            }

            trgData.setElemDoubleAt(targetTile.getDataBufferIndex(x, y), v);
        }
    }
}

From source file:org.esa.s1tbx.calibration.gpf.ASARCalibrator.java

public void removeFactorsForCurrentTile(Band targetBand, Tile targetTile, String srcBandName)
        throws OperatorException {

    if (!srgrFlag) {
        return;//w  w w .j av a  2s  .  c om
    }

    final Rectangle targetTileRectangle = targetTile.getRectangle();
    final int x0 = targetTileRectangle.x;
    final int y0 = targetTileRectangle.y;
    final int w = targetTileRectangle.width;
    final int h = targetTileRectangle.height;
    //System.out.println("x0 = " + x0 + ", y0 = " + y0 + ", w = " + w + ", h = " + h);

    final Band sourceBand = sourceProduct.getBand(srcBandName);
    final Tile sourceTile = calibrationOp.getSourceTile(sourceBand, targetTileRectangle);
    final ProductData srcData = sourceTile.getDataBuffer();
    final Unit.UnitType bandUnit = Unit.getUnitType(sourceBand);
    final ProductData trgData = targetTile.getDataBuffer();

    final String pol = OperatorUtils.getBandPolarization(targetBand.getName(), absRoot);
    int prodBand = 0;
    if (pol != null && mdsPolar[1] != null && mdsPolar[1].contains(pol)) {
        prodBand = 1;
    }

    final double[][] targetTileNewAntPat = new double[h][w];
    final double[][] targetTileSlantRange = new double[h][w];
    final double[][] targetTileOldAntPat = new double[h][w];

    final TiePointInterpolator slantRangeTPGInterp = new TiePointInterpolator(slantRangeTime);

    if (wideSwathProductFlag) {
        computeWideSwathAntennaPatternForCurrentTile(x0, y0, w, h, targetTileOldAntPat, targetTileNewAntPat,
                targetTileSlantRange, slantRangeTPGInterp);
    } else {
        computeSingleSwathAntennaPatternForCurrentTile(x0, y0, w, h, targetTileOldAntPat, targetTileNewAntPat,
                targetTileSlantRange, prodBand, slantRangeTPGInterp);
    }

    final int maxY = y0 + h;
    final int maxX = x0 + w;
    double gain, slantRange, v;
    for (int y = y0, yy = 0; y < maxY; ++y, ++yy) {
        for (int x = x0, xx = 0; x < maxX; ++x, ++xx) {
            v = srcData.getElemDoubleAt(sourceTile.getDataBufferIndex(x, y));
            gain = targetTileOldAntPat[yy][xx];
            slantRange = targetTileSlantRange[yy][xx];

            if (bandUnit == Unit.UnitType.AMPLITUDE) {
                v *= Math.sqrt(gain)
                        * FastMath.pow(refSlantRange800km / slantRange, 0.5 * rangeSpreadingCompPower);
            } else if (bandUnit == Unit.UnitType.AMPLITUDE_DB) {
                v = FastMath.pow(10, v / 10.0) * Math.sqrt(gain)
                        * FastMath.pow(refSlantRange800km / slantRange, 0.5 * rangeSpreadingCompPower);
                v = 10.0 * Math.log10(v);
            } else if (bandUnit == Unit.UnitType.INTENSITY) {
                v *= gain * FastMath.pow(refSlantRange800km / slantRange, rangeSpreadingCompPower);
            } else if (bandUnit == Unit.UnitType.INTENSITY_DB) {
                v = FastMath.pow(10, v / 10.0) * gain
                        * FastMath.pow(refSlantRange800km / slantRange, rangeSpreadingCompPower);
                v = 10.0 * Math.log10(v);
            } else {
                throw new OperatorException("Unknown band unit");
            }

            trgData.setElemDoubleAt(targetTile.getDataBufferIndex(x, y), v);
        }
    }
}

From source file:org.esa.nest.gpf.ERSCalibrator.java

private boolean isADCNeeded(final Band sourceBand1, final Band sourceBand2, final Unit.UnitType bandUnit) {

    final int w = Math.min(windowWidth, sourceImageWidth);
    final int h = Math.min(windowHeight, sourceImageHeight);
    final int x0 = (sourceImageWidth - w) / 2;
    final int y0 = (sourceImageHeight - h) / 2;

    final Rectangle sourceTileRectangle = new Rectangle(x0, y0, w, h);
    final Tile sourceRaster1 = getSourceTile(sourceBand1, sourceTileRectangle);
    Tile sourceRaster2 = null;// w  ww .  j av  a2  s  . com
    if (sourceBand2 != null) {
        sourceRaster2 = getSourceTile(sourceBand2, sourceTileRectangle);
    }

    final ProductData srcData1 = sourceRaster1.getDataBuffer();
    ProductData srcData2 = null;
    if (sourceRaster2 != null)
        srcData2 = sourceRaster2.getDataBuffer();

    int index;
    double sigma = 0.0;
    for (int y = y0; y < y0 + h; y++) {
        for (int x = x0; x < x0 + w; x++) {

            index = sourceRaster1.getDataBufferIndex(x, y);

            if (bandUnit == Unit.UnitType.AMPLITUDE) {
                final double dn = srcData1.getElemDoubleAt(index);
                sigma += dn * dn;
            } else if (bandUnit == Unit.UnitType.INTENSITY) {
                sigma += srcData1.getElemDoubleAt(index);
            } else { // COMPLEX
                final double i = srcData1.getElemDoubleAt(index);
                final double q = srcData2.getElemDoubleAt(index);
                sigma += i * i + q * q;
            }
        }
    }
    sigma /= w * h * calibrationConstant;
    if (sigma < underFlowFloat) {
        sigma = Math.min(ers1ApplyADCThreshold, ers2ApplyADCThreshold);
    } else {
        sigma = 10.0 * Math.log10(sigma);
    }

    if (isERS1Mission && sigma <= ers1ApplyADCThreshold) {
        return false;
    }

    return !(!isERS1Mission && sigma <= ers2ApplyADCThreshold);
}

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

/**
 * Riemann zeta function./*  w ww  . ja v  a 2 s  . c om*/
 *
 * @param n  The positive integer argument.
 *           32
 * @param mc Specification of the accuracy of the result.
 * @return zeta(n).
 */
static public BigDecimal zeta(final int n, final MathContext mc) {
    if (n <= 0) {
        throw new ProviderException("Unimplemented zeta at negative argument " + n);
    }

    if (n == 1) {
        throw new ArithmeticException("Pole at zeta(1) ");
    }

    if (n % 2 == 0) {
        /* Even indices. Abramowitz-Stegun 23.2.16. Start with 2^(n-1)*B(n)/n!
         */
        Rational b = (new Bernoulli()).at(n).abs();
        b = b.divide((new Factorial()).at(n));
        b = b.multiply(BigInteger.ONE.shiftLeft(n - 1));
        /* to be multiplied by pi^n. Absolute error in the result of pi^n is n times
         * error in pi times pi^(n-1). Relative error is n*error(pi)/pi, requested by mc.
         * Need one more digit in pi if n=10, two digits if n=100 etc, and add one extra digit.
         */
        MathContext mcpi = new MathContext(mc.getPrecision() + (int) (Math.log10(10.0 * n)));
        final BigDecimal piton = pi(mcpi).pow(n, mc);

        return multiplyRound(piton, b);

    } else if (n == 3) {
        /* Broadhurst BBP \protect\vrule width0pt\protect\href{http://arxiv.org/abs/math/9803067}{arXiv:math/9803067}
         * Error propagation: S31 is roughly 0.087, S33 roughly 0.131
         */
        int[] a31 = { 1, -7, -1, 10, -1, -7, 1, 0 };

        int[] a33 = { 1, 1, -1, -2, -1, 1, 1, 0 };
        BigDecimal S31 = broadhurstBBP(3, 1, a31, mc);
        BigDecimal S33 = broadhurstBBP(3, 3, a33, mc);
        S31 = S31.multiply(new BigDecimal(48));
        S33 = S33.multiply(new BigDecimal(32));

        return S31.add(S33).divide(new BigDecimal(7), mc);

    } else if (n == 5) {
        /* Broadhurst BBP \protect\vrule width0pt\protect\href{http://arxiv.org/abs/math/9803067}{arXiv:math/9803067}
         * Error propagation: S51 is roughly -11.15, S53 roughly 22.165, S55 is roughly 0.031
         * 9*2048*S51/6265 = -3.28. 7*2038*S53/61651= 5.07. 738*2048*S55/61651= 0.747.
         * The result is of the order 1.03, so we add 2 digits to S51 and S52 and one digit to S55.
         */
        int[] a51 = { 31, -1614, -31, -6212, -31, -1614, 31, 74552 };

        int[] a53 = { 173, 284, -173, -457, -173, 284, 173, -111 };

        int[] a55 = { 1, 0, -1, -1, -1, 0, 1, 1 };
        BigDecimal S51 = broadhurstBBP(5, 1, a51, new MathContext(2 + mc.getPrecision()));
        BigDecimal S53 = broadhurstBBP(5, 3, a53, new MathContext(2 + mc.getPrecision()));
        BigDecimal S55 = broadhurstBBP(5, 5, a55, new MathContext(1 + mc.getPrecision()));
        S51 = S51.multiply(new BigDecimal(18432));
        S53 = S53.multiply(new BigDecimal(14336));
        S55 = S55.multiply(new BigDecimal(1511424));

        return S51.add(S53).subtract(S55).divide(new BigDecimal(62651), mc);

    } else {
        /* Cohen et al Exp Math 1 (1) (1992) 25
         */
        Rational betsum = new Rational();
        Bernoulli bern = new Bernoulli();
        Factorial fact = new Factorial();

        for (int npr = 0; npr <= (n + 1) / 2; npr++) {
            Rational b = bern.at(2 * npr).multiply(bern.at(n + 1 - 2 * npr));
            b = b.divide(fact.at(2 * npr)).divide(fact.at(n + 1 - 2 * npr));
            b = b.multiply(1 - 2 * npr);

            if (npr % 2 == 0) {
                betsum = betsum.add(b);
            } else {
                betsum = betsum.subtract(b);
            }

        }
        betsum = betsum.divide(n - 1);
        /* The first term, including the facor (2pi)^n, is essentially most
         * of the result, near one. The second term below is roughly in the range 0.003 to 0.009.
         * So the precision here is matching the precisionn requested by mc, and the precision
         * requested for 2*pi is in absolute terms adjusted.
         */
        MathContext mcloc = new MathContext(2 + mc.getPrecision() + (int) (Math.log10((double) (n))));
        BigDecimal ftrm = pi(mcloc).multiply(new BigDecimal(2));
        ftrm = ftrm.pow(n);

        ftrm = multiplyRound(ftrm, betsum.BigDecimalValue(mcloc));
        BigDecimal exps = new BigDecimal(0);
        /* the basic accuracy of the accumulated terms before multiplication with 2
         */

        double eps = Math.pow(10., -mc.getPrecision());

        if (n % 4 == 3) {
            /* since the argument n is at least 7 here, the drop
             * of the terms is at rather constant pace at least 10^-3, for example
             * 0.0018, 0.2e-7, 0.29e-11, 0.74e-15 etc for npr=1,2,3.... We want 2 times these terms
             * fall below eps/10.
             */
            int kmax = mc.getPrecision() / 3;
            eps /= kmax;
            /* need an error of eps for 2/(exp(2pi)-1) = 0.0037
             * The absolute error is 4*exp(2pi)*err(pi)/(exp(2pi)-1)^2=0.0075*err(pi)
             */
            BigDecimal exp2p = pi(new MathContext(3 + err2prec(3.14, eps / 0.0075)));
            exp2p = exp(exp2p.multiply(new BigDecimal(2)));
            BigDecimal c = exp2p.subtract(BigDecimal.ONE);
            exps = divideRound(1, c);

            for (int npr = 2; npr <= kmax; npr++) {
                /* the error estimate above for npr=1 is the worst case of
                 * the absolute error created by an error in 2pi. So we can
                 * safely re-use the exp2p value computed above without
                 * reassessment of its error.
                 */
                c = powRound(exp2p, npr).subtract(BigDecimal.ONE);
                c = multiplyRound(c, (new BigInteger("" + npr)).pow(n));
                c = divideRound(1, c);
                exps = exps.add(c);

            }
        } else {
            /* since the argument n is at least 9 here, the drop
             * of the terms is at rather constant pace at least 10^-3, for example
             * 0.0096, 0.5e-7, 0.3e-11, 0.6e-15 etc. We want these terms
             * fall below eps/10.
             */
            int kmax = (1 + mc.getPrecision()) / 3;
            eps /= kmax;
            /* need an error of eps for 2/(exp(2pi)-1)*(1+4*Pi/8/(1-exp(-2pi)) = 0.0096
             * at k=7 or = 0.00766 at k=13 for example.
             * The absolute error is 0.017*err(pi) at k=9, 0.013*err(pi) at k=13, 0.012 at k=17
             */
            BigDecimal twop = pi(new MathContext(3 + err2prec(3.14, eps / 0.017)));
            twop = twop.multiply(new BigDecimal(2));
            BigDecimal exp2p = exp(twop);
            BigDecimal c = exp2p.subtract(BigDecimal.ONE);
            exps = divideRound(1, c);
            c = BigDecimal.ONE.subtract(divideRound(1, exp2p));
            c = divideRound(twop, c).multiply(new BigDecimal(2));
            c = divideRound(c, n - 1).add(BigDecimal.ONE);
            exps = multiplyRound(exps, c);

            for (int npr = 2; npr <= kmax; npr++) {
                c = powRound(exp2p, npr).subtract(BigDecimal.ONE);
                c = multiplyRound(c, (new BigInteger("" + npr)).pow(n));
                BigDecimal d = divideRound(1, exp2p.pow(npr));
                d = BigDecimal.ONE.subtract(d);
                d = divideRound(twop, d).multiply(new BigDecimal(2 * npr));
                d = divideRound(d, n - 1).add(BigDecimal.ONE);
                d = divideRound(d, c);
                exps = exps.add(d);

            }
        }
        exps = exps.multiply(new BigDecimal(2));

        return ftrm.subtract(exps, mc);

    }
}

From source file:org.gumtree.vis.plot1d.LogarithmizableAxis.java

private List getAllTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
    // TODO Auto-generated method stub
    List ticks = new java.util.ArrayList();
    Range range = getRange();/*from ww  w. java2s . c o m*/

    //get lower bound value:
    double lowerBoundVal = range.getLowerBound();
    //if small log values and lower bound value too small
    // then set to a small value (don't allow <= 0):
    if (this.smallLogFlag && lowerBoundVal < SMALL_LOG_VALUE) {
        lowerBoundVal = SMALL_LOG_VALUE;
    }

    //get upper bound value
    double upperBoundVal = range.getUpperBound();

    //get log10 version of lower bound and round to integer:
    int iBegCount = (int) Math.rint(switchedLog10(lowerBoundVal));
    //get log10 version of upper bound and round to integer:
    int iEndCount = (int) Math.rint(switchedLog10(upperBoundVal));

    //        if (iBegCount == iEndCount && iBegCount >= 0
    if (iBegCount == iEndCount && Math.pow(10, iBegCount) > lowerBoundVal) {
        //only 1 power of 10 value, it's > 0 and its resulting
        // tick value will be larger than lower bound of data
        --iBegCount; //decrement to generate more ticks
    }

    int numberOfGrids = 0;
    int numberOfTicks = 0;
    NumberTick lastTick = null;

    double currentTickValue;
    String tickLabel;
    boolean zeroTickFlag = false;
    for (int i = iBegCount; i <= iEndCount; i++) {
        //for each power of 10 value; create ten ticks
        for (int j = 0; j < 10; ++j) {
            //for each tick to be displayed
            if (this.smallLogFlag) {
                //small log values in use; create numeric value for tick
                currentTickValue = Math.pow(10, i) + (Math.pow(10, i) * j);
                if (this.expTickLabelsFlag || (i < 0 && currentTickValue > 0.0 && currentTickValue < 1.0)) {
                    //showing "1e#"-style ticks or negative exponent
                    // generating tick value between 0 & 1; show fewer
                    //first tick of series, or not too small a value and
                    // one of first 3 ticks, or last tick to be displayed
                    // set exact number of fractional digits to be shown
                    // (no effect if showing "1e#"-style ticks):
                    this.numberFormatterObj.setMaximumFractionDigits(-i);
                    //create tick label (force use of fmt obj):
                    tickLabel = makeTickLabel(currentTickValue, true);
                } else { //tick value not between 0 & 1
                         //show tick label if it's the first or last in
                         // the set, or if it's 1-5; beyond that show
                         // fewer as the values get larger:
                    tickLabel = makeTickLabel(currentTickValue);
                }
            } else { //not small log values in use; allow for values <= 0
                if (zeroTickFlag) { //if did zero tick last iter then
                    --j; //decrement to do 1.0 tick now
                } //calculate power-of-ten value for tick:
                currentTickValue = (i >= 0) ? Math.pow(10, i) + (Math.pow(10, i) * j)
                        : -(Math.pow(10, -i) - (Math.pow(10, -i - 1) * j));
                if (!zeroTickFlag) { // did not do zero tick last iteration
                    if (Math.abs(currentTickValue - 1.0) < 0.0001 && lowerBoundVal <= 0.0
                            && upperBoundVal >= 0.0) {
                        //tick value is 1.0 and 0.0 is within data range
                        currentTickValue = 0.0; //set tick value to zero
                        zeroTickFlag = true; //indicate zero tick
                    }
                } else { //did zero tick last iteration
                    zeroTickFlag = false; //clear flag
                } //create tick label string:
                //show tick label if "1e#"-style and it's one
                // of the first two, if it's the first or last
                // in the set, or if it's 1-5; beyond that
                // show fewer as the values get larger:
                tickLabel = makeTickLabel(currentTickValue);
            }

            if (currentTickValue > upperBoundVal) {
                if (lastTick != null) {
                    String lastTickText = lastTick.getText();
                    if (lastTickText == null || lastTickText.trim().length() == 0) {
                        ticks.remove(lastTick);
                        ticks.add(new NumberTick(lastTick.getValue(),
                                createTickLabel(lastTick.getValue(), i - 1), lastTick.getTextAnchor(),
                                lastTick.getRotationAnchor(), lastTick.getAngle()));
                    }
                }
                if (ticks.size() < 2) {
                    double definition = Math.abs(lowerBoundVal - upperBoundVal);
                    int numberOfDigits = 0;
                    if (definition >= 1)
                        numberOfDigits = 0;
                    else {
                        numberOfDigits = (int) Math.ceil((-Math.log10(definition)));
                    }
                    if (definition < 2 * Math.pow(10, -numberOfDigits)) {
                        numberOfDigits++;
                    }
                    double tickVal;
                    tickVal = lowerBoundVal;
                    if (definition > 1)
                        tickLabel = Long.toString((long) Math.rint(tickVal));
                    else
                        tickLabel = (new Formatter()).format("%." + numberOfDigits + "f", tickVal).toString();
                    ticks.add(new NumberTick(new Double(tickVal), tickLabel, TextAnchor.TOP_CENTER,
                            TextAnchor.TOP_CENTER, 0.0));
                    tickVal = upperBoundVal;
                    if (definition > 1) {
                        tickLabel = Long.toString((long) Math.rint(tickVal));
                    } else {
                        tickLabel = (new Formatter()).format("%." + numberOfDigits + "f", tickVal).toString();
                    }
                    ticks.add(new NumberTick(new Double(tickVal), tickLabel, TextAnchor.TOP_CENTER,
                            TextAnchor.TOP_CENTER, 0.0));
                }
                return ticks; // if past highest data value then exit
                              // method
            }

            if (currentTickValue >= lowerBoundVal - SMALL_LOG_VALUE) {
                //tick value not below lowest data value
                TextAnchor anchor = null;
                TextAnchor rotationAnchor = null;
                double angle = 0.0;
                if (isVerticalTickLabels()) {
                    anchor = TextAnchor.CENTER_RIGHT;
                    rotationAnchor = TextAnchor.CENTER_RIGHT;
                    if (edge == RectangleEdge.TOP) {
                        angle = Math.PI / 2.0;
                    } else {
                        angle = -Math.PI / 2.0;
                    }
                } else {
                    if (edge == RectangleEdge.TOP) {
                        anchor = TextAnchor.BOTTOM_CENTER;
                        rotationAnchor = TextAnchor.BOTTOM_CENTER;
                    } else {
                        anchor = TextAnchor.TOP_CENTER;
                        rotationAnchor = TextAnchor.TOP_CENTER;
                    }
                }

                lastTick = new NumberTick(new Double(currentTickValue), tickLabel, anchor, rotationAnchor,
                        angle);
                ticks.add(lastTick);
                if (tickLabel != null && tickLabel.trim().length() > 0)
                    numberOfTicks++;
                numberOfGrids++;
            }
        }
    }
    if (ticks.size() < 2) {
        double definition = Math.abs(lowerBoundVal - upperBoundVal);
        int numberOfDigits = 0;
        if (definition >= 1)
            numberOfDigits = 0;
        else {
            numberOfDigits = (int) Math.ceil((-Math.log10(definition)));
        }
        double tickVal;
        tickVal = lowerBoundVal;
        if (definition > 1)
            tickLabel = Long.toString((long) Math.rint(tickVal));
        else
            tickLabel = (new Formatter()).format("%." + numberOfDigits + "f", tickVal).toString();
        ticks.add(new NumberTick(new Double(tickVal), tickLabel, TextAnchor.TOP_CENTER, TextAnchor.TOP_CENTER,
                0.0));
        tickVal = upperBoundVal;
        if (definition > 1)
            tickLabel = Long.toString((long) Math.rint(tickVal));
        else
            tickLabel = (new Formatter()).format("%." + numberOfDigits + "f", tickVal).toString();
        ticks.add(new NumberTick(new Double(tickVal), tickLabel, TextAnchor.TOP_CENTER, TextAnchor.TOP_CENTER,
                0.0));
    }
    return ticks;
}

From source file:org.esa.nest.gpf.ERSCalibrator.java

/**
 * Compute ADC power loss value for given pixel value using LUT in Appendix F1 or F2.
 *
 * @param dn    The pixel value/*  w w w  . j av  a 2s . c om*/
 * @param array 2-D array holding ADC power loss value data given in Appendix F1 or F2
 * @return The ADC power loss value (in linear scale)
 */
private static double getPowerLossValue(final double dn, final double[][] array) {

    final int numRows = array.length;
    final int numCols = array[0].length;
    if (numCols != 2) {
        throw new OperatorException("Incorrect array dimension");
    }

    double dnInDb;
    if (dn < underFlowFloat) {
        return -underFlowFloat;
    } else {
        dnInDb = 10.0 * Math.log10(dn);
    }

    int row1 = 0;
    int row2 = 0;
    if (dnInDb < array[0][0]) {
        row1 = 0;
        row2 = 1;
    } else if (dnInDb > array[numRows - 1][0]) {
        row1 = numRows - 2;
        row2 = numRows - 1;
    } else {
        for (int i = 1; i < numRows; i++) {
            if (dnInDb < array[i][0]) {
                row1 = i - 1;
                row2 = i;
                break;
            }
        }
    }

    final double intensityK1 = array[row1][0];
    final double intensityK2 = array[row2][0];
    final double loss1 = array[row1][1];
    final double loss2 = array[row2][1];
    final double lambda = (dnInDb - intensityK1) / (intensityK2 - intensityK1);
    double loss = (1 - lambda) * loss1 + lambda * loss2;
    loss = Math.pow(10.0, loss / 10.0); // dB to linear scale

    return loss;
}