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.canova.api.util.MathUtils.java

/**
 * Term frequency: 1+ log10(count)//from w ww . ja  va 2s  . com
 *
 * @param count the count of a word or character in a given string or document
 * @return 1+ log(10) count
 */
public static double tf(int count) {
    return count > 0 ? 1 + Math.log10(count) : 0;
}

From source file:main.java.utils.Utility.java

public static int rightPadding(int id, int value) {
    return ((int) Math.pow(10, Math.floor(Math.log10(value)) + 1) * id + value);
}

From source file:SDRecord.java

private static String formatSize(long v) {
    if (v <= 0)
        return "0";
    final String[] units = new String[] { "B", "KB", "MB", "GB", "TB", "PB", "EB" };
    int digitGroups = (int) (Math.log10(v) / Math.log10(1000));
    return new DecimalFormat("#,##0.00").format(v / Math.pow(1000, digitGroups)) + " " + units[digitGroups];
}

From source file:org.jax.bham.test.MultiHaplotypeBlockTestGraphPanel.java

private void cacheChromosomeTests(final int[] chromosomes) {
    List<Integer> chromosomesToCalculate = SequenceUtilities.toIntegerList(chromosomes);
    chromosomesToCalculate.removeAll(this.chromosomeToNegLogValueMap.keySet());

    PerformSlidingWindowAssociationTestTask testTask = new PerformSlidingWindowAssociationTestTask(
            this.testToPlot, chromosomesToCalculate);
    MultiTaskProgressPanel progressTracker = BhamApplication.getInstance().getBhamFrame()
            .getMultiTaskProgress();/*from  ww w . ja  va 2 s.  c  o m*/
    progressTracker.addTaskToTrack(testTask, true);

    while (testTask.hasMoreElements()) {
        int nextChromosome = testTask.getNextChromosome();
        MultiHaplotypeBlockTestResult[] results = testTask.nextElement();

        List<MultiHaplotypeBlockTestResult> filteredResults = OcclusionFilter
                .filterOutOccludedIntervals(Arrays.asList(results), true);

        RealValuedBasePairInterval[] negLogResults = new RealValuedBasePairInterval[filteredResults.size()];
        for (int i = 0; i < negLogResults.length; i++) {
            negLogResults[i] = new CompositeRealValuedBasePairInterval(
                    filteredResults.get(i).getDelegateInterval(),
                    -Math.log10(filteredResults.get(i).getPValue()));
        }

        this.chromosomeToNegLogValueMap.put(nextChromosome, negLogResults);
    }
}

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

/**
 * Called by the framework in order to compute a tile for the given target band.
 * <p>The default implementation throws a runtime exception with the message "not implemented".</p>
 *
 * @param targetBand The target band.//from w  w w.  j a v a 2 s .  c o  m
 * @param targetTile The current tile associated with the target band to be computed.
 * @param pm         A progress monitor which should be used to determine computation cancelation requests.
 * @throws org.esa.beam.framework.gpf.OperatorException If an error occurs during computation of the target raster.
 */
public void computeTile(Band targetBand, Tile targetTile, ProgressMonitor pm) throws OperatorException {

    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;

    Tile sourceRaster1 = null;
    ProductData srcData1 = null;
    ProductData srcData2 = null;
    Band sourceBand1 = null;

    final String[] srcBandNames = targetBandNameToSourceBandName.get(targetBand.getName());
    if (srcBandNames.length == 1) {
        sourceBand1 = sourceProduct.getBand(srcBandNames[0]);
        sourceRaster1 = calibrationOp.getSourceTile(sourceBand1, targetTileRectangle);
        srcData1 = sourceRaster1.getDataBuffer();
    } else {
        sourceBand1 = sourceProduct.getBand(srcBandNames[0]);
        final Band sourceBand2 = sourceProduct.getBand(srcBandNames[1]);
        sourceRaster1 = calibrationOp.getSourceTile(sourceBand1, targetTileRectangle);
        final Tile sourceRaster2 = calibrationOp.getSourceTile(sourceBand2, targetTileRectangle);
        srcData1 = sourceRaster1.getDataBuffer();
        srcData2 = sourceRaster2.getDataBuffer();
    }

    final Unit.UnitType bandUnit = Unit.getUnitType(sourceBand1);

    // copy band if unit is phase
    if (bandUnit == Unit.UnitType.PHASE) {
        targetTile.setRawSamples(sourceRaster1.getRawSamples());
        return;
    }

    final ProductData trgData = targetTile.getDataBuffer();
    final TileIndex srcIndex = new TileIndex(sourceRaster1);
    final TileIndex tgtIndex = new TileIndex(targetTile);

    final int maxY = y0 + h;
    final int maxX = x0 + w;

    double dn = 0, dn2 = 0, sigma, i, q;
    int srcIdx, tgtIdx;

    for (int y = y0; y < maxY; ++y) {
        srcIndex.calculateStride(y);
        tgtIndex.calculateStride(y);

        for (int x = x0; x < maxX; ++x) {
            srcIdx = srcIndex.getIndex(x);
            tgtIdx = tgtIndex.getIndex(x);

            if (bandUnit == Unit.UnitType.AMPLITUDE) {
                dn = srcData1.getElemDoubleAt(srcIdx);
                dn2 = dn * dn;
            } else if (bandUnit == Unit.UnitType.INTENSITY) {
                dn2 = srcData1.getElemDoubleAt(srcIdx);
            } else if (bandUnit == Unit.UnitType.REAL || bandUnit == Unit.UnitType.IMAGINARY) {
                if (outputImageInComplex) {
                    dn = srcData1.getElemDoubleAt(srcIdx);
                } else {
                    i = srcData1.getElemDoubleAt(srcIdx);
                    q = srcData2.getElemDoubleAt(srcIdx);
                    dn2 = i * i + q * q;
                }
            } else {
                throw new OperatorException("ALOS Calibration: unhandled unit");
            }

            if (isComplex && outputImageInComplex) {
                sigma = dn * Math.sqrt(calibrationFactor);
            } else {
                sigma = dn2 * calibrationFactor;
            }

            if (outputImageScaleInDb) { // convert calibration result to dB
                if (sigma < underFlowFloat) {
                    sigma = -underFlowFloat;
                } else {
                    sigma = 10.0 * Math.log10(sigma);
                }
            }

            trgData.setElemDoubleAt(tgtIdx, sigma);
        }
    }
}

From source file:com.bhbsoft.videoconference.record.convert.util.FlvFileHelper.java

public static String getHumanSize(long size) {
    if (size <= 0)
        return "0";
    final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" };
    int digitGroups = (int) (Math.log10(size) / Math.log10(1024));
    return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups];
}

From source file:asl.util.PlotMaker2.java

public void writePlot(String fileName) {
    //System.out.format("== plotTitle=[%s] fileName=[%s]\n", plotTitle, fileName);

    File outputFile = new File(fileName);

    // Check that we will be able to output the file without problems and if not --> return
    if (!checkFileOut(outputFile)) {
        System.out.format("== plotMaker: request to output plot=[%s] but we are unable to create it "
                + " --> skip plot\n", fileName);
        return;/*from   w  w w.  ja  v  a 2 s  . c  o  m*/
    }

    NumberAxis horizontalAxis = new NumberAxis("x-axis default"); // x = domain

    if (fileName.contains("nlnm") || fileName.contains("coher") || fileName.contains("stn")) { // NLNM or StationDeviation 
        horizontalAxis = new LogarithmicAxis("Period (sec)");
        horizontalAxis.setRange(new Range(1, 11000));
        horizontalAxis.setTickUnit(new NumberTickUnit(5.0));
    } else { // EventCompareSynthetics/StrongMotion
        horizontalAxis = new NumberAxis("Time (s)");
        double x[] = panels.get(0).getTraces().get(0).getxData();
        horizontalAxis.setRange(new Range(x[0], x[x.length - 1]));
    }

    CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(horizontalAxis);
    combinedPlot.setGap(15.);

    // Loop over (3) panels for this plot:

    for (Panel panel : panels) {

        NumberAxis verticalAxis = new NumberAxis("y-axis default"); // y = range

        if (fileName.contains("nlnm") || fileName.contains("stn")) { // NLNM or StationDeviation 
            verticalAxis = new NumberAxis("PSD 10log10(m**2/s**4)/Hz dB");
            verticalAxis.setRange(new Range(-190, -95));
            verticalAxis.setTickUnit(new NumberTickUnit(5.0));
        } else if (fileName.contains("coher")) { // Coherence
            verticalAxis = new NumberAxis("Coherence, Gamma");
            verticalAxis.setRange(new Range(0, 1.2));
            verticalAxis.setTickUnit(new NumberTickUnit(0.1));
        } else { // EventCompareSynthetics/StrongMotion
            verticalAxis = new NumberAxis("Displacement (m)");
        }

        Font fontPlain = new Font("Verdana", Font.PLAIN, 14);
        Font fontBold = new Font("Verdana", Font.BOLD, 18);
        verticalAxis.setLabelFont(fontBold);
        verticalAxis.setTickLabelFont(fontPlain);
        horizontalAxis.setLabelFont(fontBold);
        horizontalAxis.setTickLabelFont(fontPlain);

        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        XYPlot xyplot = new XYPlot((XYDataset) seriesCollection, horizontalAxis, verticalAxis, renderer);
        xyplot.setDomainGridlinesVisible(true);
        xyplot.setRangeGridlinesVisible(true);
        xyplot.setRangeGridlinePaint(Color.black);
        xyplot.setDomainGridlinePaint(Color.black);

        // Plot each trace on this panel:
        int iTrace = 0;
        for (Trace trace : panel.getTraces()) {

            XYSeries series = new XYSeries(trace.getName());

            double xdata[] = trace.getxData();
            double ydata[] = trace.getyData();
            for (int k = 0; k < xdata.length; k++) {
                series.add(xdata[k], ydata[k]);
            }

            renderer.setSeriesPaint(iTrace, trace.getColor());
            renderer.setSeriesStroke(iTrace, trace.getStroke());
            renderer.setSeriesLinesVisible(iTrace, true);
            renderer.setSeriesShapesVisible(iTrace, false);

            seriesCollection.addSeries(series);

            iTrace++;
        }

        // Add Annotations for each trace - This is done in a separate loop so that
        //                      the upper/lower limits for this panel will be known
        double xmin = horizontalAxis.getRange().getLowerBound();
        double xmax = horizontalAxis.getRange().getUpperBound();
        double ymin = verticalAxis.getRange().getLowerBound();
        double ymax = verticalAxis.getRange().getUpperBound();
        double delX = Math.abs(xmax - xmin);
        double delY = Math.abs(ymax - ymin);

        // Annotation (x,y) in normalized units - where upper-right corner = (1,1)
        double xAnn = 0.97; // Right center coords of the trace name (e.g., "00-LHZ")
        double yAnn = 0.95;

        double yOff = 0.05; // Vertical distance between different trace legends

        iTrace = 0;
        for (Trace trace : panel.getTraces()) {
            if (!trace.getName().contains("NLNM") && !trace.getName().contains("NHNM")) {
                // x1 > x2 > x3, e.g.:
                //  o-------o   00-LHZ
                //  x3     x2       x1

                double scale = .01; // Controls distance between trace label and line segment
                double xL = .04; // Length of trace line segment in legend

                double xAnn2 = xAnn - scale * trace.getName().length();
                double xAnn3 = xAnn - scale * trace.getName().length() - xL;

                double x1 = xAnn * delX + xmin; // Right hand x-coord of text in range units
                double x2 = xAnn2 * delX + xmin; // x-coord of line segment end in range units
                double x3 = xAnn3 * delX + xmin; // x-coord of line segment end in range units

                double y = (yAnn - (iTrace * yOff)) * delY + ymin;

                if (horizontalAxis instanceof LogarithmicAxis) {
                    double logMin = Math.log10(xmin);
                    double logMax = Math.log10(xmax);
                    delX = logMax - logMin;
                    x1 = Math.pow(10, xAnn * delX + logMin);
                    x2 = Math.pow(10, xAnn2 * delX + logMin);
                    x3 = Math.pow(10, xAnn3 * delX + logMin);
                }
                xyplot.addAnnotation(new XYLineAnnotation(x3, y, x2, y, trace.getStroke(), trace.getColor()));
                XYTextAnnotation xyText = new XYTextAnnotation(trace.getName(), x1, y);
                xyText.setFont(new Font("Verdana", Font.BOLD, 18));
                xyText.setTextAnchor(TextAnchor.CENTER_RIGHT);
                xyplot.addAnnotation(xyText);
            }
            iTrace++;
        }

        combinedPlot.add(xyplot, 1);

    } // panel

    final JFreeChart chart = new JFreeChart(combinedPlot);
    chart.setTitle(new TextTitle(plotTitle, new Font("Verdana", Font.BOLD, 18)));
    chart.removeLegend();

    try {
        ChartUtilities.saveChartAsPNG(outputFile, chart, 1400, 1400);
    } catch (IOException e) {
        System.err.println("Problem occurred creating chart.");

    }

}

From source file:io.github.dsheirer.spectrum.SpectrumPanel.java

/**
 * Sets the source sample size in bits which defines the lowest dB value to
 * display in the spectrum//from www. ja  v  a 2s .c  o m
 *
 * @param sampleSize in bits
 */
public void setSampleSize(double sampleSize) {
    Validate.isTrue(2.0 <= sampleSize && sampleSize <= 32.0);

    mDBScale = (float) (20.0 * Math.log10(Math.pow(2.0, sampleSize - 1)));
}

From source file:asl.plotmaker.PlotMaker2.java

public void writePlot(String fileName) {
    // System.out.format("== plotTitle=[%s] fileName=[%s]\n", plotTitle,
    // fileName);

    File outputFile = new File(fileName);

    // Check that we will be able to output the file without problems and if
    // not --> return
    if (!checkFileOut(outputFile)) {
        // System.out.format("== plotMaker: request to output plot=[%s] but we are unable to create it "
        // + " --> skip plot\n", fileName );
        logger.warn("== Request to output plot=[{}] but we are unable to create it " + " --> skip plot\n",
                fileName);//from  www .  j  a  v a  2  s  .co  m
        return;
    }

    NumberAxis horizontalAxis = new NumberAxis("x-axis default"); // x =
    // domain

    if (fileName.contains("alnm") || fileName.contains("nlnm") || fileName.contains("coher")
            || fileName.contains("stn")) { // NLNM or StationDeviation
        horizontalAxis = new LogarithmicAxis("Period (sec)");
        horizontalAxis.setRange(new Range(1, 11000));
        horizontalAxis.setTickUnit(new NumberTickUnit(5.0));
    } else { // EventCompareSynthetics/StrongMotion
        horizontalAxis = new NumberAxis("Time (s)");
        double x[] = panels.get(0).getTraces().get(0).getxData();
        horizontalAxis.setRange(new Range(x[0], x[x.length - 1]));
    }

    CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(horizontalAxis);
    combinedPlot.setGap(15.);

    // Loop over (3) panels for this plot:

    for (Panel panel : panels) {

        NumberAxis verticalAxis = new NumberAxis("y-axis default"); // y =
        // range

        if (fileName.contains("alnm") || fileName.contains("nlnm") || fileName.contains("stn")) { // NLNM
            // or
            // StationDeviation
            verticalAxis = new NumberAxis("PSD 10log10(m**2/s**4)/Hz dB");
            verticalAxis.setRange(new Range(-190, -80));
            verticalAxis.setTickUnit(new NumberTickUnit(5.0));
        } else if (fileName.contains("coher")) { // Coherence
            verticalAxis = new NumberAxis("Coherence, Gamma");
            verticalAxis.setRange(new Range(0, 1.2));
            verticalAxis.setTickUnit(new NumberTickUnit(0.1));
        } else { // EventCompareSynthetics/StrongMotion
            verticalAxis = new NumberAxis("Displacement (m)");
        }

        Font fontPlain = new Font("Verdana", Font.PLAIN, 14);
        Font fontBold = new Font("Verdana", Font.BOLD, 18);
        verticalAxis.setLabelFont(fontBold);
        verticalAxis.setTickLabelFont(fontPlain);
        horizontalAxis.setLabelFont(fontBold);
        horizontalAxis.setTickLabelFont(fontPlain);

        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        XYDotRenderer renderer = new XYDotRenderer();
        XYPlot xyplot = new XYPlot(seriesCollection, horizontalAxis, verticalAxis, renderer);
        xyplot.setDomainGridlinesVisible(true);
        xyplot.setRangeGridlinesVisible(true);
        xyplot.setRangeGridlinePaint(Color.black);
        xyplot.setDomainGridlinePaint(Color.black);

        // Plot each trace on this panel:
        int iTrace = 0;
        for (Trace trace : panel.getTraces()) {

            XYSeries series = new XYSeries(trace.getName());

            double xdata[] = trace.getxData();
            double ydata[] = trace.getyData();
            for (int k = 0; k < xdata.length; k++) {
                series.add(xdata[k], ydata[k]);
            }

            renderer.setSeriesPaint(iTrace, trace.getColor());
            renderer.setSeriesStroke(iTrace, trace.getStroke());

            seriesCollection.addSeries(series);

            iTrace++;
        }

        // Add Annotations for each trace - This is done in a separate loop
        // so that
        // the upper/lower limits for this panel will be known
        double xmin = horizontalAxis.getRange().getLowerBound();
        double xmax = horizontalAxis.getRange().getUpperBound();
        double ymin = verticalAxis.getRange().getLowerBound();
        double ymax = verticalAxis.getRange().getUpperBound();
        double delX = Math.abs(xmax - xmin);
        double delY = Math.abs(ymax - ymin);

        // Annotation (x,y) in normalized units - where upper-right corner =
        // (1,1)
        double xAnn = 0.97; // Right center coords of the trace name (e.g.,
        // "00-LHZ")
        double yAnn = 0.95;

        double yOff = 0.05; // Vertical distance between different trace
        // legends

        iTrace = 0;
        for (Trace trace : panel.getTraces()) {
            if (!trace.getName().contains("NLNM") && !trace.getName().contains("NHNM")
                    && !trace.getName().contains("ALNM")) {
                // x1 > x2 > x3, e.g.:
                // o-------o 00-LHZ
                // x3 x2 x1

                double scale = .01; // Controls distance between trace label
                // and line segment
                double xL = .04; // Length of trace line segment in legend

                double xAnn2 = xAnn - scale * trace.getName().length();
                double xAnn3 = xAnn - scale * trace.getName().length() - xL;

                double x1 = xAnn * delX + xmin; // Right hand x-coord of
                // text in range units
                double x2 = xAnn2 * delX + xmin; // x-coord of line segment
                // end in range units
                double x3 = xAnn3 * delX + xmin; // x-coord of line segment
                // end in range units

                double y = (yAnn - (iTrace * yOff)) * delY + ymin;

                if (horizontalAxis instanceof LogarithmicAxis) {
                    double logMin = Math.log10(xmin);
                    double logMax = Math.log10(xmax);
                    delX = logMax - logMin;
                    x1 = Math.pow(10, xAnn * delX + logMin);
                    x2 = Math.pow(10, xAnn2 * delX + logMin);
                    x3 = Math.pow(10, xAnn3 * delX + logMin);
                }
                xyplot.addAnnotation(new XYLineAnnotation(x3, y, x2, y, trace.getStroke(), trace.getColor()));
                XYTextAnnotation xyText = new XYTextAnnotation(trace.getName(), x1, y);
                xyText.setFont(new Font("Verdana", Font.BOLD, 18));
                xyText.setTextAnchor(TextAnchor.CENTER_RIGHT);
                xyplot.addAnnotation(xyText);
            }
            iTrace++;
        }

        combinedPlot.add(xyplot, 1);

    } // panel

    final JFreeChart chart = new JFreeChart(combinedPlot);
    chart.setTitle(new TextTitle(plotTitle, new Font("Verdana", Font.BOLD, 18)));
    chart.removeLegend();

    try {
        ChartUtilities.saveChartAsPNG(outputFile, chart, 1400, 1400);
    } catch (IOException e) {
        // System.err.println("Problem occurred creating chart.");
        logger.error("IOException:", e);
    }

}

From source file:com.joptimizer.algebra.MatrixLogSumRescaler.java

/**
 * Check if the scaling algorithm returned proper results.
 * Note that the scaling algorithm is for minimizing a given objective function of the original matrix elements, and
 * the check will be done on the value of this objective function. 
 * @param A the ORIGINAL (before scaling) matrix
 * @param U the return of the scaling algorithm
 * @param V the return of the scaling algorithm
 * @param base//from  ww  w.  ja  v  a 2  s . c  om
 * @return
 */
public boolean checkScaling(final DoubleMatrix2D A, final DoubleMatrix1D U, final DoubleMatrix1D V) {

    final double log10_2 = Math.log10(base);
    final double[] originalOFValue = { 0 };
    final double[] scaledOFValue = { 0 };
    final double[] x = new double[A.rows()];
    final double[] y = new double[A.columns()];

    A.forEachNonZero(new IntIntDoubleFunction() {
        public double apply(int i, int j, double aij) {
            double v = Math.log10(Math.abs(aij)) / log10_2 + 0.5;
            originalOFValue[0] = originalOFValue[0] + Math.pow(v, 2);
            double xi = Math.log10(U.getQuick(i)) / log10_2;
            double yj = Math.log10(V.getQuick(j)) / log10_2;
            scaledOFValue[0] = scaledOFValue[0] + Math.pow(xi + yj + v, 2);
            x[i] = xi;
            y[j] = yj;
            return aij;
        }
    });

    originalOFValue[0] = 0.5 * originalOFValue[0];
    scaledOFValue[0] = 0.5 * scaledOFValue[0];

    logger.debug("x: " + ArrayUtils.toString(x));
    logger.debug("y: " + ArrayUtils.toString(y));
    logger.debug("originalOFValue: " + originalOFValue[0]);
    logger.debug("scaledOFValue  : " + scaledOFValue[0]);
    return !(originalOFValue[0] < scaledOFValue[0]);
}