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:hulo.localization.models.obs.GaussianProcessLDPLMeanModel.java

void optimizeForGPIsoScaleLOOMSE() {
    MultivariateFunction negaLLfunc = generateGPIsoScaleLOOMSE(this);
    double lambda0 = Math.pow(sigmaN / stdev, 2);
    double[] pointInit = { Math.log10(lengthes[0]), Math.log10(lambda0) };
    double[] dPointInit = { 0.01, 0.01 };
    minimize(negaLLfunc, pointInit, dPointInit);
}

From source file:com.alibaba.jstorm.ui.utils.UIUtils.java

public static String prettyFileSize(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:org.esa.nest.gpf.TerraSARXCalibrator.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./*ww  w .j  ava 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;
    //System.out.println("x0 = " + x0 + ", y0 = " + y0 + ", w = " + w + ", h = " + h);

    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();
    }

    Tile srcGIMTile = null;
    ProductData srcGIMData = null;
    if (useIncidenceAngleFromGIM) {
        srcGIMTile = calibrationOp.getSourceTile(sourceGIMProduct.getBand("band_1"), targetTileRectangle);
        srcGIMData = srcGIMTile.getDataBuffer();
    }

    final Unit.UnitType bandUnit = Unit.getUnitType(sourceBand1);
    final double noDataValue = sourceBand1.getNoDataValue();

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

    final String pol = OperatorUtils.getBandPolarization(srcBandNames[0], absRoot).toUpperCase();
    double Ks = 0.0;
    if (pol != null) {
        Ks = calibrationFactor.get(pol);
    }

    double[][] tileNoise = null;
    if (!noiseCorrectedFlag) {
        tileNoise = new double[h][w];
        computeTileNoise(pol, x0, y0, w, h, tileNoise);
    }

    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 sigma, dn, 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);
                if (dn == noDataValue) { // skip noDataValue
                    continue;
                }
                sigma = dn * dn;
            } else if (bandUnit == Unit.UnitType.INTENSITY) {
                sigma = srcData1.getElemDoubleAt(srcIdx);
            } else if (bandUnit == Unit.UnitType.REAL || bandUnit == Unit.UnitType.IMAGINARY) {
                i = srcData1.getElemDoubleAt(srcIdx);
                q = srcData2.getElemDoubleAt(srcIdx);
                sigma = i * i + q * q;
            } else {
                throw new OperatorException("TerraSARXCalibrator: unhandled unit");
            }

            double inciAng;
            if (useIncidenceAngleFromGIM) {
                final int gim = srcGIMData.getElemIntAt(srcIdx);
                inciAng = (gim - (gim % 10)) / 100.0 * Constants.DTOR;
            } else {
                inciAng = incidenceAngle.getPixelDouble(x, y) * Constants.DTOR;
            }

            if (noiseCorrectedFlag) {
                sigma = Ks * sigma * FastMath.sin(inciAng);
            } else {
                sigma = Ks * (sigma - tileNoise[y - y0][x - x0]) * FastMath.sin(inciAng);
            }

            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:cross.datastructures.workflow.DefaultWorkflow.java

@Override
public File getOutputDirectory(Object iwe) {
    if (iwe instanceof AFragmentCommand) {
        Collection<IFragmentCommand> c = this.commandSequence.getCommands();
        int i = 0;
        int digits = (int) Math.ceil(Math.log10(c.size())) + 1;
        for (IFragmentCommand afc : c) {
            IFragmentCommand iwa = (IFragmentCommand) iwe;
            log.debug("Checking for reference equality!");
            // check for reference equality
            if (iwa == afc) {
                log.debug("Reference equality holds!");
                if (activeCommand == null) {
                    activeCommand = iwa;
                }//w  w w. j a  v  a 2  s .c  o  m
                if (activeCommand != iwa) {
                    activeCommand = iwa;
                }
                File outputFile = new File(outputDirectory,
                        String.format("%0" + digits + "d", i) + "_" + iwa.getClass().getSimpleName());
                outputFile.mkdirs();
                log.info("Output dir for object of type {}: {}", iwe.getClass().getSimpleName(),
                        this.outputDirectory);
                return outputFile;
            }
            i++;
        }
        if (activeCommand != null) {
            File dir = new File(getOutputDirectory(activeCommand), iwe.getClass().getSimpleName());
            if (!dir.exists()) {
                dir.mkdirs();
            }
            log.info("Output dir for object of type {}: {}", iwe.getClass().getSimpleName(),
                    this.outputDirectory);
            return dir;
        }
    } else if (iwe instanceof IWorkflowElement) {
        if (activeCommand != null) {
            File dir = new File(getOutputDirectory(activeCommand), iwe.getClass().getSimpleName());
            if (!dir.exists()) {
                dir.mkdirs();
            }
            log.info("Output dir for object of type {}: {}", iwe.getClass().getSimpleName(),
                    this.outputDirectory);
            return dir;
        }
    }

    File outputFile = new File(outputDirectory, iwe.getClass().getSimpleName());
    outputFile.mkdirs();
    log.info("Output dir for object of type {}: {}", iwe.getClass().getSimpleName(), this.outputDirectory);
    return outputFile;
}

From source file:no.sintef.ict.splcatool.CoveringArrayAlgICPL.java

private void generate2(int coverLimit, Integer sizelimit)
        throws TimeoutException, org.sat4j.specs.TimeoutException {

    // Get a list of vars
    List<BooleanVariableInterface> vars = new ArrayList<BooleanVariableInterface>(cnf.getFocusVariables());

    // Get the invalid 1-tuples
    generate1(100, sizelimit);/*w  w  w. j  a  v a2 s  . co m*/

    // 2-wise
    System.out.println("--- 2-wise ---");

    // Set of invalid 2-tuples
    invalid2w = new HashSet<Pair2>();

    // Solutions
    List<List<Integer>> solutions = new ArrayList<List<Integer>>(initial);
    int coveredInitially = 0;

    // Calculate uncovered tuples
    List<Pair2> uncovered = new ArrayList<Pair2>();
    List<BooleanVariableInterface> vars2 = new ArrayList<BooleanVariableInterface>(vars);
    long invalid = 0;
    for (BooleanVariableInterface var1 : vars) {
        vars2.remove(var1);
        for (BooleanVariableInterface var2 : vars2) {

            // Set pair
            Pair2 unc;
            if (!coverOnlyOnes) {
                if (coverZerosOnly) {
                    if (!(invalid1w.contains(new Pair(var1, false))
                            || invalid1w.contains(new Pair(var2, false)))) {
                        unc = new Pair2(idnr);
                        unc.v1 = var1;
                        unc.b1 = false;
                        unc.v2 = var2;
                        unc.b2 = false;
                        if (!CALib.isCovered(idnr, unc, solutions))
                            uncovered.add(unc);
                        else
                            invalid++;
                    } else {
                        Pair2 inv = new Pair2(idnr);
                        inv.v1 = var1;
                        inv.b1 = false;
                        inv.v2 = var2;
                        inv.b2 = false;
                        invalid2w.add(inv);
                        invalid++;
                    }
                }
                if (!(invalid1w.contains(new Pair(var1, false)) || invalid1w.contains(new Pair(var2, true)))) {
                    unc = new Pair2(idnr);
                    unc.v1 = var1;
                    unc.b1 = false;
                    unc.v2 = var2;
                    unc.b2 = true;
                    if (!CALib.isCovered(idnr, unc, solutions))
                        uncovered.add(unc);
                    else
                        invalid++;
                } else {
                    Pair2 inv = new Pair2(idnr);
                    inv.v1 = var1;
                    inv.b1 = false;
                    inv.v2 = var2;
                    inv.b2 = true;
                    invalid2w.add(inv);
                    invalid++;
                }
                if (!(invalid1w.contains(new Pair(var1, true)) || invalid1w.contains(new Pair(var2, false)))) {
                    unc = new Pair2(idnr);
                    unc.v1 = var1;
                    unc.b1 = true;
                    unc.v2 = var2;
                    unc.b2 = false;
                    if (!CALib.isCovered(idnr, unc, solutions))
                        uncovered.add(unc);
                    else
                        invalid++;
                } else {
                    Pair2 inv = new Pair2(idnr);
                    inv.v1 = var1;
                    inv.b1 = true;
                    inv.v2 = var2;
                    inv.b2 = false;
                    invalid2w.add(inv);
                    invalid++;
                }
            }
            if (!(invalid1w.contains(new Pair(var1, true)) || invalid1w.contains(new Pair(var2, true)))) {
                unc = new Pair2(idnr);
                unc.v1 = var1;
                unc.b1 = true;
                unc.v2 = var2;
                unc.b2 = true;
                if (!CALib.isCovered(idnr, unc, solutions))
                    uncovered.add(unc);
                else
                    invalid++;
            } else {
                Pair2 inv = new Pair2(idnr);
                inv.v1 = var1;
                inv.b1 = true;
                inv.v2 = var2;
                inv.b2 = true;
                invalid2w.add(inv);
                invalid++;
            }
        }
    }

    System.out.println("Uncovered pairs left: " + uncovered.size() + ", invalid: " + invalid2w.size());

    // Check
    /*      System.out.println(uncovered.size());
          System.out.println(invalid);
          System.out.println(ignored);
          System.out.println(4*MathUtils.binomialCoefficient(vars.size(), 2));
    *//*      if(uncovered.size() + invalid + ignored != 4*MathUtils.binomialCoefficient(vars.size(), 2)){
              System.out.println("Internal error: Wrong number of tuples");
              System.exit(-1);
           }
       */
    // Cover
    long grandTotal = uncovered.size() + invalid;
    boolean invalidRemoved = false;
    while (!uncovered.isEmpty()) {
        // Start threads
        int uncTotal = coveredInitially + uncovered.size();

        List<Pair2> uncSplit = new ArrayList<Pair2>();
        for (int i = 0; i < uncovered.size(); i++) {
            uncSplit.add(uncovered.get(i));
        }

        C2SplitThread fmt = new C2SplitThread(cnf, uncSplit, idnr);
        Thread t = new Thread(fmt);

        t.start();

        // Start monitoring thread
        List<C2SplitThread> fmts = new ArrayList<C2SplitThread>();
        fmts.add(fmt);
        List<ProgressReporter> prs = new ArrayList<ProgressReporter>(fmts);
        ProgressThread pt = new ProgressThread("Cover pairs", prs, uncTotal);
        Thread ptt = new Thread(pt);
        ptt.start();

        // Wait for all threads to finish
        try {
            t.join();
        } catch (InterruptedException e) {
        }

        // Stop monitoring
        pt.stop();

        // Round complete
        System.out.println("Round complete");
        Set<Pair2> uncovSet = new HashSet<Pair2>();
        uncovSet.addAll(fmt.getUncovered());
        List<List<Integer>> sols = new ArrayList<List<Integer>>();
        sols.addAll(fmt.getSolutions());
        Set<Pair2> cov = getCovInv(sols, new ArrayList<Pair2>(uncovSet));
        System.out.println("Additionally covered " + cov.size());
        int newcovered = uncovSet.size();
        uncovSet.removeAll(cov);
        newcovered = newcovered - uncovSet.size();

        // Remove invalid at some round
        if (!invalidRemoved) {
            if ((int) Math.log10(cov.size()) <= (int) Math.log10(cnf.getFocusVariables().size())
                    || coverLimit <= coverage) {
                System.out.println("Removing invalid");
                int diff = uncovSet.size();
                uncovSet = new HashSet<Pair2>(getInvalid(coveredInitially, new ArrayList<Pair2>(uncovSet)));
                diff -= uncovSet.size();
                uncTotal -= diff;
                System.out.println("Invalid: " + diff);
                invalidRemoved = true;
            }
        }

        // Store
        solutions.addAll(sols);
        uncovered.clear();
        uncovered.addAll(uncovSet);
        if (saveAfterEachRound) {
            try {
                result = solutions;
                writeToFile(tmp_save_filename, Type.horizontal, tmpSave_hideUnderscoreVariables);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        // Report progress
        System.out.println("Uncovered: " + uncovered.size() + ", progress: "
                + (grandTotal - uncovered.size()) * 100 / grandTotal + "% with solutions: " + solutions.size());

        // Stop at limit
        coverage = (grandTotal - uncovered.size()) * 100 / grandTotal;
        if (invalidRemoved && coverLimit <= coverage)
            break;

        // Stop at limit
        if (solutions.size() >= sizelimit)
            break;
    }

    // Done
    result = solutions;

    System.out.println("2-wise done, solutions: " + solutions.size() + ", invalid: " + invalid2w.size());
}

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

/**
 * Computes a binomial probability.  This is computed using the formula
 * <p/>/*from w  w w . j a  v a  2 s. co  m*/
 * B(k; n; p) = [ n! / ( k! (n - k)! ) ] (p^k)( (1-p)^k )
 * <p/>
 * where n is the number of trials, k is the number of successes, and p is the probability of success
 *
 * @param n number of Bernoulli trials
 * @param k number of successes
 * @param p probability of success
 * @return the binomial probability of the specified configuration.  Computes values down to about 1e-237.
 */
public static double binomialProbability(final int n, final int k, final double p) {
    return Math.pow(10, log10BinomialProbability(n, k, Math.log10(p)));
}

From source file:desmoj.extensions.grafic.util.Plotter.java

/**
 * configure range axis ( lowerBound, upperBound, label, format ticks)
 * of time-series chart/*from  www.j  a  v a2 s.com*/
 * @param numberAxis
 * @param label
 */
private void configureRangeAxis(NumberAxis numberAxis, String label) {
    double min = numberAxis.getLowerBound();
    double max = numberAxis.getUpperBound();
    Double delta = 0.01 * (max - min);
    numberAxis.setLowerBound(min - delta);
    numberAxis.setUpperBound(max + delta);

    numberAxis.setLabel(label);

    // format Ticks
    double fontHeight = numberAxis.getTickLabelFont().getLineMetrics("X", this.frc).getHeight();
    double maxTicks = this.paintPanel.getSize().height / fontHeight;
    int digits = Math.max(0, (int) -Math.floor(Math.log10((max - min) / maxTicks)));
    //System.out.println(fontHeight+"  "+digits+"  "+Math.log10((max - min)/ maxTicks));
    NumberFormat formatter = NumberFormat.getNumberInstance(this.locale);
    formatter.setMinimumFractionDigits(digits);
    formatter.setMaximumFractionDigits(digits);
    formatter.setGroupingUsed(true);
    numberAxis.setNumberFormatOverride(formatter);
}

From source file:hulo.localization.models.obs.GaussianProcessLDPLMeanModel.java

void optimizeEstimateSigmaN_NM(final List<Sample> samplesForEstimateSigmaN) {
    MultivariateFunction negaLLfunc = generateSigmaNObjectiveFunction(this, samplesForEstimateSigmaN);
    double[] pointInit = { Math.log10(sigmaN) };
    double[] dPointInit = { 0.01 };
    minimize(negaLLfunc, pointInit, dPointInit);
}

From source file:adapters.AxisAdapter.java

private double computeAutoTickValue() {
    // Calcule le pas d'affichage par defaut des labels
    double pas;/*from  w w  w.j  a  v  a  2 s .  c  om*/
    double[] bounds = new double[2];
    bounds[0] = Math.min(axis.getRange().getLowerBound(), twinAxisPosition);
    bounds[1] = Math.max(axis.getRange().getUpperBound(), twinAxisPosition);
    if (bounds[1] - bounds[0] >= 1) {
        int nbMaxDeFois = (int) (bounds[1] - bounds[0]);
        int puissDix = (int) Math.log10(nbMaxDeFois);
        nbMaxDeFois = (int) (nbMaxDeFois / Math.pow(10, puissDix)) + 1;
        if (nbMaxDeFois > 5)
            pas = Math.pow(10, puissDix);
        else if (nbMaxDeFois > 3)
            pas = 0.5 * Math.pow(10, puissDix);
        else if (nbMaxDeFois > 1)
            pas = 0.25 * Math.pow(10, puissDix);
        else //nbMaxDeFois==1
            pas = 0.1 * Math.pow(10, puissDix);
    } else {
        double nbMaxDeFois = bounds[1] - bounds[0];
        int puissDix = 0;
        while (nbMaxDeFois < 1) {
            nbMaxDeFois *= 10;
            puissDix++;
        }
        if (nbMaxDeFois > 5)
            pas = 1 / Math.pow(10, puissDix);
        else if (nbMaxDeFois > 3)
            pas = 0.5 / Math.pow(10, puissDix);
        else if (nbMaxDeFois > 1)
            pas = 0.3 / Math.pow(10, puissDix);
        else //nbMaxDeFois==1
            pas = 0.1 / Math.pow(10, puissDix);
    }
    return pas;
}

From source file:org.processmining.analysis.performance.dottedchart.ui.DottedChartPanel.java

/**
 * adjusts the viewable are of the log (zoom)
 *///  w ww .j ava  2 s  .c  o  m
public Point zoomInViewPort() {
    if (p1 == null || p2 == null)
        return null;
    Dimension d = dca.getViewportSize();
    int width = Math.abs(p1.x - p2.x);
    int height = Math.abs(p1.y - p2.y);

    int value = (int) (Math.log10(
            (double) this.getWidth() * (d.getWidth() / width) / (double) dca.getViewportSize().getWidth())
            * 1000.0);
    if (value > 3000)
        return null;
    value = (int) (Math.log10(
            (double) this.getHeight() * (d.getHeight() / height) / (double) dca.getViewportSize().getHeight())
            * 1000.0);
    if (value > 3000)
        return null;

    updWidth = (int) ((double) this.getWidth() * (d.getWidth() / width));
    updHight = (int) ((double) this.getHeight() * (d.getHeight() / height));

    Dimension dim = new Dimension(updWidth, updHight);
    int pos_x = Math.min(p1.x, p2.x);
    int pos_y = Math.min(p1.y, p2.y);

    this.setPreferredSize(dim);
    updateMilli2pixelsRatio();
    this.revalidate();
    p1 = null;
    p2 = null;
    adjustSlideBar();
    return new Point((int) (pos_x * d.getWidth() / width), (int) (pos_y * d.getHeight() / height));
}