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.apache.calcite.runtime.SqlFunctions.java

/** SQL {@code LOG10(number)} function applied to long values. */
public static double log10(long b0) {
    return Math.log10(b0);
}

From source file:org.apache.calcite.runtime.SqlFunctions.java

/** SQL {@code LOG10(number)} function applied to BigDecimal values. */
public static double log10(BigDecimal d) {
    return Math.log10(d.doubleValue());
}

From source file:org.jax.maanova.test.gui.VolcanoPlotPanel.java

/**
 * Creates volcano plot data points from a JFreeChart {@link XYDataset}
 * from the given test statistics./*from www  .  j  av a  2 s  .  c  o  m*/
 * @param plotIndex
 *          the index of test that we want data points for
 * @param testStatistics
 *          the test statistics to extract from
 * @param testStatisticSubtype
 *          the subtype to extract from
 * @return
 *          the XY points for the volcano plot
 */
private XYProbeData createXYData(int plotIndex, MaanovaTestStatistics testStatistics,
        MaanovaTestStatisticSubtype testStatisticSubtype) {
    Double[] objXValues = this.maanovaTestResult.getFoldChangeValues(plotIndex);
    Double[] objYValues = testStatistics.getValues(testStatisticSubtype, plotIndex);

    // check the array lengths which should be the same if everything is OK
    if (objXValues.length != objYValues.length) {
        throw new IllegalArgumentException("There is a missmatch between the number of X (" + objXValues.length
                + ") and Y (" + objYValues.length + ") values");
    }

    // first count all non-null pairings
    int nonNullCount = 0;
    for (int i = 0; i < objXValues.length; i++) {
        if (objXValues[i] != null && objYValues[i] != null) {
            nonNullCount++;
        }
    }

    if (nonNullCount != objXValues.length && LOG.isLoggable(Level.WARNING)) {
        LOG.warning(
                "Found " + (objXValues.length - nonNullCount) + " NaN data points in the volcano plot data");
    }

    // OK, now convert to primitive arrays
    double[] primXValues = new double[nonNullCount];
    double[] primYValues = new double[nonNullCount];
    int[] probeIndices = new int[nonNullCount];
    int primitiveArraysIndex = 0;
    for (int objArraysIndex = 0; objArraysIndex < objXValues.length; objArraysIndex++) {
        if (objXValues[objArraysIndex] != null && objYValues[objArraysIndex] != null) {
            double yVal = objYValues[objArraysIndex];
            if (yVal < MIN_PVALUE_THRESHOLD) {
                yVal = MIN_PVALUE_THRESHOLD;
            }
            primXValues[primitiveArraysIndex] = objXValues[objArraysIndex];
            primYValues[primitiveArraysIndex] = -Math.log10(yVal);
            probeIndices[primitiveArraysIndex] = objArraysIndex;

            primitiveArraysIndex++;
        }
    }

    return new XYProbeData(primXValues, primYValues, probeIndices);
}

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

@Test(enabled = true && !DEBUG_ONLY, dataProvider = "PNonRef")
private void testPNonRef(final VariantContext vcRoot, AFCalcFactory.Calculation modelType,
        AFCalcTestBuilder.PriorType priorType, final List<Genotype> genotypes, final double expectedPNonRef,
        final double tolerance, final int nNonInformative) {
    final AFCalcTestBuilder testBuilder = new AFCalcTestBuilder(1, vcRoot.getNAlleles() - 1, modelType,
            priorType);//  ww  w. j  av  a 2  s  .c  o  m

    final VariantContextBuilder vcb = new VariantContextBuilder(vcRoot);
    vcb.genotypes(genotypes);

    final AFCalcResult resultTracker = testBuilder.makeModel().getLog10PNonRef(vcb.make(),
            testBuilder.makePriors());

    Assert.assertEquals(resultTracker.getLog10PosteriorOfAFGT0(), Math.log10(expectedPNonRef), tolerance,
            "Actual pNonRef not within tolerance " + tolerance + " of expected");
}

From source file:Model.MultiPlatformLDA.java

private double getPostLikelihood(int u, int j) {
    // compute likelihood of post number j of user number u

    // content/* w  w  w  . j  a va  2 s.  co m*/
    double content_LogLikelihood = 0;
    for (int i = 0; i < users[u].posts[j].words.length; i++) {
        int w = users[u].posts[j].words[i];
        // probability that word i is generated by background topic
        double p_0 = backgroundTopic[w] * coinBias[0];
        // probability that word i is generated by other topics
        double p_1 = 0;
        for (int z = 0; z < nTopics; z++) {
            double p_z = topics[z][w] * users[u].topicDistribution[z];
            p_1 = p_1 + p_z;
        }
        p_1 = p_1 * coinBias[1];
        content_LogLikelihood += Math.log10(p_0 + p_1);
    }
    // platform
    int p = users[u].posts[j].platform;
    double p_Platform = 0;
    for (int z = 0; z < nTopics; z++) {
        if (modelType == ModelType.USER_SPECIFIC) {
            p_Platform += users[u].topicDistribution[z] * users[u].topicPlatformDistribution[z][p];
        } else {
            p_Platform += users[u].topicDistribution[z] * globalTopicPlatformDistribution[z][p];
        }
    }

    return content_LogLikelihood + Math.log10(p_Platform);
}

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

private double getFilteredValue(int tx, int ty, Tile sourceRaster1, Tile sourceRaster2,
        Unit.UnitType bandUnitType) {/*from  w w w  .  ja  v a2s  .  c  o m*/

    final int x0 = (int) (tx * stepRange + 0.5);
    final int y0 = (int) (ty * stepAzimuth + 0.5);
    final int maxY = y0 + filterHeight;
    final int maxX = x0 + filterWidth;

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

    float numPixels = filterWidth * filterHeight;
    double filteredValue = 0.0;
    for (int y = y0; y < maxY; y++) {
        for (int x = x0; x < maxX; x++) {

            final int index = sourceRaster1.getDataBufferIndex(x, y);
            final float weight = kernel[maxY - 1 - y][maxX - 1 - x] / numPixels;

            if (bandUnitType == Unit.UnitType.INTENSITY_DB || bandUnitType == Unit.UnitType.AMPLITUDE_DB) {

                final double dn = srcData1.getElemDoubleAt(index);
                filteredValue += FastMath.pow(10, dn / 10.0) * weight; // dB to linear

            } else if (sourceRaster2 == null) {

                filteredValue += srcData1.getElemDoubleAt(index) * weight;

            } else { // COMPLEX

                final double i = srcData1.getElemDoubleAt(index);
                final double q = srcData2.getElemDoubleAt(index);
                filteredValue += (i * i + q * q) * weight;
            }
        }
    }

    if (bandUnitType == Unit.UnitType.INTENSITY_DB || bandUnitType == Unit.UnitType.AMPLITUDE_DB) {
        filteredValue = 10.0 * Math.log10(filteredValue); // linear to dB
    }
    return filteredValue;
}

From source file:fastcall.FastCallSNP.java

public String getGenotype(int[] cnt) {
    int n = cnt.length * (cnt.length + 1) / 2;
    int[] likelihood = new int[n];
    int sum = 0;//from w w  w.  j  a v a  2  s . co m
    for (int i = 0; i < cnt.length; i++)
        sum += cnt[i];
    if (sum == 0)
        return "./.";
    else if (sum > this.maxFactorial) {
        double portion = (double) this.maxFactorial / sum;
        for (int i = 0; i < cnt.length; i++) {
            cnt[i] = (int) (cnt[i] * portion);
        }
        sum = this.maxFactorial;
    }
    double coe = this.factorialMap.get(sum);
    for (int i = 0; i < cnt.length; i++)
        coe = coe / this.factorialMap.get(cnt[i]);
    double max = Double.MAX_VALUE;
    int a1 = 0;
    int a2 = 0;
    for (int i = 0; i < cnt.length; i++) {
        for (int j = i; j < cnt.length; j++) {
            int index = (j * (j + 1) / 2) + i;
            double value = Double.MAX_VALUE;
            if (i == j) {
                value = -Math.log10(coe * Math.pow((1 - 0.75 * this.sequencingErrorRate), cnt[i])
                        * Math.pow(this.sequencingErrorRate / 4, (sum - cnt[i])));
            } else {
                value = -Math.log10(coe * Math.pow((0.5 - this.sequencingErrorRate / 4), cnt[i] + cnt[j])
                        * Math.pow(this.sequencingErrorRate / 4, (sum - cnt[i] - cnt[j])));
            }
            if (value < max) {
                max = value;
                a1 = i;
                a2 = j;
            }
            likelihood[index] = (int) Math.round(value);
        }
    }
    StringBuilder sb = new StringBuilder();
    sb.append(a1).append("/").append(a2).append(":");
    for (int i = 0; i < cnt.length; i++)
        sb.append(cnt[i]).append(",");
    sb.deleteCharAt(sb.length() - 1);
    sb.append(":");
    for (int i = 0; i < likelihood.length; i++)
        sb.append(likelihood[i]).append(",");
    sb.deleteCharAt(sb.length() - 1);
    return sb.toString();
}

From source file:spectrogram.Spectrogram.java

/**
 * Put the created raster into the image, label the axis and generally make it look pretty and write it out.
 * /*from  w ww.  j  a v  a2s  .com*/
 * @throws IOException probably image write failed
 */
private void finalizeImage() throws IOException {
    img.setData(rast);
    grph.setFont(lblFont);
    // add the axis labels
    int lasc = labelMetrics.getAscent();
    int imgXmax = imgX0 + dimX;

    // label the X-axis of plot
    if (xTicks == 0) {
        // @todo make an intelligent choice
        xTicks = 11;
    }
    double tw = (double) dimX / (xTicks - 1);
    double dt = secPerFFT * (1 - overlap) * spectraCache.size() / ((float) xTicks - 1);
    String fmt = "%1$.0f";
    if (duration < xTicks) {
        fmt = "%1$.2f";
    } else if (duration < xTicks * 2) {
        fmt = "%1$.1f";
    }
    int y = (int) (pltRect.getY() + pltRect.getHeight() + 5);
    int yp = y + 5 + lasc;
    int gpsyp = (int) (yp + lblHeight * 1.2);
    int lastGpsPos = 0; // too see if it fits nicely
    for (int t = 0; t < xTicks; t++) {
        int x = (int) (t * tw + imgX0);
        long tsec = Math.round(t * dt);
        String xLbl;
        if (duration > 1000) {
            xLbl = TimeAndDate.hrTime(tsec, true);
        } else {
            xLbl = String.format(fmt, t * dt);
        }
        int xw = labelMetrics.stringWidth(xLbl);
        int xp = x - xw / 2;
        if (t == xTicks) { // make sure the last tick is at the edge (round off errors)
                           // and the label ends there since we can't center it
            x = imgXmax;
            xp = x - xw;
        }

        grph.drawLine(x, imgY0, x, y);
        grph.drawString(xLbl, xp, yp);

        // add the gps time for this tick if it fits
        String gpsStr = String.format("%1$,d", (int) (startGPS + t * dt));
        int gpsWdt = labelMetrics.stringWidth(gpsStr);
        int gpsPos = x - gpsWdt / 2;

        if (gpsPos > lastGpsPos + em * 2) {
            grph.drawString(gpsStr, gpsPos, gpsyp);
            lastGpsPos = gpsPos + gpsWdt;
        }
    }
    // label the Y-axis
    if (yTicks == 0) {
        // @todo make a more intelligent choice
        yTicks = 11;
    }
    int xps = imgX0 - 3;
    int xpe = imgX0 + dimX;
    float bw = 1.f / secPerFFT;

    // get the actual frequency range
    fmin = spectraCache.getSmin();
    fmax = spectraCache.getSmax();

    if (logFreq) {
        double mxexp = Math.log10(fmax - fmin);
        double mnexp;
        if (fmin > 0) {
            mnexp = Math.log10(fmin);
        } else {
            fmin = bw;
            mnexp = Math.log10(bw);
        }

        double val = 0;
        double lastLabel = 0;
        for (int ex = (int) Math.floor(mnexp); val < fmax; ex++) {
            double exp;
            if (mnexp < mxexp) {
                exp = Math.pow(10, ex);
            } else {
                exp = Math.pow(10, ex - 1);
            }
            for (int s = 1; s < 10; s++) {
                val = s * exp;
                if (mnexp == mxexp) {
                    val += Math.pow(10, mnexp);
                }
                if (val >= fmin && val <= fmax) {
                    drawGrid(mxexp, val);
                    if (s == 1 || s == 2 || s == 5) {
                        labelYTick(mxexp, val);
                        lastLabel = val;
                    }
                }
            }
        }
        // mark the max value if it's not too close to the last label
        if ((fmax - lastLabel) / fmax > .15) {
            labelYTick(mxexp, (int) fmax);
        }
    } else {
        double yfact = (fmax - fmin) / yTicks;
        double ypf = ((double) dimY) / yTicks;

        for (int yt = 0; yt <= yTicks; yt++) {
            double yv = yt * yfact + fmin;
            int ytp = (int) (dimY - Math.round(yt * ypf) + imgY0);
            grph.drawLine(xps, ytp, xpe, ytp);
            String fstr = String.format("%1$,.0f", yv);
            int fstrLen = labelMetrics.stringWidth(fstr);
            int fsp = xps - fstrLen - 2;
            grph.drawString(fstr, fsp, ytp + lblHeight / 2);
        }
    }

    // add the aux info line at the bottom
    int imgCenter = (imgXmax - imgX0) / 2;
    String auxInfo = getAuxInfo();

    int xw = labelMetrics.stringWidth(auxInfo);
    int xp = imgCenter - xw / 2 + imgX0;
    int auxyp = (int) (outY - lblHeight * 1.5);

    grph.drawString(auxInfo, xp, auxyp + lblHeight + 3);

    // label the color scale
    labelColorMapTics();

    // write the file
    File outputfile = new File(ofileName);
    ImageIO.write(img, "png", outputfile);
    System.out.println("Wrote: " + ofileName);
}

From source file:eu.crisis_economics.abm.fund.FundTest.java

public void testLongTermNetWithdrawal() {
    /*//from  ww  w  .j a  va 2s. com
     * Test parameters
     */
    final int numberOfBusinessCycles = 1000;
    final double periodicFundProfit = 1.e7, fundInitialDeposits = 0.,
            householdInitialDeposits = 1.e8 / myHouseholds.length,
            periodicHouseholdWithdrawal = .7 * periodicFundProfit / myHouseholds.length;

    myFund = new MutualFund(myBank, new HomogeneousPortfolioWeighting(),
            new FundamentalistStockReturnExpectationFunction(), clearingHouse, new NoSmoothingAlgorithm()); // Fresh fund

    myFund.debit(fundInitialDeposits);
    final Contract exogenousReturns = myFund.mDepositor.depositAccount;
    for (int i = 0; i < myHouseholds.length; ++i) {
        myHouseholds[i] = new HouseholdStub(myFund, myBank, householdInitialDeposits);
        try {
            myFund.invest(myHouseholds[i], householdInitialDeposits * .9);
        } catch (final InsufficientFundsException unexpectedException) {
            Assert.fail();
        }
    }

    double totalFundProfits = 0.;
    for (int i = 0; i < numberOfBusinessCycles; ++i) {
        for (int j = 0; j < myHouseholds.length; ++j) {
            try {
                myFund.requestWithdrawal(myHouseholds[j], periodicHouseholdWithdrawal);
            } catch (final InsufficientFundsException unexpectedException) {
                Assert.fail();
            }
        }
        myFund.preClearingProcessing();
        exogenousReturns.setValue(exogenousReturns.getValue() + periodicFundProfit);
        totalFundProfits += periodicFundProfit;
        try {
            myFund.postClearingProcessing();
        } catch (final InsufficientFundsException unexpectedException) {
            Assert.fail();
        }

        System.out.printf("MutualFund profits:     %16.10g\n", periodicFundProfit);
        System.out.printf("MutualFund assets:      %16.10g\n", myFund.getTotalAssets());
        System.out.printf("MutualFund liabilities: %16.10g\n", myFund.getTotalLiabilities());
        System.out.printf("MutualFund equity:      %16.10g\n", myFund.getEquity());

        System.out.println("Number of shares: " + myFund.mInvestmentAccount.getNumberOfEmittedShares());

        // Assertions
        final double postClearingEquity = myFund.getEquity();
        Assert.assertEquals(postClearingEquity, fundInitialDeposits, 1.e-1);

        continue;
    }

    // Tally the total amount of cash in the system.
    double totalHouseholdProfits = 0.;
    System.out.printf("household  deposits [open]  fund investments [open]"
            + "  deposits [close] fund investments [close] sum [close]\n");
    for (int i = 0; i < N_HOUSEHOLDS; ++i) { // Assert no money creation
        final double closingHouseholdDeposits = myHouseholds[i].bankAccount.getBalance(),
                closingFundAccountValue = myFund.getBalance(myHouseholds[i]);
        System.out.printf("%5d %16.10g %16.10g         %16.10g %16.10g         %16.10g\n", i,
                householdInitialDeposits, 0., closingHouseholdDeposits, closingFundAccountValue,
                closingHouseholdDeposits + closingFundAccountValue);
        totalHouseholdProfits += (closingHouseholdDeposits + closingFundAccountValue)
                - householdInitialDeposits;
    }

    System.out.printf("Aggregate household profits: %16.10g. MutualFund profits: %16.10g\n",
            totalHouseholdProfits, totalFundProfits);
    Assert.assertEquals(totalHouseholdProfits / Math.pow(10., (int) Math.log10(totalHouseholdProfits)),
            totalFundProfits / Math.pow(10., (int) Math.log10(totalFundProfits)), 1.e-12);
    Assert.assertTrue(myFund.mInvestmentAccount.numberOfEmittedShares > 1.);

    return;
}

From source file:Model.MultiPlatformLDA.java

private double getPostLikelihood(int u, int j, int z) {
    // Compute likelihood of post number j of user number u given the topic
    // z//from w ww.  j  a  v  a 2 s . c om
    if (z >= 0) {
        double content_logLikelihood = 0;
        for (int i = 0; i < users[u].posts[j].words.length; i++) {
            int w = users[u].posts[j].words[i];
            // Probability that word i is generated by background topic
            double p_0 = backgroundTopic[w] * coinBias[0];
            // Probability that word i is generated by topic z
            double p_1 = topics[z][w] * coinBias[1];
            content_logLikelihood += Math.log10(p_0 + p_1);
        }
        double platform_logLikelihood = 0;
        int p = users[u].posts[j].platform;
        if (modelType == ModelType.USER_SPECIFIC) {
            platform_logLikelihood = Math.log10(users[u].topicPlatformDistribution[z][p]);
        } else {
            platform_logLikelihood = Math.log10(globalTopicPlatformDistribution[z][p]);
        }

        return (content_logLikelihood + platform_logLikelihood);
    } else {// background topic only
        double content_logLikelihood = 0;
        for (int i = 0; i < users[u].posts[j].words.length; i++) {
            int w = users[u].posts[j].words[i];
            // Probability that word i is generated by background topic
            double p_0 = backgroundTopic[w];
            content_logLikelihood = content_logLikelihood + Math.log10(p_0);
        }
        double platform_logLikelihood = Math.log10(1.0 / nPlatforms);// random
        return (content_logLikelihood + platform_logLikelihood);
    }
}