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.bmwcarit.barefoot.markov.KStateTest.java

@Test
public void TestTState() {
    Map<Integer, MockElem> elements = new HashMap<>();
    elements.put(0, new MockElem(0, Math.log10(0.3), 0.3, null));
    elements.put(1, new MockElem(1, Math.log10(0.2), 0.2, null));
    elements.put(2, new MockElem(2, Math.log10(0.5), 0.5, null));

    KState<MockElem, StateTransition, Sample> state = new KState<>(-1, 1);
    {//from  w w  w  . java 2  s .c  o m
        Set<MockElem> vector = new HashSet<>(Arrays.asList(elements.get(0), elements.get(1), elements.get(2)));

        state.update(vector, new Sample(0));

        assertEquals(3, state.size());
        assertEquals(2, state.estimate().numid());
    }

    elements.put(3, new MockElem(3, Math.log10(0.3), 0.3, elements.get(1)));
    elements.put(4, new MockElem(4, Math.log10(0.2), 0.2, elements.get(1)));
    elements.put(5, new MockElem(5, Math.log10(0.4), 0.4, elements.get(2)));
    elements.put(6, new MockElem(6, Math.log10(0.1), 0.1, elements.get(2)));

    {
        Set<MockElem> vector = new HashSet<>(
                Arrays.asList(elements.get(3), elements.get(4), elements.get(5), elements.get(6)));

        state.update(vector, new Sample(1));

        assertEquals(6, state.size());
        assertEquals(5, state.estimate().numid());

        List<Integer> sequence = new LinkedList<>(Arrays.asList(2, 5));
        for (int i = 0; i < state.sequence().size() - 1; ++i) {
            assertEquals(sequence.get(i).longValue(), state.sequence().get(i).numid());
        }
    }

    elements.put(7, new MockElem(7, Math.log10(0.3), 0.3, elements.get(5)));
    elements.put(8, new MockElem(8, Math.log10(0.2), 0.2, elements.get(5)));
    elements.put(9, new MockElem(9, Math.log10(0.4), 0.4, elements.get(6)));
    elements.put(10, new MockElem(10, Math.log10(0.1), 0.1, elements.get(6)));

    {
        Set<MockElem> vector = new HashSet<>(
                Arrays.asList(elements.get(7), elements.get(8), elements.get(9), elements.get(10)));

        state.update(vector, new Sample(2));

        assertEquals(6, state.size());
        assertEquals(9, state.estimate().numid());

        List<Integer> sequence = new LinkedList<>(Arrays.asList(6, 9));
        for (int i = 0; i < state.sequence().size() - 1; ++i) {
            assertEquals(sequence.get(i).longValue(), state.sequence().get(i).numid());
        }
    }

    elements.put(11, new MockElem(11, Math.log10(0.3), 0.3, null));
    elements.put(12, new MockElem(12, Math.log10(0.2), 0.2, null));
    elements.put(13, new MockElem(13, Math.log10(0.4), 0.4, null));
    elements.put(14, new MockElem(14, Math.log10(0.1), 0.1, null));

    {
        Set<MockElem> vector = new HashSet<>(
                Arrays.asList(elements.get(11), elements.get(12), elements.get(13), elements.get(14)));

        state.update(vector, new Sample(3));

        assertEquals(5, state.size());
        assertEquals(13, state.estimate().numid());

        List<Integer> sequence = new LinkedList<>(Arrays.asList(9, 13));
        for (int i = 0; i < state.sequence().size() - 1; ++i) {
            assertEquals(sequence.get(i).longValue(), state.sequence().get(i).numid());
        }
    }
    {
        Set<MockElem> vector = new HashSet<>();

        state.update(vector, new Sample(4));

        assertEquals(5, state.size());
        assertEquals(13, state.estimate().numid());

        List<Integer> sequence = new LinkedList<>(Arrays.asList(9, 13));
        for (int i = 0; i < state.sequence().size() - 1; ++i) {
            assertEquals(sequence.get(i).longValue(), state.sequence().get(i).numid());
        }
    }
}

From source file:com.mycom.products.mywebsite.backend.util.UploadHandler.java

private String getReadableFileSize(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.Radarsat2Calibrator.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./*w ww  .j  a va 2  s  .  c  om*/
 * @param targetTile The current tile associated with the target band to be computed.
 * @param pm         A progress monitor which should be used to determine computation cancelation requests.
 * @throws org.esa.beam.framework.gpf.OperatorException If an error occurs during computation of the target raster.
 */
public void computeTile(Band targetBand, Tile targetTile, ProgressMonitor pm) throws OperatorException {

    final Rectangle targetTileRectangle = targetTile.getRectangle();
    final int x0 = targetTileRectangle.x;
    final int y0 = targetTileRectangle.y;
    final int w = targetTileRectangle.width;
    final int h = targetTileRectangle.height;

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

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

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

    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);
                sigma = dn * dn;
            } else if (bandUnit == Unit.UnitType.INTENSITY) {
                sigma = srcData1.getElemDoubleAt(srcIdx);
            } else if (bandUnit == Unit.UnitType.REAL || bandUnit == Unit.UnitType.IMAGINARY) {
                if (outputImageInComplex) {
                    // the sigma below is actually i or q, we still call it sigma just for convenient
                    sigma = srcData1.getElemDoubleAt(srcIdx);
                } else {
                    i = srcData1.getElemDoubleAt(srcIdx);
                    q = srcData2.getElemDoubleAt(srcIdx);
                    sigma = i * i + q * q;
                }
            } else {
                throw new OperatorException("Calibration: unhandled unit");
            }

            if (isComplex) {
                if (gains != null) {
                    if (outputImageInComplex) {
                        sigma /= gains[x + subsetOffsetX];
                    } else {
                        sigma /= (gains[x + subsetOffsetX] * gains[x + subsetOffsetX]);
                    }
                }
            } else {
                sigma += offset;
                if (gains != null) {
                    sigma /= gains[x + subsetOffsetX];
                }
            }

            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:de.tudarmstadt.lt.lm.lucenebased.CountingStringLM.java

@Override
public double getNgramLogProbability(List<String> ngram) {
    // check length
    assert ngram/*from ww  w  .  j av a  2s.  c o  m*/
            .size() <= _order : "Length of Ngram must be lower or equal to the order of the language model.";
    if (ngram.size() < 1)
        return Double.NEGATIVE_INFINITY;

    // c(w_1 ... w_n)
    Long nominator = getQuantity(ngram);
    if (nominator == 0)
        return Double.NEGATIVE_INFINITY;

    // c(w_1) / N
    if (ngram.size() == 1)
        return Math.log10((double) nominator) - Math.log10(_num_ngrams[1][0]);

    // c(w_1 ... w_n-1)
    Long denominator = getQuantity(ngram.subList(0, ngram.size() - 1));

    if (denominator == 0)
        return Double.NEGATIVE_INFINITY;

    double logprob = Math.log10((double) nominator) - Math.log10((double) denominator);
    return logprob;
}

From source file:simulation.AureoZauleckAnsLab2.java

/**
 *
 *///from   w  ww  . java 2  s.c  o  m
public AureoZauleckAnsLab2() {
    // TODO code application logic here
    Scanner sc = new Scanner(System.in);
    String choice_s = "";
    int choice = 0;

    do {
        DisplayMenu();
        choice_s = sc.next();
        String title = "";
        Scanner s = new Scanner(System.in);
        //test input
        if (IsNumber(choice_s)) {
            choice = Convert(choice_s);
        } else {
            do {
                System.out.println("Please enter a number only.");
                choice_s = sc.next();
            } while (!IsNumber(choice_s));
            choice = Convert(choice_s);
        }

        if (choice == 1) {
            System.out.println("*** CATEGORICAL ***");
            System.out.println();
            System.out.println("TITLE(title of data set)");
            //sc = new Scanner(System.in);               
            title = s.nextLine();
            System.out.println("this is the title:  " + title);

            ArrayList a = new ArrayList<>();
            ArrayList<Double> percentages = new ArrayList<>();
            ArrayList<ArrayList> all;
            a = GetData();

            Collections.sort(a);
            all = Stratified(a);
            System.out.println("GROUPED DATA:  " + all);
            System.out.println("size  " + all.size());

            double percent = 0.0, sum = 0.0;
            for (int i = 0; i < all.size(); i++) {

                ArrayList inner = new ArrayList<>();
                inner = all.get(i);
                //System.out.println(inner);

                int inner_n = inner.size();
                percent = GetPercentage(N, inner_n);
                percentages.add(percent);
                sum += percent;
                System.out.println("" + inner.get(0) + "\t" + "        " + percent);
            }
            System.out.println("\t" + "total   " + Math.ceil(sum));
            System.out.println("all = " + all);

            JFrame frame = new JFrame();
            //frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);                        
            JTable table = new JTable();
            table.setModel(new DefaultTableModel((int) (all.size() + 2), 2));

            table.setValueAt("VALUE LABELS", 0, 0);
            table.setValueAt("PERCENTAGE", 0, 1);

            table.setValueAt("TOTAL = 100%", (int) (all.size() + 1), 1);

            for (int i = 0; i < all.size(); i++) {
                table.setValueAt(all.get(i).get(0), i + 1, 0);

                table.setValueAt(new DecimalFormat("#.##").format(percentages.get(i)), i + 1, 1);

            }

            JScrollPane scrollPane = new JScrollPane(table);
            scrollPane.setBorder(BorderFactory.createTitledBorder(title));
            frame.add(scrollPane, BorderLayout.CENTER);
            frame.setSize(300, 150);
            frame.setVisible(true);

            int type = 0, testT = 0;
            String typeTest = "";
            do {
                System.out.println("GENERATE GRAPH?");
                System.out.println("[1] YES");
                System.out.println("[2] NO");

                System.out.println();
                System.out.println("Please pick a number from the choices above.");

                typeTest = sc.next();

                if (IsNumber(typeTest)) {
                    testT = Convert(typeTest);
                } else {
                    do {
                        System.out.println("Please enter a number only.");
                        typeTest = sc.next();
                    } while (!IsNumber(typeTest));

                    testT = Convert(typeTest);
                }
                type = testT;
            } while (type < 1 || type > 2);

            if (type == 1) {
                DefaultPieDataset dataset = new DefaultPieDataset();
                for (int i = 0; i < all.size(); i++) {
                    dataset.setValue(
                            all.get(i).get(0).toString() + " = "
                                    + new DecimalFormat("#.##").format(percentages.get(i)) + "%",
                            percentages.get(i));
                }
                JFreeChart chart = ChartFactory.createPieChart(title, // chart title 
                        dataset, // data    
                        true, // include legend   
                        true, false);
                ChartPanel chartPanel = new ChartPanel(chart);
                chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
                JFrame l = new JFrame();

                l.setContentPane(chartPanel);
                l.setSize(400, 400);
                l.setVisible(true);

            } else {
                //do nothing?
            }

            int type2 = 0, testT2 = 0;
            String typeTest2 = "";
            do {
                System.out.println("REDISPLAY TABLE?");
                System.out.println("[1] YES");
                System.out.println("[2] NO");
                System.out.println();
                System.out.println("Please pick a number from the choices above.");

                typeTest2 = sc.next();

                if (IsNumber(typeTest2)) {
                    testT2 = Convert(typeTest2);
                } else {
                    do {
                        System.out.println("Please enter a number only.");
                        typeTest2 = sc.next();
                    } while (!IsNumber(typeTest2));

                    testT2 = Convert(typeTest2);
                }
                type2 = testT2;
            } while (type2 < 1 || type2 > 2);

            if (type2 == 1) {
                DisplayTable(all, percentages, title);
            } else {
                //do nothing?
            }

        } else if (choice == 2) {

            System.out.println("*** NUMERICAL ***");
            System.out.println();
            System.out.println("TITLE(title of data set)");
            title = s.nextLine();

            System.out.println("this is the title  " + title);

            ArrayList<Double> a = new ArrayList<>();
            //ArrayList<ArrayList> all; 
            //a = GetData2();

            double[] arr = { 70, 36, 43, 69, 82, 48, 34, 62, 35, 15, 59, 139, 46, 37, 42, 30, 55, 56, 36, 82,
                    38, 89, 54, 25, 35, 24, 22, 9, 55, 19 };

            /*    
                double[] arr = {112, 100, 127,120,134,118,105,110,109,112,
                110, 118, 117, 116, 118, 122, 114, 114, 105, 109,
                107, 112, 114, 115, 118, 117, 118, 122, 106, 110,
                116, 108, 110, 121, 113, 120, 119, 111, 104, 111,
                120, 113, 120, 117, 105, 110, 118, 112, 114, 114};
             */
            N = arr.length;
            double t = 0.0;
            for (int i = 0; i < N; i++) {
                a.add(arr[i]);
            }

            Collections.sort(a);
            System.out.println("sorted a " + a);
            double min = (double) a.get(0);
            double max = (double) a.get(N - 1);

            System.out.println("Min" + min);
            System.out.println("Max" + max);

            double k = Math.ceil(1 + 3.322 * Math.log10(N));
            System.out.println("K " + k);

            double range = GetRange(min, max);
            System.out.println("Range " + range);

            double width = Math.ceil(range / k);
            //todo, i ceiling sa 1st decimal point
            System.out.println("Width " + width);

            ArrayList<Double> cl = new ArrayList<>();
            cl.add(min);
            double rest;
            for (int i = 1; i < k; i++) {
                cl.add(min += width);
            }

            ArrayList<Double> cl2 = new ArrayList<>();
            double cl2min = cl.get(1) - 1;
            cl2.add(cl2min);
            for (int i = 1; i < k; i++) {
                cl2.add(cl2min += width);
            }

            System.out.println("cl 1 " + cl);
            System.out.println("cl 2 " + cl2);

            ArrayList<Double> tlcl = new ArrayList<>();
            double tlclmin = cl.get(0) - Multiplier(cl.get(0));
            tlcl.add(tlclmin);
            for (int i = 1; i < k; i++) {
                tlcl.add(tlclmin += width);
            }

            ArrayList<Double> tucl = new ArrayList<>();
            double tuclmin = cl2.get(0) + Multiplier(cl2.get(0));
            tucl.add(tuclmin);
            for (int i = 1; i < k; i++) {
                tucl.add(tuclmin += width);
            }
            System.out.println("tlcl 1 " + tlcl);
            System.out.println("tucl 2 " + tucl);
            System.out.println("N " + N);

            ArrayList<Double> midList = new ArrayList<>();
            double mid = (cl.get(0) + cl2.get(0)) / 2;
            midList.add(mid);
            for (int i = 1; i < k; i++) {
                midList.add((tlcl.get(i) + tucl.get(i)) / 2);
            }

            for (int i = 0; i < k; i++) {
                System.out.println((tlcl.get(i) + tucl.get(i)) / 2);
            }

            System.out.println("mid" + midList);

            ArrayList<ArrayList<Double>> freq = new ArrayList<>();

            double ctr = 0.0;
            for (int j = 0; j < k; j++) {
                for (int i = 0; i < N; i++) {
                    if ((a.get(i) >= tlcl.get(j)) && (a.get(i) <= tucl.get(j))) {
                        freq.add(new ArrayList<Double>());
                        freq.get(j).add(a.get(i));
                    }
                }
            }

            ArrayList<Double> freqSize = new ArrayList<>();
            double size = 0.0;
            for (int i = 0; i < k; i++) {
                size = (double) freq.get(i).size();
                freqSize.add(size);
            }

            ArrayList<Double> freqPercent = new ArrayList<>();
            for (int i = 0; i < k; i++) {

                freqPercent.add(freqSize.get(i) / N * 100);
            }

            ArrayList<Double> cfs = new ArrayList<>();
            double cf = freqSize.get(0);
            cfs.add(cf);
            for (int i = 1; i < k; i++) {
                cf = freqSize.get(i) + cfs.get(i - 1);
                cfs.add(cf);
            }

            double sum = 0.0;
            for (int i = 1; i < cfs.size(); i++) {
                sum += cfs.get(i);
            }

            ArrayList<Double> cps = new ArrayList<>();
            double cp = 0.0;
            for (int i = 0; i < k; i++) {
                cp = (cfs.get(i) / N) * 100;
                cps.add(cp);
            }

            System.out.println("T o t a l: " + sum);
            System.out.println(cfs);
            System.out.println(cps);

            System.out.println("frequency list " + freq);

            System.out.println("frequency sizes " + freqSize);
            System.out.println("frequency percentages " + freqPercent);

            System.out.println();
            System.out.println(title);

            System.out.println("CLASS LIMITS" + "\t" + "T CLASS LIMITS" + "\t" + "MID" + "\t" + "FREQ" + "\t"
                    + "PERCENT" + "\t" + "CF" + "\t" + "CP");
            for (int i = 0; i < k; i++) {
                System.out.println(cl.get(i) + " - " + cl2.get(i) + "\t" + tlcl.get(i) + " - " + tucl.get(i)
                        + "\t" + midList.get(i) + "\t" + freq.get(i).size() + "\t"
                        + new DecimalFormat("#.##").format(freqPercent.get(i)) + "\t" + cfs.get(i) + "\t"
                        + new DecimalFormat("#.##").format(cps.get(i)));
            }
            //2
            System.out.println("CLASS LIMITS" + "\t" + "T C L" + "\t" + "MID" + "\t" + "FREQ" + "\t" + "PERCENT"
                    + "\t" + "CF" + "\t" + "CP");
            for (int i = 0; i < k; i++) {
                System.out.println(">=" + cl.get(i) + "\t\t" + " - " + "\t" + " - " + "\t" + freq.get(i).size()
                        + "\t" + new DecimalFormat("#.##").format(freqPercent.get(i)) + "\t" + cfs.get(i) + "\t"
                        + new DecimalFormat("#.##").format(cps.get(i)));
            }
            //3
            System.out.println("CLASS LIMITS" + "\t" + "T C L" + "\t" + "MID" + "\t" + "FREQ" + "\t" + "PERCENT"
                    + "\t" + "CF" + "\t" + "CP");
            for (int i = 0; i < k; i++) {
                System.out.println("<=" + cl2.get(i) + "\t\t" + " - " + "\t" + " - " + "\t" + freq.get(i).size()
                        + "\t" + new DecimalFormat("#.##").format(freqPercent.get(i)) + "\t" + cfs.get(i) + "\t"
                        + new DecimalFormat("#.##").format(cps.get(i)));
            }

            System.out.println("CLASS LIMITS" + "\t" + "T CLASS LIMITS" + "\t" + "MID" + "\t" + "FREQ" + "\t"
                    + "PERCENT" + "\t" + "CF" + "\t" + "CP");
            for (int i = 0; i < k; i++) {
                System.out.println(">=" + cl.get(i) + " and <=" + cl2.get(i) + "\t" + " - " + "\t" + " - "
                        + "\t" + freq.get(i).size() + "\t"
                        + new DecimalFormat("#.##").format(freqPercent.get(i)) + "\t" + cfs.get(i) + "\t"
                        + new DecimalFormat("#.##").format(cps.get(i)));
            }

            DisplayTables(k, cl, cl2, tlcl, tucl, midList, freq, freqPercent, cfs, cps, title);

            int type = 0, testT = 0;
            String typeTest = "";
            do {
                do {

                    System.out.println();
                    System.out.println("GENERATE GRAPH?");
                    System.out.println("[1] YES");
                    System.out.println("[2] NO");
                    System.out.println();
                    System.out.println("Please pick a number from the choices above.");

                    typeTest = sc.next();

                    if (IsNumber(typeTest)) {
                        testT = Convert(typeTest);
                    } else {
                        do {
                            System.out.println("Please enter a number only.");
                            typeTest = sc.next();
                        } while (!IsNumber(typeTest));

                        testT = Convert(typeTest);
                    }
                    type = testT;
                } while (type < 1 || type > 2);

                if (type == 1) {
                    int bins = (int) k;
                    System.out.println();
                    System.out.println("You may input a label for your X axis:");
                    String x = "";
                    x = s.nextLine();
                    createHistogram(a, bins, title, x);

                    int type2 = 0, testT2 = 0;
                    String typeTest2 = "";
                    do {
                        System.out.println();
                        System.out.println("REDISPLAY TABLE?");
                        System.out.println("[1] YES");
                        System.out.println("[2] NO");
                        System.out.println();
                        System.out.println("Please pick a number from the choices above.");

                        typeTest2 = sc.next();

                        if (IsNumber(typeTest2)) {
                            testT2 = Convert(typeTest2);
                        } else {
                            do {
                                System.out.println("Please enter a number only.");
                                typeTest2 = sc.next();
                            } while (!IsNumber(typeTest2));

                            testT2 = Convert(typeTest2);
                        }
                        type2 = testT2;
                    } while ((type2 < 1 || type2 > 2) && type != 2);

                    if (type2 == 1) {

                        DisplayTables(k, cl, cl2, tlcl, tucl, midList, freq, freqPercent, cfs, cps, title);
                    } else {
                        //do nothing?
                    }
                }
            } while (type != 2);

        } else if (choice == 3) {
            System.out.println("*** QUIT ***");
        }

    } while (choice != 3);

    System.out.println("Thank you for your time.");
    s = new Simulation();

}

From source file:picard.analysis.TheoreticalSensitivity.java

/**
 * Determines if a variant would be called under the particular conditions of a given total depth, alt depth,
 * average base qualities, allele fraction of variant and log odds threshold necessary to call variant.
 * @param totalDepth Depth at the site to be called, both alt and ref.
 * @param altDepth Number of alt bases at this site.
 * @param sumOfAltQualities Average Phred-scaled quality of bases
 * @param alleleFraction Allele fraction we are attempting to detect
 * @param logOddsThreshold Log odds threshold necessary for variant to be called
 * @return Whether or not the model would call a variant given the parameters
 *///from  ww  w.  ja  va2 s  .  c  o  m
@VisibleForTesting
static boolean isCalled(final int totalDepth, final int altDepth, final double sumOfAltQualities,
        final double alleleFraction, final double logOddsThreshold) {
    final double threshold = 10.0 * (altDepth * -Math.log10(alleleFraction)
            + (totalDepth - altDepth) * -Math.log10(1.0 - alleleFraction) + logOddsThreshold);

    return sumOfAltQualities > threshold;
}

From source file:de.tudarmstadt.lt.lm.web.servlet.LanguageModelProviderServlet.java

private void show(String inputtype, String lm_key, String plaintext, String crawluri, boolean show_all_ngrams,
        PrintWriter w) throws Exception {
    if ("uri".equals(inputtype))
        plaintext = null;//  www  . ja  va 2  s. c  o  m
    if ("text".equals(inputtype))
        crawluri = null;

    if (plaintext == null && crawluri == null) // no parameter set
        plaintext = _test_text;

    w.write(_html_header);
    final Integer lm_index = _lm_keys.get(lm_key);
    if (lm_index == null) {
        LOG.error("Language model '{}' unknown.", lm_key);
        w.format("<p>Language model '%s' unknown. Please go to <a href='?'>main page</a>.</p>", lm_key);
        return;
    }

    StringProviderMXBean s = _lm_provider.get(lm_index);
    if (s == null) {
        if (!connectToLanguageModel(lm_key)) {
            w.format("<p>Language Model is loading. Please try again later.</p>", lm_key);
            w.write(_html_footer);
            w.flush();
            return;
        }
        s = _lm_provider.get(lm_index);
    }

    w.format("<h3>%s</h3>%n", lm_key);

    double crawl_perp = -1d;

    if (crawluri != null) {
        Object[] triple = crawl_and_extract_plaintext(crawluri, lm_key, lm_index);
        plaintext = (String) triple[0];
        crawl_perp = (Double) triple[1];
    } else
        crawluri = "";

    w.format(
            "<p>Crawl URI:</p>%n<p><form action='' method='get'><input type='text' name='crawluri' value='%s' size='100' />&nbsp;&nbsp;<input type='submit' value='Submit'><input type='hidden' name='inputtype' value='uri'><input type='hidden' name='lm' value='%s'><input type='hidden' name='action' value='show'></form></p>%n",
            crawluri, lm_key);
    w.format("<p>Crawler Perplexity = %012g</p>%n", crawl_perp);
    w.format("<p>Bytes Plaintext = %d</p>%n", plaintext.getBytes().length);
    w.format("<br />%n");
    w.format(
            "<p>Plaintext:</p>%n<p><form action='' method='get'><textarea rows='20' cols='150' name='plaintext'>%s</textarea><p><input type='submit' value='Submit'></p><input type='hidden' name='inputtype' value='text'><input type='hidden' name='lm' value='%s'><input type='hidden' name='action' value='show'></form></p>%n",
            plaintext, lm_key);
    w.format("<p>Perplexity = %012g</p>%n", s.getPerplexity(plaintext, false));
    w.format("<br />%n");

    w.format("<tt>%n");
    List<String>[] ngram_sequence = s.getNgrams(plaintext);
    w.format("+++ #ngrams= %d +++ <br /><br />%n", ngram_sequence.length);

    // TODO: provide ngrams
    for (int i = 0; i < ngram_sequence.length && (i <= 500 || show_all_ngrams); i++) {
        List<String> ngram = ngram_sequence[i];
        double log10_prob = s.getNgramLog10Probability(ngram);
        double prob10 = Math.pow(10, log10_prob);
        double log2_prob = log10_prob / Math.log10(2);
        int[] ngram_ids = s.getNgramAsIds(ngram);
        List<String> ngram_lm = s.getNgramAsWords(ngram_ids);
        w.format("%s <br />%n &nbsp;=> %s <br />%n &nbsp;= %012g (log_2 = %012g)<br /><br />%n",
                StringEscapeUtils.escapeHtml(ngram.toString()),
                StringEscapeUtils.escapeHtml(ngram_lm.toString()), prob10, log2_prob);
    }
    if (ngram_sequence.length > 500 && !show_all_ngrams)
        w.format("...%n");
    w.format("<br />%n");
    w.format("</tt>%n");

    w.write(_html_footer);

}

From source file:org.specvis.logic.Functions.java

/**
 * Get rounded decibel (dB) double value based on provided luminance parameters.
 * @param maxLuminance//from www  .jav a 2 s.c  o m
 * @param stimulusLuminance
 * @param backgroundLuminance
 * @param round
 * @return Decibel (dB) double value.
 */
public double decibelsValue(double maxLuminance, double stimulusLuminance, double backgroundLuminance,
        int round) {
    double decibels = 10 * Math.log10(maxLuminance / stimulusLuminance);
    return round(decibels, round);
}

From source file:net.phyloviz.mstsstatistics.Runner.java

private double calcNumberMSTs(List edgesList, GOeBurstResult sgr) {

    Collections.sort(edgesList);/*from   w  w w. j  a v a2s  .c o  m*/

    double nmsts = 0;

    int mapid;

    //Passo 1 - Descobrir o MaxId Inicial
    int maxid = findMaxId(edgesList);
    SparseDoubleMatrix2D matrix = new SparseDoubleMatrix2D(maxid + 1, maxid + 1);
    matrix.assign(0);

    DisjointSet ds = new DisjointSet(maxid);

    int[] map = new int[maxid + 1];
    for (int i = 0; i <= maxid; i++) {
        map[i] = i;
    }

    int[] mapaux = new int[maxid + 1];
    for (int i = 0; i <= maxid; i++) {
        mapaux[i] = -1;
    }

    //Passo 2 - Varrer arcos do nivel L, preenchendo a matriz
    Iterator<EdgeMST> eIter = edgesList.iterator();

    EdgeMST e = eIter.next();
    int level = (e != null) ? e.getLevel() : 1;

    ArrayList<Integer> vaux = new ArrayList<Integer>(maxid + 1);

    int prev = 0;
    int now = 0;

    while (true) {
        if (e != null && e.getLevel() == level) {
            int u = e.getSource();
            int v = e.getDest();
            if (!vaux.contains(u)) {
                vaux.add(u);
            }
            if (!vaux.contains(v)) {
                vaux.add(v);
            }
            //Preenchimento da Matriz
            int s = map[u];
            int d = map[v];

            matrix.setQuick(s, d, matrix.getQuick(s, d) - 1);
            matrix.setQuick(d, s, matrix.getQuick(d, s) - 1);
            matrix.setQuick(s, s, matrix.getQuick(s, s) + 1);
            matrix.setQuick(d, d, matrix.getQuick(d, d) + 1);

            if (!ds.sameSet(u, v)) {
                ds.unionSet(u, v);
            }

            now++;

            try {
                e = eIter.next();
            } catch (NoSuchElementException ex) {
                e = null;
            }

        } else if (prev != now) {
            mapid = 0;
            for (int i = 0; i <= maxid; i++) {
                int setid = ds.findSet(i);
                if (mapaux[setid] == -1) {
                    mapaux[setid] = mapid;
                    mapaux[i] = mapid;
                    mapid++;
                } else {
                    mapaux[i] = mapaux[setid];
                }
            }

            ArrayList[] calcDet = new ArrayList[mapid];
            for (int i = 0; i < calcDet.length; i++) {
                calcDet[i] = new ArrayList<Integer>();
            }

            for (int i = 0; i < vaux.size(); i++) {
                if (!calcDet[mapaux[vaux.get(i)]].contains(map[vaux.get(i)])) {
                    calcDet[mapaux[vaux.get(i)]].add(map[vaux.get(i)]);
                }
            }

            sgr.getPanel().appendWithDate("Level " + level + "\n");

            double[] calcNMstsDet = new double[mapid];
            for (int i = 0; i < calcDet.length; i++) {

                if (!calcDet[i].isEmpty()) {

                    int[] vgraph = new int[calcDet[i].size()];
                    ArrayList<Integer> graph = (ArrayList<Integer>) calcDet[i];
                    Iterator<Integer> gIter = graph.iterator();
                    int index = 0;
                    while (gIter.hasNext()) {
                        vgraph[index++] = gIter.next();
                    }

                    double det = 0.0;
                    LUDecomposition tempMax = new LUDecomposition(
                            (matrix.viewSelection(ArrayUtils.subarray(vgraph, 0, vgraph.length - 1),
                                    ArrayUtils.subarray(vgraph, 0, vgraph.length - 1))));
                    DoubleMatrix2D max = tempMax.getU();
                    System.out.println(max.rows());
                    for (int k = 0; k < max.rows(); k++) {
                        det += Math.log10(Math.abs(max.get(k, k)));
                    }

                    if (det == 0) {
                        det = 1;
                    }

                    sgr.getPanel().append("View: " + Arrays.toString(vgraph) + "\n");
                    sgr.getPanel().append("Det: " + det + "\n");
                    sgr.getPanel().flush();

                    calcNMstsDet[i] = det;
                    nmsts = nmsts + det;

                }
            }

            calcEdgesNMSTs(edgesList, prev, now, map, mapaux, calcDet, matrix, calcNMstsDet);

            prev = now;
            if (e == null) {
                break;
            }

            matrix = new SparseDoubleMatrix2D(mapid, mapid);
            matrix.assign(0);
            map = mapaux;
            mapaux = new int[maxid + 1];
            for (int i = 0; i <= maxid; i++) {
                mapaux[i] = -1;
            }
            //Passa para o nvel seguinte
            level++;
            vaux = new ArrayList<Integer>(mapid);
        } else { // Se prev==now a lista  vazia e passamos para o nvel seguinte
            level++;
        }
    }

    return nmsts;
}

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

/**
 * Apply calibrations to the given point. The following calibrations are included: calibration constant,
 * antenna pattern compensation, range spreading loss correction and incidence angle correction.
 *
 * @param v                   The pixel value.
 * @param slantRange          The slant range (in m).
 * @param satelliteHeight     The distance from satellite to earth centre (in m).
 * @param sceneToEarthCentre  The distance from the backscattering element position to earth centre (in m).
 * @param localIncidenceAngle The local incidence angle (in degrees).
 * @param bandPolar           The source band polarization index.
 * @param bandUnit            The source band unit.
 * @param subSwathIndex       The sub swath index for current pixel for wide swath product case.
 * @return The calibrated pixel value.//from   ww w.  j  a v  a  2s  . c  om
 */
public double applyCalibration(final double v, final double rangeIndex, final double azimuthIndex,
        final double slantRange, final double satelliteHeight, final double sceneToEarthCentre,
        final double localIncidenceAngle, final String bandPolar, final Unit.UnitType bandUnit,
        int[] subSwathIndex) {

    double Ks = 1.0;
    if (applyConstantCorrection) {
        Ks = calibrationFactor.get(bandPolar.toUpperCase());
    }

    double sigma = 0.0;
    if (bandUnit == Unit.UnitType.AMPLITUDE) {
        sigma = v * v;
    } else if (bandUnit == Unit.UnitType.INTENSITY || bandUnit == Unit.UnitType.REAL
            || bandUnit == Unit.UnitType.IMAGINARY) {
        sigma = v;
    } else if (bandUnit == Unit.UnitType.INTENSITY_DB) {
        sigma = FastMath.pow(10, v / 10.0); // convert dB to linear scale
    } else {
        throw new OperatorException("Unknown band unit");
    }

    if (applyRangeSpreadingLossCorrection)
        sigma *= FastMath.pow(referenceSlantRange, 2 * referenceSlantRangeExp);

    if (applyIncidenceAngleCorrection)
        sigma *= FastMath.sin(referenceIncidenceAngle);

    sigma /= (rescalingFactor * rescalingFactor * Ks);

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