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.esa.nest.gpf.ForestAreaDetectionOp.java

/**
 * Called by the framework in order to compute the stack of tiles for the given target bands.
 * <p>The default implementation throws a runtime exception with the message "not implemented".</p>
 *
 * @param targetTiles     The current tiles to be computed for each target band.
 * @param targetRectangle The area in pixel coordinates to be computed (same for all rasters in <code>targetRasters</code>).
 * @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 rasters.
 *///ww w. j  a  v  a2  s. c  o m
@Override
public void computeTileStack(Map<Band, Tile> targetTiles, Rectangle targetRectangle, ProgressMonitor pm)
        throws OperatorException {

    try {
        final int tx0 = targetRectangle.x;
        final int ty0 = targetRectangle.y;
        final int tw = targetRectangle.width;
        final int th = targetRectangle.height;
        //System.out.println("tx0 = " + tx0 + ", ty0 = " + ty0 + ", tw = " + tw + ", th = " + th);

        final Rectangle sourceTileRectangle = getSourceTileRectangle(tx0, ty0, tw, th);
        final Band nominatorBand = sourceProduct.getBand(sourceBandNames[0]);
        final Band denominatorBand = sourceProduct.getBand(sourceBandNames[1]);
        final Tile nominatorTile = getSourceTile(nominatorBand, sourceTileRectangle);
        final Tile denominatorTile = getSourceTile(denominatorBand, sourceTileRectangle);
        final ProductData nominatorData = nominatorTile.getDataBuffer();
        final ProductData denominatorData = denominatorTile.getDataBuffer();
        final String nominatorBandUnit = nominatorBand.getUnit();
        final String denominatorBandUnit = denominatorBand.getUnit();
        final double noDataValueN = nominatorBand.getNoDataValue();
        final double noDataValueD = denominatorBand.getNoDataValue();

        final Band targetRatioBand = targetProduct.getBand(RATIO_BAND_NAME);
        final Tile targetRatioTile = targetTiles.get(targetRatioBand);
        final ProductData ratioData = targetRatioTile.getDataBuffer();
        //final Band targetMaskBand = targetProduct.getBand(FOREST_MASK_NAME);
        //final Tile targetMaskTile = targetTiles.get(targetMaskBand);
        //final ProductData maskData = targetMaskTile.getDataBuffer();

        final TileIndex trgIndex = new TileIndex(targetTiles.get(targetTiles.keySet().iterator().next()));
        final TileIndex srcIndex = new TileIndex(nominatorTile); // src and trg tile are different size

        final int maxy = ty0 + th;
        final int maxx = tx0 + tw;

        double vDDB, vRatioDB;
        for (int ty = ty0; ty < maxy; ty++) {
            trgIndex.calculateStride(ty);
            srcIndex.calculateStride(ty);
            for (int tx = tx0; tx < maxx; tx++) {
                final int trgIdx = trgIndex.getIndex(tx);
                final int srcIdx = srcIndex.getIndex(tx);

                final double vN = nominatorData.getElemDoubleAt(srcIdx);
                final double vD = denominatorData.getElemDoubleAt(srcIdx);
                if (vN == noDataValueN || vD == noDataValueD) {
                    //maskData.setElemIntAt(trgIdx, -1);
                    ratioData.setElemFloatAt(trgIdx, 0.0f);
                    continue;
                }

                final double vRatio = computeRatio(tx, ty, nominatorTile, nominatorData, denominatorTile,
                        denominatorData, nominatorBandUnit, denominatorBandUnit, noDataValueN, noDataValueD);

                if (vRatio == noDataValueN || vRatio == noDataValueD) {
                    //maskData.setElemIntAt(trgIdx, -1);
                    ratioData.setElemFloatAt(trgIdx, 0.0f);
                    continue;
                }

                vRatioDB = 10.0 * Math.log10(Math.max(vRatio, Constants.EPS));
                vDDB = 10.0 * Math.log10(Math.max(vD, Constants.EPS));

                //int maskBit = 0;
                //if (vRatioDB > T_Ratio_Low && vRatioDB < T_Ratio_High && vDDB > T_HV_Low) {
                //    maskBit = 1;
                //}

                //maskData.setElemIntAt(trgIdx, maskBit);
                ratioData.setElemFloatAt(trgIdx, (float) vRatioDB);
            }
        }

    } catch (Throwable e) {
        OperatorUtils.catchOperatorException(getId(), e);
    }
}

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

public static double log10sumLog10(final double[] log10p, final int start, final int finish) {

    if (start >= finish)
        return Double.NEGATIVE_INFINITY;
    final int maxElementIndex = MathUtils.maxElementIndex(log10p, start, finish);
    final double maxValue = log10p[maxElementIndex];
    if (maxValue == Double.NEGATIVE_INFINITY)
        return maxValue;
    double sum = 1.0;
    for (int i = start; i < finish; i++) {
        double curVal = log10p[i];
        double scaled_val = curVal - maxValue;
        if (i == maxElementIndex || curVal == Double.NEGATIVE_INFINITY) {
            continue;
        } else {// w  w w .  j  a v  a  2 s  .co  m
            sum += Math.pow(10.0, scaled_val);
        }
    }
    if (Double.isNaN(sum) || sum == Double.POSITIVE_INFINITY) {
        throw new IllegalArgumentException("log10p: Values must be non-infinite and non-NAN");
    }
    return maxValue + (sum != 1.0 ? Math.log10(sum) : 0.0);
}

From source file:com.amaze.filemanager.utils.Futils.java

public String readableFileSize(long size) {
    if (size <= 0)
        return "0 B";
    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:com.wildplot.android.ankistats.AnswerButton.java

public double ticsCalcY(int pixelDistance, Rectangle field) {
    double deltaRange = mMaxCards - 0;
    int ticlimit = field.height / pixelDistance;
    double tics = Math.pow(10, (int) Math.log10(deltaRange / ticlimit));
    while (2.0 * (deltaRange / (tics)) <= ticlimit) {
        tics /= 2.0;//from   w w w  .  j a va 2 s . co  m
    }
    while ((deltaRange / (tics)) / 2 >= ticlimit) {
        tics *= 2.0;
    }
    return tics;
}

From source file:delfos.rs.contentbased.vsm.booleanvsm.symeonidis2007.Symeonidis2007FeatureWeighted.java

@Override
public Symeonidis2007Model buildRecommendationModel(DatasetLoader<? extends Rating> datasetLoader)
        throws CannotLoadRatingsDataset, CannotLoadContentDataset {

    final RatingsDataset<? extends Rating> ratingsDataset = datasetLoader.getRatingsDataset();
    final ContentDataset contentDataset;
    if (datasetLoader instanceof ContentDatasetLoader) {
        ContentDatasetLoader contentDatasetLoader = (ContentDatasetLoader) datasetLoader;
        contentDataset = contentDatasetLoader.getContentDataset();
    } else {// w w w  .  j  a  v a2s .  c  om
        throw new CannotLoadContentDataset(
                "The dataset loader is not a ContentDatasetLoader, cannot apply a content-based ");
    }
    BooleanFeaturesTransformation booleanFeaturesTransformation = new BooleanFeaturesTransformation(
            contentDataset);

    Symeonidis2007Model model = new Symeonidis2007Model(booleanFeaturesTransformation);
    fireBuildingProgressChangedEvent("Model creation", 0, -1);
    {
        int i = 1;
        for (Item item : contentDataset) {
            try {
                SparseVector<Long> itemProfile = makeFFItemProfile(item.getId(), datasetLoader,
                        booleanFeaturesTransformation);
                model.putItemProfile(item.getId(), itemProfile);

                fireBuildingProgressChangedEvent("Profile creation",
                        (int) ((double) i++ * 100 / contentDataset.size()), -1);
            } catch (ItemNotFound ex) {
                ERROR_CODES.ITEM_NOT_FOUND.exit(ex);
            }
        }
    }

    fireBuildingProgressChangedEvent("Profile creation", 100, -1);

    RelevanceCriteria relevanceCriteria = datasetLoader.getDefaultRelevanceCriteria();

    Map<Integer, SparseVector<Long>> ff_userProfiles = new TreeMap<Integer, SparseVector<Long>>();

    //Calculo los perfiles de usuario, la parte FF(u)
    for (int idUser : ratingsDataset.allUsers()) {
        try {
            ff_userProfiles.put(idUser,
                    makeFFUserProfile(idUser, datasetLoader, booleanFeaturesTransformation));
        } catch (UserNotFound ex) {
            ERROR_CODES.USER_NOT_FOUND.exit(ex);
        }
    }

    //Calculo la IUF.
    SparseVector<Long> iuf = booleanFeaturesTransformation.newProfile();
    {
        int i = 0;
        final double numUsers = ratingsDataset.allUsers().size();
        fireBuildingProgressChangedEvent("IUF calculation", 0, -1);
        for (Feature feature : contentDataset.getFeatures()) {
            for (Object featureValue : booleanFeaturesTransformation.getAllFeatureValues(feature)) {
                long idFeatureValue = booleanFeaturesTransformation.getFeatureIndex(feature, featureValue);

                double count = 0;
                for (int idUser : ratingsDataset.allUsers()) {

                    try {
                        Map<Integer, ? extends Rating> userRatingsRated = ratingsDataset
                                .getUserRatingsRated(idUser);
                        for (Map.Entry<Integer, ? extends Rating> entry : userRatingsRated.entrySet()) {

                            int idItemRatedByUser = entry.getKey();
                            Number rating = entry.getValue().getRatingValue().doubleValue();

                            //Si el rating es negativo, este producto no cuenta.
                            if (relevanceCriteria.isRelevant(rating)) {

                                SparseVector<Long> itemProfile = model.getItemProfile(idItemRatedByUser);
                                if (itemProfile.containsKey(idFeatureValue)
                                        && itemProfile.get(idFeatureValue) > 0) {
                                    count++;

                                    //Como este usuario tiene algn producto valorado con la caracterstica, paro el clculo ya que no me interesa si tiene ms de uno.
                                    break;
                                }
                            }
                        }
                    } catch (UserNotFound ex) {
                        ERROR_CODES.USER_NOT_FOUND.exit(ex);
                        throw new IllegalArgumentException(ex);
                    }
                }

                double u_div_uf = numUsers / count;

                double iufThisFeatureValue = Math.log10(u_div_uf);

                if (Global.isVerboseAnnoying()) {
                    Global.showInfoMessage("Feature " + feature + " and value " + featureValue
                            + " has an IUF of " + iufThisFeatureValue + "\n");
                }
                iuf.set(idFeatureValue, iufThisFeatureValue);
                fireBuildingProgressChangedEvent("IUF calculation",
                        (int) ((double) i++ * 100 / booleanFeaturesTransformation.sizeOfAllFeatureValues()),
                        -1);
            }
        }
    }

    model.setAllIuf(iuf);

    //Ahora calculo los perfiles de los usuarios, para luego hacer vecindario...
    {
        for (int idUser : ratingsDataset.allUsers()) {
            SparseVector<Long> userFF = ff_userProfiles.get(idUser);

            SparseVector<Long> userProfileFinalVector = userFF.clone();
            userProfileFinalVector.multiply(iuf);

            Map<Feature, Map<Object, Double>> userProfileValues = booleanFeaturesTransformation
                    .getFeatureValueMap(userProfileFinalVector);

            model.putUserProfile(idUser, new Symeonidis2007UserProfile(idUser, userProfileValues));
        }
    }

    return model;
}

From source file:org.ut.biolab.medsavant.client.view.genetics.charts.SummaryChart.java

private synchronized Chart drawChart(ChartFrequencyMap[] chartMaps) {

    ChartFrequencyMap filteredChartMap = chartMaps[0];
    ChartFrequencyMap unfilteredChartMap = null;

    DefaultChartModel filteredChartModel = new DefaultChartModel();
    DefaultChartModel unfilteredChartModel = null;

    if (this.showComparedToOriginal) {
        unfilteredChartMap = ChartFrequencyMap.subtract(chartMaps[1], filteredChartMap, isLogScaleY());
        unfilteredChartModel = new DefaultChartModel();
    }/* w  w  w. j  a va2  s  . c  om*/

    final Chart chart = new Chart();

    JPanel panel = new JPanel();
    Legend legend = new Legend(chart, 0);
    panel.add(legend);
    legend.addChart(chart);

    boolean multiColor = !mapGenerator.isNumeric() || isPie;

    chart.setRolloverEnabled(true);
    chart.setSelectionEnabled(true);
    chart.setSelectionShowsOutline(true);
    chart.setSelectionShowsExplodedSegments(true);
    chart.setAntiAliasing(true);
    chart.setBarGap(5);
    chart.setBorder(ViewUtil.getBigBorder());
    chart.setLabellingTraces(true);

    chart.setAnimateOnShow(false);

    chart.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                JPopupMenu popup = createPopup(chart);
                popup.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    });

    AbstractPieSegmentRenderer rpie = new DefaultPieSegmentRenderer();
    chart.setPieSegmentRenderer(rpie);

    //Makes a box with fill color 255,255,255,0 and put a label with a black
    //font in that box.  The box is positioned directly over the corresponding pie slice.
    /*
    SimplePieLabelRenderer plr = new SimplePieLabelRenderer();
    plr.setLabelColor(Color.BLACK);
    plr.setBackground(new Color(0,0,0,0));
    rpie.setPieLabelRenderer(plr);
    */

    //....alternatively, the below draws a line from the pie wedge to the label.
    //see http://www.jidesoft.com/javadoc/com/jidesoft/chart/render/LinePieLabelRenderer.html
    LinePieLabelRenderer plr = new LinePieLabelRenderer();
    plr.setLabelColor(Color.black);
    plr.setLineColor(Color.black); //see also plr.setLineStroke        
    rpie.setPieLabelRenderer(plr);

    DefaultBarRenderer rbar = new DefaultBarRenderer();
    chart.setBarRenderer(rbar);

    rpie.setSelectionColor(Color.gray);
    rbar.setSelectionColor(Color.gray);

    if (isSortedKaryotypically()) {
        filteredChartMap.sortKaryotypically();
        if (this.showComparedToOriginal) {
            unfilteredChartMap.sortKaryotypically();
        }
    }

    if (isSorted() && !mapGenerator.isNumeric() && !isSortedKaryotypically()) {
        filteredChartMap.sortNumerically();
        if (this.showComparedToOriginal) {
            chartMaps[1].sortNumerically();
        }
    } else {
        filteredChartMap.undoSortNumerically();
        if (this.showComparedToOriginal) {
            chartMaps[1].undoSortNumerically();
        }
    }

    long max = filteredChartMap.getMax();
    List<ChartCategory> chartCategories;
    if (this.showComparedToOriginal) {
        chartCategories = chartMaps[1].getCategories();
        max = chartMaps[1].getMax();
    } else {
        chartCategories = filteredChartMap.getCategories();
    }

    CategoryRange<String> range = new CategoryRange<String>();
    List<Highlight> highlights = new ArrayList<Highlight>();

    Color color = new Color(72, 181, 249);
    Highlight h;
    int catNum = 0;
    int totalCats = filteredChartMap.getEntries().size();

    for (ChartCategory category : chartCategories) {
        range.add(category);
        if (multiColor) {
            color = ViewUtil.getColor(catNum++, totalCats);
        }
        h = new Highlight(category.getName());
        highlights.add(h);
        chart.setHighlightStyle(h, barStyle(color));
    }

    final CategoryAxis xaxis = new CategoryAxis(range, "Category");
    chart.setXAxis(xaxis);
    if (this.isLogScaleY()) {
        chart.setYAxis(new Axis(new NumericRange(0, Math.log10(max) * 1.1), "log(Frequency)"));
    } else {
        chart.setYAxis(new Axis(new NumericRange(0, max * 1.1), "Frequency"));
    }

    addEntriesToChart(filteredChartModel, filteredChartMap, chartCategories, highlights);
    if (this.showComparedToOriginal) {
        addEntriesToChart(unfilteredChartModel, unfilteredChartMap, chartCategories, null);
    }

    chart.getXAxis().getLabel().setFont(ViewUtil.getMediumTitleFont());
    chart.getYAxis().getLabel().setFont(ViewUtil.getMediumTitleFont());

    // rotate 90 degrees (using radians)
    chart.getXAxis().setTickLabelRotation(1.57079633);

    if (isPie) {
        System.out.println("Setting chart type to pie");
        chart.setChartType(ChartType.PIE);
        chart.getXAxis().getLabel().setColor(Color.BLUE);
    }

    // This adds zooming cababilities to bar charts, not great though
    /*else {
     RubberBandZoomer rubberBand = new RubberBandZoomer(chart);
     chart.addDrawable(rubberBand);
     chart.addMouseListener(rubberBand);
     chart.addMouseMotionListener(rubberBand);
            
     rubberBand.addZoomListener(new ZoomListener() {
     public void zoomChanged(ChartSelectionEvent event) {
     if (event instanceof RectangleSelectionEvent) {
     Range<?> currentXRange = chart.getXAxis().getOutputRange();
     Range<?> currentYRange = chart.getYAxis().getOutputRange();
     ZoomFrame frame = new ZoomFrame(currentXRange, currentYRange);
     zoomStack.push(frame);
     Rectangle selection = (Rectangle) event.getLocation();
     Point topLeft = selection.getLocation();
     topLeft.x = (int) Math.floor(frame.getXRange().minimum());
     Point bottomRight = new Point(topLeft.x + selection.width, topLeft.y + selection.height);
     bottomRight.x = (int) Math.ceil(frame.getXRange().maximum());
     assert bottomRight.x >= topLeft.x;
     Point2D rp1 = chart.calculateUserPoint(topLeft);
     Point2D rp2 = chart.calculateUserPoint(bottomRight);
     if (rp1 != null && rp2 != null) {
     assert rp2.getX() >= rp1.getX();
     Range<?> xRange = new NumericRange(rp1.getX(), rp2.getX());
     assert rp1.getY() >= rp2.getY();
     Range<?> yRange = new NumericRange(rp2.getY(), rp1.getY());
     //chart.getXAxis().setRange(xRange);
     chart.getYAxis().setRange(yRange);
     }
     } else if (event instanceof PointSelectionEvent) {
     if (zoomStack.size() > 0) {
     ZoomFrame frame = zoomStack.pop();
     Range<?> xRange = frame.getXRange();
     Range<?> yRange = frame.getYRange();
     //chart.getXAxis().setRange(xRange);
     chart.getYAxis().setRange(yRange);
     }
     }
     }
     });
     }
     *
     */

    for (int i = 1; i < this.getComponentCount(); i++) {
        this.remove(i);
    }

    chart.addModel(filteredChartModel, new ChartStyle().withBars());
    if (this.showComparedToOriginal) {
        chart.addModel(unfilteredChartModel, new ChartStyle(new Color(10, 10, 10, 100)).withBars());
    }

    return chart;
}

From source file:dsp.unige.figures.ChannelHelper.java

/**
 * Returns the bit error rate when NOT using any FEC code
 * //from  ww  w  .java2 s.co m
 * @param sta  the station object
 * @param sat the satellite object
 * @param rate the information rate
 * @return the ber rate in (0,0.5)
 */
public static double getUncodedBER(Station sta, Satellite sat, double rate) {
    double SdBW, Eb, N0, EbN0;
    SdBW = getSdBW(sta, sat);
    Eb = 10 * Math.log10(Math.pow(10, SdBW / 10d) / (rate * 1000d));
    N0 = getN0dBW(sta, sat);
    EbN0 = Eb - N0;
    double ber = 0.5 * Erf.erfc(Math.sqrt(EbN0));
    if (!Double.isNaN(ber) && ber < 0.5)
        return ber;
    else
        return 0.5;
}

From source file:com.github.pitzcarraldo.dissimilar.Dissimilar.java

/**
 * Calculate PSNR; see http://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio
 * @param pOne first image to compare//from ww w.  j  a  va  2 s . com
 * @param pTwo second image to compare
 * @param pGreyscale whether the images are greyscale or not
 * @return calculated psnr
 */
public static double calcPSNR(final int[] pOne, final int[] pTwo, final boolean pGreyscale) {

    if (!checkPair(pOne, pTwo))
        return -1;

    final double mse = calcMSE(pOne, pTwo, pGreyscale);

    //what to do if the bit depth of the images are different?

    //we are just using an 8-bit per channel representation at the moment
    final double maxPixelValue = Math.pow(2, 8) - 1;

    final double psnr = 10 * Math.log10((maxPixelValue * maxPixelValue) / mse);

    return psnr;
}

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

/**
 * adjusts the viewable are of the log (zoom)
 *//*  www  .j  a va  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(this.getWidth() * (d.getWidth() / width) / dca.getViewportSize().getWidth())
            * 1000.0);
    if (value > 3000)
        return null;
    value = (int) (Math.log10(this.getHeight() * (d.getHeight() / height) / dca.getViewportSize().getHeight())
            * 1000.0);
    if (value > 3000)
        return null;

    updWidth = (int) (this.getWidth() * (d.getWidth() / width));
    updHight = (int) (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);
    coUtil.updateMilli2pixelsRatio(this.getWidth(), BORDER);
    this.revalidate();
    p1 = null;
    p2 = null;
    adjustSlideBar();
    return new Point((int) (pos_x * d.getWidth() / width), (int) (pos_y * d.getHeight() / height));
}

From source file:com.wildplot.android.ankistats.AnswerButton.java

public double ticsCalc(int pixelDistance, Rectangle field, double deltaRange) {
    int ticlimit = field.height / pixelDistance;
    double tics = Math.pow(10, (int) Math.log10(deltaRange / ticlimit));
    while (2.0 * (deltaRange / (tics)) <= ticlimit) {
        tics /= 2.0;/* w w  w . j  a  va 2 s . c om*/
    }
    while ((deltaRange / (tics)) / 2 >= ticlimit) {
        tics *= 2.0;
    }
    return tics;
}