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:com.android.mail.ui.ConversationListFragment.java

/**
 * Handles a request to show a new conversation list, either from a search
 * query or for viewing a folder. This will initiate a data load, and hence
 * must be called on the UI thread.//from  w  w w.j  a  va2  s. co  m
 */
private void showList() {
    mInitialCursorLoading = true;
    onFolderUpdated(mActivity.getFolderController().getFolder());
    onConversationListStatusUpdated();

    // try to get an order-of-magnitude sense for message count within folders
    // (N.B. this count currently isn't working for search folders, since their counts stream
    // in over time in pieces.)
    final Folder f = mViewContext.folder;
    if (f != null) {
        final long countLog;
        if (f.totalCount > 0) {
            countLog = (long) Math.log10(f.totalCount);
        } else {
            countLog = 0;
        }
        Analytics.getInstance().sendEvent("view_folder", f.getTypeDescription(), Long.toString(countLog),
                f.totalCount);
    }
}

From source file:Model.MultiPlatformLDA.java

private double getPostLikelihood(int u, int j, int p, int z) {
    // Compute likelihood of post number j of user number u given the
    // platform is p and the topic is z
    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);
        }//from  w w  w  .  j  a  v a 2  s  .  c o  m
        double platform_logLikelihood = 0;
        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);
    }
}

From source file:spectrogram.Spectrogram.java

/**
 * Add a tick to the y axis//  w  w  w .j  a v a2 s  .  c o  m
 * @param mxexp
 * @param val 
 */
private void labelYTick(double mxexp, double val) {
    int ypos = getYpos(mxexp, val);
    int xps = imgX0 - 5;
    int xpe = imgX0 + dimX;

    grph.drawLine(xps, ypos, xpe, ypos);
    String fmt = "%1$,.0f";
    if (val == 0) {
        fmt = "%1$.1f";
    } else if (val < 1) {
        int exp = -(int) Math.floor(Math.log10(val));
        fmt = "%1$." + Integer.toString(exp) + "f";
    }
    String fstr = String.format(fmt, val);
    int fstrLen = labelMetrics.stringWidth(fstr);
    int fsp = xps - fstrLen - 2;
    grph.drawString(fstr, fsp, ypos + lblHeight / 2);
}

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

protected List getAllTicksVertical(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
    List ticks = new java.util.ArrayList();

    //get lower bound value:
    double lowerBoundVal = getRange().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;
    }//  w w  w.  java 2  s  . c o  m
    //get upper bound value
    double upperBoundVal = getRange().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 && 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 tickVal;
    String tickLabel;
    //        tickVal = lowerBoundVal;
    //        
    //        tickLabel = Long.toString((long) Math.rint(tickVal));
    //        ticks.add(new NumberTick(new Double(tickVal), tickLabel,
    //              TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, 0.0));
    boolean zeroTickFlag = false;
    for (int i = iBegCount; i <= iEndCount; i++) {
        //for each tick with a label to be displayed
        int jEndCount = 10;
        if (i == iEndCount) {
            //                jEndCount = 1;
        }

        for (int j = 0; j < jEndCount; j++) {
            //for each tick to be displayed
            if (this.smallLogFlag) {
                //small log values in use
                tickVal = Math.pow(10, i) + (Math.pow(10, i) * j);
                //first tick of group; create label text
                if (this.log10TickLabelsFlag) {
                    //if flag then
                    tickLabel = "10^" + i; //create "log10"-type label
                } else { //not "log10"-type label
                    if (this.expTickLabelsFlag) {
                        //if flag then
                        tickLabel = "1e" + i; //create "1e#"-type label
                    } else { //not "1e#"-type label
                        if (i >= 0) { // if positive exponent then
                                      // make integer
                            NumberFormat format = getNumberFormatOverride();
                            if (format != null) {
                                tickLabel = format.format(tickVal);
                            } else {
                                tickLabel = Long.toString((long) Math.rint(tickVal));
                            }
                        } else {
                            //negative exponent; create fractional value
                            //set exact number of fractional digits to
                            // be shown:
                            this.numberFormatterObj.setMaximumFractionDigits(-i);
                            //create tick label:
                            tickLabel = this.numberFormatterObj.format(tickVal);
                        }
                    }
                }
            } 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
                tickVal = (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 (i > iBegCount && i < iEndCount && Math.abs(tickVal - 1.0) < 0.0001) {
                        // not first or last tick on graph and value
                        // is 1.0
                        tickVal = 0.0; //change value to 0.0
                        zeroTickFlag = true; //indicate zero tick
                        tickLabel = "0"; //create label for tick
                    } else {
                        //first or last tick on graph or value is 1.0
                        //create label for tick:
                        tickLabel = createTickLabel(tickVal, i);
                    }
                } else { // not first tick of group
                    tickLabel = createTickLabel(tickVal, i);
                }
            }

            if (tickVal > 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)));
                    }
                    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.CENTER_RIGHT,
                            TextAnchor.CENTER_RIGHT, 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.CENTER_RIGHT,
                            TextAnchor.CENTER_RIGHT, 0.0));
                }
                return ticks; //if past highest data value then exit method
            }

            if (tickVal >= lowerBoundVal - SMALL_LOG_VALUE) {
                //tick value not below lowest data value
                TextAnchor anchor = null;
                TextAnchor rotationAnchor = null;
                double angle = 0.0;
                if (isVerticalTickLabels()) {
                    if (edge == RectangleEdge.LEFT) {
                        anchor = TextAnchor.BOTTOM_CENTER;
                        rotationAnchor = TextAnchor.BOTTOM_CENTER;
                        angle = -Math.PI / 2.0;
                    } else {
                        anchor = TextAnchor.BOTTOM_CENTER;
                        rotationAnchor = TextAnchor.BOTTOM_CENTER;
                        angle = Math.PI / 2.0;
                    }
                } else {
                    if (edge == RectangleEdge.LEFT) {
                        anchor = TextAnchor.CENTER_RIGHT;
                        rotationAnchor = TextAnchor.CENTER_RIGHT;
                    } else {
                        anchor = TextAnchor.CENTER_LEFT;
                        rotationAnchor = TextAnchor.CENTER_LEFT;
                    }
                }
                //create tick object and add to list:
                lastTick = new NumberTick(new Double(tickVal), 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)));
        }
        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.CENTER_RIGHT,
                TextAnchor.CENTER_RIGHT, 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.CENTER_RIGHT,
                TextAnchor.CENTER_RIGHT, 0.0));
    }
    return ticks;
}

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

@Test
public void testNormalDistribution() {
    final double requiredPrecision = 1E-10;

    final Normal n = new Normal(0.0, 1.0, null);
    for (final double mu : new double[] { -5.0, -3.2, -1.5, 0.0, 1.2, 3.0, 5.8977 }) {
        for (final double sigma : new double[] { 1.2, 3.0, 5.8977 }) {
            for (final double x : new double[] { -5.0, -3.2, -1.5, 0.0, 1.2, 3.0, 5.8977 }) {
                n.setState(mu, sigma);//ww w  .j a v a2  s  . c  om
                Assert.assertEquals(n.pdf(x), MathUtils.normalDistribution(mu, sigma, x), requiredPrecision);
                Assert.assertEquals(Math.log10(n.pdf(x)), MathUtils.normalDistributionLog10(mu, sigma, x),
                        requiredPrecision);
            }
        }
    }
}

From source file:de.Keyle.MyPet.skill.skills.Beacon.java

public void schedule() {
    if (myPet.getStatus() == MyPet.PetState.Here && isActive() && active && selectedBuffs.size() != 0
            && --beaconTimer <= 0) {
        beaconTimer = 2;//www . ja va  2s.  co  m

        double range = this.range * (Math.log10(myPet.getSaturation()) / 2);

        if (range < 0.7) {
            active = false;
            selectedBuffs.clear();
        }

        range = range * range;

        if (selectedBuffs.size() > selectableBuffs) {
            int usableBuff = 0;
            for (int buff : selectedBuffs) {
                if (buffLevel.get(buff) > 0) {
                    usableBuff = buff;
                }
            }
            selectedBuffs.clear();
            if (usableBuff != 0) {
                selectedBuffs.add(usableBuff);
            }
        }

        if (selectedBuffs.size() == 0) {
            return;
        }

        MyPetApi.getPlatformHelper().playParticleEffect(myPet.getLocation().get().add(0, 1, 0), "SPELL_WITCH",
                0.2F, 0.2F, 0.2F, 0.1F, 5, 20);

        List<Player> members = null;
        if (Configuration.Skilltree.Skill.Beacon.PARTY_SUPPORT && receiver == BeaconReceiver.Party) {
            members = MyPetApi.getHookHelper().getPartyMembers(getMyPet().getOwner().getPlayer());
        }
        int duration = this.duration * 20;

        List<PotionEffect> potionEffects = new ArrayList<>();
        for (int buff : selectedBuffs) {
            int amplification = buffLevel.get(buff) - 1;
            PotionEffect effect = new PotionEffect(PotionEffectType.getById(buff), duration, amplification,
                    true, true);
            potionEffects.add(effect);
        }

        Location myPetLocation = this.myPet.getLocation().get();
        targetLoop: for (Player player : myPetLocation.getWorld().getPlayers()) {
            if (MyPetApi.getPlatformHelper().distanceSquared(player.getLocation(), myPetLocation) > range) {
                continue;
            }

            switch (receiver) {
            case Owner:
                if (!myPet.getOwner().equals(player)) {
                    continue targetLoop;
                } else {
                    for (PotionEffect effect : potionEffects) {
                        player.addPotionEffect(effect, true);
                    }
                    MyPetApi.getPlatformHelper().playParticleEffect(player.getLocation().add(0, 1, 0),
                            "SPELL_INSTANT", 0.2F, 0.2F, 0.2F, 0.1F, 5, 20);
                    break targetLoop;
                }
            case Everyone:
                for (PotionEffect effect : potionEffects) {
                    player.addPotionEffect(effect, true);
                }
                MyPetApi.getPlatformHelper().playParticleEffect(player.getLocation().add(0, 1, 0),
                        "SPELL_INSTANT", 0.2F, 0.2F, 0.2F, 0.1F, 5, 20);
                break;
            case Party:
                if (Configuration.Skilltree.Skill.Beacon.PARTY_SUPPORT && members != null) {
                    if (members.contains(player)) {
                        for (PotionEffect effect : potionEffects) {
                            player.addPotionEffect(effect, true);
                        }
                        MyPetApi.getPlatformHelper().playParticleEffect(player.getLocation().add(0, 1, 0),
                                "SPELL_INSTANT", 0.2F, 0.2F, 0.2F, 0.1F, 5, 20);
                    }
                    break;
                } else {
                    receiver = BeaconReceiver.Owner;
                    break targetLoop;
                }
            }
        }

        if (Configuration.Skilltree.Skill.Beacon.HUNGER_DECREASE_TIME > 0 && hungerDecreaseTimer-- < 0) {
            myPet.decreaseSaturation(1);
            hungerDecreaseTimer = Configuration.Skilltree.Skill.Beacon.HUNGER_DECREASE_TIME;
        }
    }
}

From source file:com.inmobi.ultrapush.AnalyzeActivity.java

private void refreshRMSLabel() {
    textRMS.setLength(0);// w  w  w.ja v  a 2  s.  c  o m
    textRMS.append("RMS:dB \n");
    SBNumFormat.fillInNumFixedWidth(textRMS, 20 * Math.log10(dtRMSFromFT), 3, 1);
    textRMS.getChars(0, Math.min(textRMS.length(), textRMSChar.length), textRMSChar, 0);

    TextView tv = (TextView) findViewById(R.id.textview_RMS);
    tv.setText(textRMSChar, 0, textRMSChar.length);
    tv.invalidate();
}

From source file:org.broadinstitute.gatk.tools.walkers.cancer.m2.SomaticGenotypingEngine.java

/** Calculate the likelihoods of hom ref and each het genotype of the form ref/alt
 *
 * @param mergedVC                              input VC
 * @param tumorPRALM                            read likelihoods
 * @param originalNormalMQs                     original MQs, before boosting normals to avoid qual capping
 * @param alleleFractions                       allele fraction(s) for alternate allele(s)
 *
 * @return                                      genotype likelihoods for homRef and het for each alternate allele
 *///from w w  w.ja v  a 2 s. c om
private PerAlleleCollection<Double> getHetGenotypeLogLikelihoods(final VariantContext mergedVC,
        final PerReadAlleleLikelihoodMap tumorPRALM, final Map<String, Integer> originalNormalMQs,
        final PerAlleleCollection<Double> alleleFractions) {
    // make sure that alleles in alleleFraction are a subset of alleles in the variant context
    if (!mergedVC.getAlternateAlleles().containsAll(alleleFractions.getAltAlleles())) {
        throw new IllegalArgumentException("alleleFractions has alleles that are not in the variant context");
    }

    final PerAlleleCollection<MutableDouble> genotypeLogLikelihoods = PerAlleleCollection
            .createPerRefAndAltAlleleCollection();
    mergedVC.getAlleles().forEach(a -> genotypeLogLikelihoods.set(a, new MutableDouble(0)));

    final Allele refAllele = mergedVC.getReference();
    for (Map.Entry<GATKSAMRecord, Map<Allele, Double>> readAlleleLikelihoodMap : tumorPRALM
            .getLikelihoodReadMap().entrySet()) {
        final Map<Allele, Double> alleleLikelihoodMap = readAlleleLikelihoodMap.getValue();
        if (originalNormalMQs.get(readAlleleLikelihoodMap.getKey().getReadName()) == 0) {
            continue;
        }

        final double readRefLogLikelihood = alleleLikelihoodMap.get(refAllele);
        genotypeLogLikelihoods.getRef().add(readRefLogLikelihood);

        for (final Allele altAllele : alleleFractions.getAltAlleles()) {
            final double readAltLogLikelihood = alleleLikelihoodMap.get(altAllele);
            final double adjustedReadAltLL = Math
                    .log10(Math.pow(10, readRefLogLikelihood) * (1 - alleleFractions.getAlt(altAllele))
                            + Math.pow(10, readAltLogLikelihood) * alleleFractions.getAlt(altAllele));
            genotypeLogLikelihoods.get(altAllele).add(adjustedReadAltLL);
        }

    }

    final PerAlleleCollection<Double> result = PerAlleleCollection.createPerRefAndAltAlleleCollection();
    mergedVC.getAlleles().stream().forEach(a -> result.set(a, genotypeLogLikelihoods.get(a).toDouble()));

    return result;
}

From source file:de.bund.bfr.knime.pmm.common.chart.Plotable.java

public static Double transform(Double value, String transform) {
    if (value == null) {
        return null;
    } else if (transform.equals(ChartConstants.NO_TRANSFORM)) {
        return value;
    } else if (transform.equals(ChartConstants.SQRT_TRANSFORM)) {
        return Math.sqrt(value);
    } else if (transform.equals(ChartConstants.LOG_TRANSFORM)) {
        return Math.log(value);
    } else if (transform.equals(ChartConstants.LOG10_TRANSFORM)) {
        return Math.log10(value);
    } else if (transform.equals(ChartConstants.EXP_TRANSFORM)) {
        return Math.exp(value);
    } else if (transform.equals(ChartConstants.EXP10_TRANSFORM)) {
        return Math.pow(10.0, value);
    } else if (transform.equals(ChartConstants.DIVX_TRANSFORM)) {
        return 1 / value;
    } else if (transform.equals(ChartConstants.DIVX2_TRANSFORM)) {
        return 1 / value / value;
    }//from   w ww.  jav  a 2 s  .  c om

    return null;
}

From source file:Model.MultiPlatformLDA.java

private void inferPostTopic() {
    for (int u = 0; u < users.length; u++) {
        for (int j = 0; j < users[u].posts.length; j++) {
            users[u].posts[j].inferedTopic = -1;// background topic only
            users[u].posts[j].inferedLikelihood = users[u].posts.length * Math.log10(coinBias[0])
                    + getPostLikelihood(u, j, -1);

            for (int z = 0; z < nTopics; z++) {
                double p_z = getPostLikelihood(u, j, z);
                p_z += Math.log10(users[u].topicDistribution[z]);

                if (users[u].posts[j].inferedLikelihood < p_z) {
                    users[u].posts[j].inferedLikelihood = p_z;
                    users[u].posts[j].inferedTopic = z;
                }/*  www  .j a  v a  2  s.co  m*/
            }
        }
    }
}