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.broadinstitute.gatk.utils.MathUtilsUnitTest.java

@Test
public void testApproximateLog10SumLog10() {

    final double requiredPrecision = 1E-4;

    Assert.assertEquals(MathUtils.approximateLog10SumLog10(new double[] { 0.0 }), 0.0, requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(new double[] { -5.15 }), -5.15, requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(new double[] { 130.0 }), 130.0, requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(new double[] { -0.145 }), -0.145, requiredPrecision);

    Assert.assertEquals(MathUtils.approximateLog10SumLog10(0.0, 0.0),
            Math.log10(Math.pow(10.0, 0.0) + Math.pow(10.0, 0.0)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(-1.0, 0.0),
            Math.log10(Math.pow(10.0, -1.0) + Math.pow(10.0, 0.0)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(0.0, -1.0),
            Math.log10(Math.pow(10.0, 0.0) + Math.pow(10.0, -1.0)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(-2.2, -3.5),
            Math.log10(Math.pow(10.0, -2.2) + Math.pow(10.0, -3.5)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(-1.0, -7.1),
            Math.log10(Math.pow(10.0, -1.0) + Math.pow(10.0, -7.1)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(5.0, 6.2),
            Math.log10(Math.pow(10.0, 5.0) + Math.pow(10.0, 6.2)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(38.1, 16.2),
            Math.log10(Math.pow(10.0, 38.1) + Math.pow(10.0, 16.2)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(-38.1, 6.2),
            Math.log10(Math.pow(10.0, -38.1) + Math.pow(10.0, 6.2)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(-19.1, -37.1),
            Math.log10(Math.pow(10.0, -19.1) + Math.pow(10.0, -37.1)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(-29.1, -27.6),
            Math.log10(Math.pow(10.0, -29.1) + Math.pow(10.0, -27.6)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(-0.12345, -0.23456),
            Math.log10(Math.pow(10.0, -0.12345) + Math.pow(10.0, -0.23456)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(-15.7654, -17.0101),
            Math.log10(Math.pow(10.0, -15.7654) + Math.pow(10.0, -17.0101)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(-0.12345, Double.NEGATIVE_INFINITY), -0.12345,
            requiredPrecision);//from   w ww  .j  a v a 2s. co  m
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(-15.7654, Double.NEGATIVE_INFINITY), -15.7654,
            requiredPrecision);

    Assert.assertEquals(MathUtils.approximateLog10SumLog10(new double[] { 0.0, 0.0 }),
            Math.log10(Math.pow(10.0, 0.0) + Math.pow(10.0, 0.0)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(new double[] { -1.0, 0.0 }),
            Math.log10(Math.pow(10.0, -1.0) + Math.pow(10.0, 0.0)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(new double[] { 0.0, -1.0 }),
            Math.log10(Math.pow(10.0, 0.0) + Math.pow(10.0, -1.0)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(new double[] { -2.2, -3.5 }),
            Math.log10(Math.pow(10.0, -2.2) + Math.pow(10.0, -3.5)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(new double[] { -1.0, -7.1 }),
            Math.log10(Math.pow(10.0, -1.0) + Math.pow(10.0, -7.1)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(new double[] { 5.0, 6.2 }),
            Math.log10(Math.pow(10.0, 5.0) + Math.pow(10.0, 6.2)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(new double[] { 38.1, 16.2 }),
            Math.log10(Math.pow(10.0, 38.1) + Math.pow(10.0, 16.2)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(new double[] { -38.1, 6.2 }),
            Math.log10(Math.pow(10.0, -38.1) + Math.pow(10.0, 6.2)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(new double[] { -19.1, -37.1 }),
            Math.log10(Math.pow(10.0, -19.1) + Math.pow(10.0, -37.1)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(new double[] { -29.1, -27.6 }),
            Math.log10(Math.pow(10.0, -29.1) + Math.pow(10.0, -27.6)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(new double[] { -0.12345, -0.23456 }),
            Math.log10(Math.pow(10.0, -0.12345) + Math.pow(10.0, -0.23456)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(new double[] { -15.7654, -17.0101 }),
            Math.log10(Math.pow(10.0, -15.7654) + Math.pow(10.0, -17.0101)), requiredPrecision);

    Assert.assertEquals(MathUtils.approximateLog10SumLog10(new double[] { 0.0, 0.0, 0.0 }),
            Math.log10(Math.pow(10.0, 0.0) + Math.pow(10.0, 0.0) + Math.pow(10.0, 0.0)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(new double[] { -1.0, 0.0, 0.0 }),
            Math.log10(Math.pow(10.0, -1.0) + Math.pow(10.0, 0.0) + Math.pow(10.0, 0.0)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(new double[] { 0.0, -1.0, -2.5 }),
            Math.log10(Math.pow(10.0, 0.0) + Math.pow(10.0, -1.0) + Math.pow(10.0, -2.5)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(new double[] { -2.2, -3.5, -1.1 }),
            Math.log10(Math.pow(10.0, -2.2) + Math.pow(10.0, -3.5) + Math.pow(10.0, -1.1)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(new double[] { -1.0, -7.1, 0.5 }),
            Math.log10(Math.pow(10.0, -1.0) + Math.pow(10.0, -7.1) + Math.pow(10.0, 0.5)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(new double[] { 5.0, 6.2, 1.3 }),
            Math.log10(Math.pow(10.0, 5.0) + Math.pow(10.0, 6.2) + Math.pow(10.0, 1.3)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(new double[] { 38.1, 16.2, 18.1 }),
            Math.log10(Math.pow(10.0, 38.1) + Math.pow(10.0, 16.2) + Math.pow(10.0, 18.1)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(new double[] { -38.1, 6.2, 26.6 }),
            Math.log10(Math.pow(10.0, -38.1) + Math.pow(10.0, 6.2) + Math.pow(10.0, 26.6)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(new double[] { -19.1, -37.1, -45.1 }),
            Math.log10(Math.pow(10.0, -19.1) + Math.pow(10.0, -37.1) + Math.pow(10.0, -45.1)),
            requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(new double[] { -29.1, -27.6, -26.2 }),
            Math.log10(Math.pow(10.0, -29.1) + Math.pow(10.0, -27.6) + Math.pow(10.0, -26.2)),
            requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(new double[] { -0.12345, -0.23456, -0.34567 }),
            Math.log10(Math.pow(10.0, -0.12345) + Math.pow(10.0, -0.23456) + Math.pow(10.0, -0.34567)),
            requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(new double[] { -15.7654, -17.0101, -17.9341 }),
            Math.log10(Math.pow(10.0, -15.7654) + Math.pow(10.0, -17.0101) + Math.pow(10.0, -17.9341)),
            requiredPrecision);

    Assert.assertEquals(MathUtils.approximateLog10SumLog10(0.0, 0.0, 0.0),
            Math.log10(Math.pow(10.0, 0.0) + Math.pow(10.0, 0.0) + Math.pow(10.0, 0.0)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(-1.0, 0.0, 0.0),
            Math.log10(Math.pow(10.0, -1.0) + Math.pow(10.0, 0.0) + Math.pow(10.0, 0.0)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(0.0, -1.0, -2.5),
            Math.log10(Math.pow(10.0, 0.0) + Math.pow(10.0, -1.0) + Math.pow(10.0, -2.5)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(-2.2, -3.5, -1.1),
            Math.log10(Math.pow(10.0, -2.2) + Math.pow(10.0, -3.5) + Math.pow(10.0, -1.1)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(-1.0, -7.1, 0.5),
            Math.log10(Math.pow(10.0, -1.0) + Math.pow(10.0, -7.1) + Math.pow(10.0, 0.5)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(5.0, 6.2, 1.3),
            Math.log10(Math.pow(10.0, 5.0) + Math.pow(10.0, 6.2) + Math.pow(10.0, 1.3)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(38.1, 16.2, 18.1),
            Math.log10(Math.pow(10.0, 38.1) + Math.pow(10.0, 16.2) + Math.pow(10.0, 18.1)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(-38.1, 6.2, 26.6),
            Math.log10(Math.pow(10.0, -38.1) + Math.pow(10.0, 6.2) + Math.pow(10.0, 26.6)), requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(-19.1, -37.1, -45.1),
            Math.log10(Math.pow(10.0, -19.1) + Math.pow(10.0, -37.1) + Math.pow(10.0, -45.1)),
            requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(-29.1, -27.6, -26.2),
            Math.log10(Math.pow(10.0, -29.1) + Math.pow(10.0, -27.6) + Math.pow(10.0, -26.2)),
            requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(-0.12345, -0.23456, -0.34567),
            Math.log10(Math.pow(10.0, -0.12345) + Math.pow(10.0, -0.23456) + Math.pow(10.0, -0.34567)),
            requiredPrecision);
    Assert.assertEquals(MathUtils.approximateLog10SumLog10(-15.7654, -17.0101, -17.9341),
            Math.log10(Math.pow(10.0, -15.7654) + Math.pow(10.0, -17.0101) + Math.pow(10.0, -17.9341)),
            requiredPrecision);

    // magnitude of the sum doesn't matter, so we can combinatorially test this via partitions of unity
    double[] mult_partitionFactor = new double[] { 0.999, 0.98, 0.95, 0.90, 0.8, 0.5, 0.3, 0.1, 0.05, 0.001 };
    int[] n_partitions = new int[] { 2, 4, 8, 16, 32, 64, 128, 256, 512, 1028 };
    for (double alpha : mult_partitionFactor) {
        double log_alpha = Math.log10(alpha);
        double log_oneMinusAlpha = Math.log10(1 - alpha);
        for (int npart : n_partitions) {
            double[] multiplicative = new double[npart];
            double[] equal = new double[npart];
            double remaining_log = 0.0; // realspace = 1
            for (int i = 0; i < npart - 1; i++) {
                equal[i] = -Math.log10(npart);
                double piece = remaining_log + log_alpha; // take a*remaining, leaving remaining-a*remaining = (1-a)*remaining
                multiplicative[i] = piece;
                remaining_log = remaining_log + log_oneMinusAlpha;
            }
            equal[npart - 1] = -Math.log10(npart);
            multiplicative[npart - 1] = remaining_log;
            Assert.assertEquals(MathUtils.approximateLog10SumLog10(equal), 0.0, requiredPrecision,
                    String.format("Did not sum to one: k=%d equal partitions.", npart));
            Assert.assertEquals(MathUtils.approximateLog10SumLog10(multiplicative), 0.0, requiredPrecision,
                    String.format("Did not sum to one: k=%d multiplicative partitions with alpha=%f", npart,
                            alpha));
        }
    }
}

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

private List getAllTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
    // TODO Auto-generated method stub
    List ticks = new java.util.ArrayList();
    Range range = getRange();/* w w w  .ja v  a2s  . c o  m*/

    //get lower bound value:
    double lowerBoundVal = range.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;
    }

    //get upper bound value
    double upperBoundVal = range.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
    if (iBegCount == iEndCount && 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 currentTickValue;
    String tickLabel;
    boolean zeroTickFlag = false;
    for (int i = iBegCount; i <= iEndCount; i++) {
        //for each power of 10 value; create ten ticks
        for (int j = 0; j < 10; ++j) {
            //for each tick to be displayed
            if (this.smallLogFlag) {
                //small log values in use; create numeric value for tick
                currentTickValue = Math.pow(10, i) + (Math.pow(10, i) * j);
                if (this.expTickLabelsFlag || (i < 0 && currentTickValue > 0.0 && currentTickValue < 1.0)) {
                    //showing "1e#"-style ticks or negative exponent
                    // generating tick value between 0 & 1; show fewer
                    //first tick of series, or not too small a value and
                    // one of first 3 ticks, or last tick to be displayed
                    // set exact number of fractional digits to be shown
                    // (no effect if showing "1e#"-style ticks):
                    this.numberFormatterObj.setMaximumFractionDigits(-i);
                    //create tick label (force use of fmt obj):
                    tickLabel = makeTickLabel(currentTickValue, true);
                } else { //tick value not between 0 & 1
                         //show tick label if it's the first or last in
                         // the set, or if it's 1-5; beyond that show
                         // fewer as the values get larger:
                    tickLabel = makeTickLabel(currentTickValue);
                }
            } 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
                } //calculate power-of-ten value for tick:
                currentTickValue = (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 (Math.abs(currentTickValue - 1.0) < 0.0001 && lowerBoundVal <= 0.0
                            && upperBoundVal >= 0.0) {
                        //tick value is 1.0 and 0.0 is within data range
                        currentTickValue = 0.0; //set tick value to zero
                        zeroTickFlag = true; //indicate zero tick
                    }
                } else { //did zero tick last iteration
                    zeroTickFlag = false; //clear flag
                } //create tick label string:
                //show tick label if "1e#"-style and it's one
                // of the first two, if it's the first or last
                // in the set, or if it's 1-5; beyond that
                // show fewer as the values get larger:
                tickLabel = makeTickLabel(currentTickValue);
            }

            if (currentTickValue > 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)));
                    }
                    if (definition < 2 * Math.pow(10, -numberOfDigits)) {
                        numberOfDigits++;
                    }
                    double tickVal;
                    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.TOP_CENTER,
                            TextAnchor.TOP_CENTER, 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.TOP_CENTER,
                            TextAnchor.TOP_CENTER, 0.0));
                }
                return ticks; // if past highest data value then exit
                              // method
            }

            if (currentTickValue >= lowerBoundVal - SMALL_LOG_VALUE) {
                //tick value not below lowest data value
                TextAnchor anchor = null;
                TextAnchor rotationAnchor = null;
                double angle = 0.0;
                if (isVerticalTickLabels()) {
                    anchor = TextAnchor.CENTER_RIGHT;
                    rotationAnchor = TextAnchor.CENTER_RIGHT;
                    if (edge == RectangleEdge.TOP) {
                        angle = Math.PI / 2.0;
                    } else {
                        angle = -Math.PI / 2.0;
                    }
                } else {
                    if (edge == RectangleEdge.TOP) {
                        anchor = TextAnchor.BOTTOM_CENTER;
                        rotationAnchor = TextAnchor.BOTTOM_CENTER;
                    } else {
                        anchor = TextAnchor.TOP_CENTER;
                        rotationAnchor = TextAnchor.TOP_CENTER;
                    }
                }

                lastTick = new NumberTick(new Double(currentTickValue), 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)));
        }
        double tickVal;
        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.TOP_CENTER, TextAnchor.TOP_CENTER,
                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.TOP_CENTER, TextAnchor.TOP_CENTER,
                0.0));
    }
    return ticks;
}

From source file:maltcms.ui.fileHandles.csv.CSVTableView.java

/**
 *
 * @param j/*w  w  w .ja va2s.  co  m*/
 * @param base
 */
public void logTransformColumn(int j, double base) {
    for (int i = 0; i < jTable1.getRowCount(); i++) {
        Object o = jTable1.getValueAt(i, j);
        if (o instanceof Double) {
            jTable1.setValueAt(Math.log10((Double) o) / Math.log10(base), i, j);
        } else if (o instanceof Float) {
            jTable1.setValueAt(Double.valueOf(Math.log10(((Double) o)) / Math.log10(base)).floatValue(), i, j);
        }
    }
}

From source file:org.nxtgenutils.bsseq.impl.MethylationProfiler.java

/**
 * @param profileRecord//from  www  .  j  a  v  a  2  s  .  c o m
 * @param conversionRate
 */
private void scoreProfileRecord(MethylationProfileRecord profileRecord, Map<String, Double> conversionRate) {

    for (MethylationProfileSampleRecord sampleRecord : profileRecord.getSampleRecords()) {

        double rate = conversionRate.get(sampleRecord.getSampleName());
        int score = -1;
        boolean rateGreateZero = false;
        if (rate > 0) {
            rateGreateZero = true;
            int trials = sampleRecord.getCtCoverage();
            int successes = sampleRecord.getCtCoverage() - sampleRecord.getCCount();
            BinomialDistribution bd = new BinomialDistributionImpl(trials, rate);
            double p = -1;
            try {

                // BinomialDistributionImpl does return 0 of the p value is >10^-16.
                // In this case we will assign a score of 161 which is one more then
                // the maximum score that can be calculated from the p values returned
                // by BinomialDistributionImpl and equivivalent to a p-value of 8.9 * 10^-17
                p = bd.cumulativeProbability(successes);
                if (p == 0.0) {
                    score = 161;
                } else {
                    score = (int) Math.round(-10 * Math.log10(p));
                }

            } catch (MathException e) {
                logger.error("Exception while scoring methylation level.", e);
            }
            if (score == -1) {
                logger.error(sampleRecord.getCCount() + "\t" + sampleRecord.getCtCoverage() + "\t" + rate + "\t"
                        + score + "\t" + rateGreateZero + "\t" + successes + "\t" + trials + "\t" + p);
            }
        }
        sampleRecord.setScore(score);

    }

}

From source file:org.easyrec.plugin.arm.impl.AssocRuleMiningServiceImpl.java

@Override
public Collection<SortedSet<ItemAssocVO<Integer, Integer>>> createBestRules(List<TupleVO> tuples,
        TObjectIntHashMap<ItemVO<Integer, Integer>> L1, ARMConfigurationInt configuration, ARMStatistics stats,
        Double minConfidence) {/*from   www . j  a va2 s  .c  o m*/
    // Integer h1, h2;
    Double dh1, dh2;

    Integer sup1, sup2;
    Double dsup1, dsup2, assocValue1, assocValue2;

    Double baskets = new Double(stats.getNrBaskets());
    stats.setMetricType(configuration.getMetricType());
    //Vector<ItemAssocVO<Integer,Integer>> ret = new Vector<ItemAssocVO<Integer,Integer>>();
    Map<ItemVO<Integer, Integer>, SortedSet<ItemAssocVO<Integer, Integer>>> ret = new HashMap<>();
    for (TupleVO tuple : tuples) {
        sup1 = L1.get(tuple.getItem1());
        dsup1 = new Double(sup1);
        sup2 = L1.get(tuple.getItem2());
        dsup2 = new Double(sup2);
        if (sup1 == null || sup2 == null) {
            continue;
        }
        // confidence
        //          h1 = (tuple.getSupport() * 100) / sup1;
        //          h2 = (tuple.getSupport() * 100) / sup2;

        // confidence
        dh1 = (tuple.getSupport() * 100) / dsup1;
        dh2 = (tuple.getSupport() * 100) / dsup2;

        // lift
        Double lift = tuple.getSupport() / (dsup1 * dsup2);

        // conviction
        Double conviction1 = (1 - (dsup2 / baskets)) / (100 - dh1);
        Double conviction2 = (1 - (dsup1 / baskets)) / (100 - dh2);

        // ltc
        Double ltc1 = dsup1 * Math.log10(dsup1 / dsup2);
        Double ltc2 = dsup2 * Math.log10(dsup2 / dsup1);

        switch (configuration.getMetricType()) {
        case CONFIDENCE:
            assocValue1 = dh1;
            assocValue2 = dh2;
            break;
        case CONVICTION:
            assocValue1 = conviction1;
            assocValue2 = conviction2;
            break;
        case LIFT:
            assocValue1 = lift;
            assocValue2 = lift;
            break;
        case LONGTAIL:
            assocValue1 = ltc1;
            assocValue2 = ltc2;
            break;
        default:
            assocValue1 = dh1;
            assocValue2 = dh2;
            break;
        }

        //          public ItemAssocVO(T tenant, ItemVO<T, I, IT> itemFrom, AT assocType,
        //                          Double assocValue, ItemVO<T, I, IT> itemTo, ST sourceType,
        //                          String sourceInfo, VT viewType, Boolean active)

        if (dh1 >= (minConfidence)) {

            SortedSet<ItemAssocVO<Integer, Integer>> bestRules = ret.get(tuple.getItem1());
            if (bestRules == null) {
                bestRules = new TreeSet<>();
            }
            if ((bestRules.size() < configuration.getMaxRulesPerItem())
                    || (assocValue1 > bestRules.first().getAssocValue())) { // no need to create objects if limit already reached and rule shows worse quality
                String comment1 = null;
                if (configuration.getStoreAlternativeMetrics()) {
                    comment1 = new StringBuilder("conf=").append(String.format("%04f", dh1)).append(" lift=")
                            .append(String.format("%04f", lift)).append(" convic=")
                            .append(String.format("%04f", conviction1)).append(" ltc=")
                            .append(String.format("%04f", ltc1)).append(" sup1=")
                            .append(String.format("%04f", dsup1)).append(" sup2=")
                            .append(String.format("%04f", dsup2)).append(" tsup=").append(tuple.getSupport())
                            .toString();
                }
                ItemAssocVO<Integer, Integer> rule = new ItemAssocVO<>(configuration.getTenantId(),
                        tuple.getItem1(), configuration.getAssocType(), assocValue1
                        /*new Double(h1)*/, tuple.getItem2(),
                        typeMappingService.getIdOfSourceType(configuration.getTenantId(),
                                ARMGenerator.ID.toString() + "/" + ARMGenerator.VERSION),
                        comment1, typeMappingService.getIdOfViewType(configuration.getTenantId(),
                                TypeMappingService.VIEW_TYPE_COMMUNITY),
                        true, stats.getStartDate());

                bestRules.add(rule);
                if (bestRules.size() > configuration.getMaxRulesPerItem()) {
                    bestRules.remove(bestRules.first());
                }
                ret.put(tuple.getItem1(), bestRules);
            }
        }

        if (dh2 >= (minConfidence)) {

            SortedSet<ItemAssocVO<Integer, Integer>> bestRules = ret.get(tuple.getItem2());
            if (bestRules == null) {
                bestRules = new TreeSet<>();
            }
            if ((bestRules.size() < configuration.getMaxRulesPerItem())
                    || (assocValue2 > bestRules.first().getAssocValue())) { // no need to create objects if limit already reached and rule shows worse quality
                String comment2 = null;
                if (configuration.getStoreAlternativeMetrics()) {
                    comment2 = new StringBuilder("conf=").append(String.format("%04f", dh2)).append(" lift=")
                            .append(String.format("%04f", lift)).append(" convic=")
                            .append(String.format("%04f", conviction2)).append(" ltc=")
                            .append(String.format("%04f", ltc2)).append(" sup2=")
                            .append(String.format("%04f", dsup2)).append(" sup1=")
                            .append(String.format("%04f", dsup1)).append(" tsup=").append(tuple.getSupport())
                            .toString();
                }
                ItemAssocVO<Integer, Integer> rule = new ItemAssocVO<>(configuration.getTenantId(),
                        tuple.getItem2(), configuration.getAssocType(), assocValue2
                        /*new Double(h2)*/, tuple.getItem1(),
                        typeMappingService.getIdOfSourceType(configuration.getTenantId(),
                                ARMGenerator.ID.toString() + "/" + ARMGenerator.VERSION),
                        comment2, typeMappingService.getIdOfViewType(configuration.getTenantId(),
                                TypeMappingService.VIEW_TYPE_COMMUNITY),
                        true, stats.getStartDate());
                bestRules.add(rule);
                if (bestRules.size() > configuration.getMaxRulesPerItem()) {
                    bestRules.remove(bestRules.first());
                }
                ret.put(tuple.getItem2(), bestRules);
            }
        }
    }
    return ret.values();
}

From source file:org.broadinstitute.gatk.tools.walkers.cancer.contamination.ContaminationResults.java

/**
 * output the contamination data, and return the contamination data
 * @param out the output source/*from  w ww .  j  a  v  a  2  s  .co m*/
 * @return the contamination value
 */
public void outputReport(double precision, PrintStream out, double fractionToTrim, double trimInterval,
        double betaThreshold) {
    out.println(
            "name\tpopulation\tpopulation_fit\tcontamination\tconfidence_interval_95_width\tconfidence_interval_95_low\tconfidence_interval_95_high\tsites");

    for (Map.Entry<String, Map<String, ContaminationStats>> entry : stats.entrySet()) {
        for (ContaminationStats stats : entry.getValue().values()) {
            String aggregationLevel = entry.getKey();
            String population = stats.getContamination().getPopultationName();

            List<ContaminationData> newStats = storedData.get(aggregationLevel).get(population);
            String pm = "%3." + Math.round(Math.log10(1 / precision)) + "f";

            int bins = newStats.iterator().next().getBins().length;
            int maxTrim = (int) Math.floor((double) (newStats.size()) * fractionToTrim);

            // sort the collection
            Collections.sort(newStats);

            List<ContaminationData> data = new ArrayList<ContaminationData>(newStats);

            // trim sites with > 95% p of being > 0.5 f (based on beta distribution)
            int trimmed = 0;
            for (Iterator<ContaminationData> i = data.iterator(); trimmed < maxTrim && i.hasNext();) {
                ContaminationData x = i.next();
                if (x.getP() >= betaThreshold) {
                    System.out.println("Trimming " + x.toString() + " with p(f>=0.5) >= " + betaThreshold
                            + " with a value of  " + x.getP());
                    i.remove();
                    trimmed++;
                }
            }

            double[][] matrix = new double[bins][data.size()];

            for (int i = 0; i < bins; i++) {
                for (int j = 0; j < data.size(); j++) {
                    matrix[i][j] = data.get(j).getBins()[i];
                }
            }

            // now perform the sum
            double[] output = new double[bins];
            for (int i = 0; i < bins; i++) {
                double[] binData = matrix[i];

                // remove the top and bottom
                output[i] = 0;
                for (int x = 0; x < binData.length; x++) {
                    output[i] += binData[x];
                }
            }
            double[] newTrimmedStats = output;

            // get the confidence interval, at the set width
            ContaminationEstimate.ConfidenceInterval newInterval = new ContaminationEstimate.ConfidenceInterval(
                    newTrimmedStats, 0.95);

            out.println(String.format("%s\t%s\t%s\t" + pm + "\t" + pm + "\t" + pm + "\t" + pm + "\t" + "%d",
                    aggregationLevel, population, "n/a", newInterval.getContamination(),
                    (newInterval.getStop() - newInterval.getStart()), newInterval.getStart(),
                    newInterval.getStop(), data.size()));

        }
    }
}

From source file:org.esa.s1tbx.calibration.gpf.calibrators.CosmoSkymedCalibrator.java

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;/*ww  w  .  ja  va2 s  .  co  m*/
    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 tgtBandUnit = Unit.getUnitType(targetBand);
    final Unit.UnitType srcBandUnit = Unit.getUnitType(sourceBand1);

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

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

    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, dn2, i, q, phaseTerm = 0.0;
    int srcIdx, tgtIdx;
    final double powFactor = FastMath.pow(referenceSlantRange, 2 * referenceSlantRangeExp);
    final double sinRefIncidenceAngle = FastMath.sin(referenceIncidenceAngle);
    final double rescaleCalFactor = rescalingFactor * rescalingFactor * Ks;

    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 (srcBandUnit == Unit.UnitType.AMPLITUDE) {
                dn = srcData1.getElemDoubleAt(srcIdx);
                dn2 = dn * dn;
            } else if (srcBandUnit == Unit.UnitType.INTENSITY) {
                dn2 = srcData1.getElemDoubleAt(srcIdx);
            } else if (srcBandUnit == Unit.UnitType.REAL) {
                i = srcData1.getElemDoubleAt(srcIdx);
                q = srcData2.getElemDoubleAt(srcIdx);
                dn2 = i * i + q * q;
                if (tgtBandUnit == Unit.UnitType.REAL) {
                    phaseTerm = i / Math.sqrt(dn2);
                } else if (tgtBandUnit == Unit.UnitType.IMAGINARY) {
                    phaseTerm = q / Math.sqrt(dn2);
                }
            } else if (srcBandUnit == Unit.UnitType.INTENSITY_DB) {
                dn2 = FastMath.pow(10, srcData1.getElemDoubleAt(srcIdx) / 10.0); // convert dB to linear scale
            } else {
                throw new OperatorException("CosmoSkymed Calibration: unhandled unit");
            }

            double calFactor = 1.0;
            if (applyRangeSpreadingLossCorrection)
                calFactor *= powFactor;

            if (applyIncidenceAngleCorrection)
                calFactor *= sinRefIncidenceAngle;

            calFactor /= rescaleCalFactor;

            sigma = dn2 * calFactor;

            if (isComplex && outputImageInComplex) {
                sigma = Math.sqrt(sigma) * phaseTerm;
            }

            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:org.ut.biolab.medsavant.client.view.genetics.charts.SummaryChart.java

private void addEntriesToChart(DefaultChartModel chartModel, ChartFrequencyMap chartMap,
        List<ChartCategory> chartCategories, List<Highlight> highlights) {

    boolean addHighlights = highlights != null;

    int index = 0;
    for (ChartCategory cat : chartCategories) {

        FrequencyEntry fe = chartMap.getEntry(cat.getName());
        long value = 0;
        if (fe != null) {
            value = fe.getFrequency();/*from   ww w  .ja v a 2 s .  c om*/
        }

        ChartPoint p = new ChartPoint(cat, value);
        ChartPoint logp = new ChartPoint(cat, Math.log10(value));

        if (addHighlights) {
            p.setHighlight(highlights.get(index));
            logp.setHighlight(highlights.get(index));
        }

        if (this.isLogScaleY()) {
            chartModel.addPoint(logp);
        } else {
            chartModel.addPoint(p);
        }

        index++;
    }
}

From source file:fr.gael.dhus.server.http.valve.processings.ProcessingValve.java

public static String formatSize(long size) {
    if (size <= 0) {
        return "0";
    }//w  w w  . jav  a2 s. c o  m
    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.broadinstitute.gatk.utils.MathUtils.java

/**
 * Calculate f(x) = log10 ( Normal(x | mu = mean, sigma = sd) )
 * @param mean the desired mean of the Normal distribution
 * @param sd the desired standard deviation of the Normal distribution
 * @param x the value to evaluate//from   w w  w.j a  v  a 2s  .com
 * @return a well-formed double
 */

public static double normalDistributionLog10(final double mean, final double sd, final double x) {
    if (sd < 0)
        throw new IllegalArgumentException("sd: Standard deviation of normal must be >0");
    if (!wellFormedDouble(mean) || !wellFormedDouble(sd) || !wellFormedDouble(x))
        throw new IllegalArgumentException(
                "mean, sd, or, x : Normal parameters must be well formatted (non-INF, non-NAN)");
    final double a = -1.0 * Math.log10(sd * SQUARE_ROOT_OF_TWO_TIMES_PI);
    final double b = -1.0 * (square(x - mean) / (2.0 * square(sd))) / NATURAL_LOG_OF_TEN;
    return a + b;
}