List of usage examples for java.lang Math log10
@HotSpotIntrinsicCandidate public static double log10(double a)
From source file:org.broadinstitute.gatk.utils.MathUtils.java
/** * @see #binomialProbability(int, int, double) with log10 applied to result *//*from w ww.j a va 2s. c o m*/ public static double log10BinomialProbability(final int n, final int k, final double log10p) { if (log10p > 1e-18) throw new IllegalArgumentException("log10p: Log-probability must be 0 or less"); double log10OneMinusP = Math.log10(1 - Math.pow(10, log10p)); return log10BinomialCoefficient(n, k) + log10p * k + log10OneMinusP * (n - k); }
From source file:statisticslabro.StatisticsLabr.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed List<String> Temp = new ArrayList<String>(); List<String> check = new ArrayList<String>(); List<Double> fnl = new ArrayList<>(); List<String> frame = new ArrayList<String>(); List<String> name = new ArrayList<String>(); List<String> name2 = new ArrayList<String>(); List<Double> frame2 = new ArrayList<Double>(); List<Double> limitLeft = new ArrayList<>(); List<Double> limitRight = new ArrayList<>(); List<Double> trueLimitLeft = new ArrayList<>(); List<Double> trueLimitRight = new ArrayList<>(); List<Double> midpoint = new ArrayList<>(); List<Integer> frequency = new ArrayList<>(); List<Double> percent = new ArrayList<>(); List<Integer> cf = new ArrayList<>(); List<Double> cp = new ArrayList<>(); Integer freq = 0;//w ww .j av a 2 s . c o m Double freqtot = 0.0; if (Categorical.isSelected() == true && Numerical.isSelected() == false) { for (int i = 0; i < jTable1.getRowCount(); i++) { frame.add((String) jTable1.getModel().getValueAt(i, 0)); } Collections.sort(frame); Integer size = frame.size(); System.out.println(size); for (Object b : frame) { String c = b + ""; Temp.add(c); } for (int i = 0; i < jTable1.getRowCount(); i++) { for (int j = 0; j < jTable1.getColumnCount(); j++) { jTable1.setValueAt("", i, j); } } int ct = 0; for (Object z : frame) { String a = z + ""; System.out.print(check.contains(a)); if (!(check.contains(a))) { for (int i = 0; i < Temp.size(); i++) { if (a.equals(Temp.get(i))) { freq++; } } Double freque = (((freq + .0) / size) * 100); fnl.add(freque); name.add(a); freqtot += freque; jTable1.getModel().setValueAt(a, ct, 0); jTable1.getModel().setValueAt(String.format("%1.1f", freque) + "%", ct, 1); ct++; freq = 0; check.add(a); } total.setText("Total :" + String.format("%1.1f", freqtot)); } if (Chart.isSelected() == true) { DefaultPieDataset chart = new DefaultPieDataset(); int h = 0; for (Double z : fnl) { chart.setValue(name.get(h) + "", new Double(z)); h++; } JFreeChart mychart = ChartFactory.createPieChart3D(Desc.getText() + "", chart, true, true, true); PiePlot3D p = (PiePlot3D) mychart.getPlot(); ChartFrame charteuFrame = new ChartFrame(Desc.getText(), mychart); charteuFrame.setVisible(true); charteuFrame.setSize(450, 500); } } else if (Numerical.isSelected() == true && Categorical.isSelected() == false) { double subtrahend = 0.5; for (int i = 0; i < jTable1.getRowCount();) { double d = Double.parseDouble((String) jTable1.getModel().getValueAt(i, 0)); frame2.add(d); i++; } double max = 0; double min = frame2.get(0); for (int j = 0; j < frame2.size(); j++) { System.out.print("Sulod"); if (max < frame2.get(j)) { max = frame2.get(j); } if (min > frame2.get(j)) { min = frame2.get(j); } } System.out.print(frame2); double range = max - min; double k = Math.ceil(1 + 3.322 * Math.log10(frame2.size())); int width = (int) Math.ceil(range / k); System.out.println("char: " + max + " " + min + " " + range + " " + k + " width: " + width); double limit = min; while (limit < max) { limitLeft.add(limit); limit += width; } for (int j = 0; j < limitLeft.size(); j++) { System.out.print(limitLeft.get(j) + " "); } double limit2 = min + width - 1; while (limit2 <= max) { limitRight.add(limit2); limit2 += width; } if (limitRight.get(limitRight.size() - 1) != max) { limitRight.add(max); } System.out.println(); for (int j = 0; j < limitRight.size(); j++) { System.out.print(limitRight.get(j) + " "); } //true limit if (((String) choice.getSelectedItem()).equals("Integer")) { for (int j = 0; j < limitLeft.size(); j++) { trueLimitLeft.add(limitLeft.get(j) - 0.5); } System.out.println(); for (int j = 0; j < trueLimitLeft.size(); j++) { System.out.print(trueLimitLeft.get(j) + " "); } for (int j = 0; j < limitRight.size(); j++) { trueLimitRight.add(limitRight.get(j) + 0.5); } System.out.println(); for (int j = 0; j < trueLimitRight.size(); j++) { System.out.print(trueLimitRight.get(j) + " "); } } else if (((String) choice.getSelectedItem()).equals("Floating")) { int count1 = 0; float diff = 0; boolean flag = false; for (int j = 0; j < frame2.size(); j++) { double value = Math.floor(frame2.get(j)); System.out.println(frame.get(j)); diff = (float) (frame2.get(j) - value); System.out.println("diff: " + diff); String counts = String.valueOf(diff); if (diff > 0.0) { if (counts.length() - 1 > count1) { count1 = counts.length() - 1; System.out.println(count1); } } } System.out.println(count1); for (int j = 0; j < count1 - 1; j++) { subtrahend /= 10; System.out.println(subtrahend); } System.out.println("sub: " + subtrahend); for (int j = 0; j < limitLeft.size(); j++) { trueLimitLeft.add(limitLeft.get(j) - subtrahend); } for (int j = 0; j < limitRight.size(); j++) { trueLimitRight.add(limitRight.get(j) + subtrahend); } } //midpoint for (int j = 0; j < limitLeft.size(); j++) { midpoint.add((limitLeft.get(j) + limitRight.get(j)) / 2); } System.out.println(); for (int j = 0; j < midpoint.size(); j++) { System.out.print(midpoint.get(j) + " "); } //frequency for (int j = 0; j < limitLeft.size(); j++) { int count = 0; for (int m = 0; m < frame2.size(); m++) { if (frame2.get(m) >= limitLeft.get(j) && frame2.get(m) <= limitRight.get(j)) { count++; } } frequency.add(count); } System.out.println(); for (int j = 0; j < frequency.size(); j++) { System.out.print(frequency.get(j) + " "); } //percent for (int j = 0; j < frequency.size(); j++) { double pp = (((double) frequency.get(j) / frame2.size()) * 100); percent.add(pp); } System.out.println(); for (int j = 0; j < percent.size(); j++) { System.out.print(percent.get(j) + " "); } int cff = 0; for (int j = 0; j < frequency.size(); j++) { cff += frequency.get(j); cf.add(cff); } System.out.println(); for (int j = 0; j < cf.size(); j++) { System.out.print(cf.get(j) + " "); } double cpp = 0; for (int j = 0; j < percent.size(); j++) { cpp += percent.get(j); cp.add(cpp); } System.out.println(); for (int j = 0; j < cp.size(); j++) { System.out.print(cp.get(j) + " "); } DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel(); dtm.setRowCount(limitLeft.size()); int ct = 0; if (collapse.isSelected() == true) { for (int j = 0; j < limitLeft.size(); j++) { if (ct == 0) { jTable1.getModel().setValueAt("< " + limitRight.get(j), ct, 1); jTable1.getModel().setValueAt("-", ct, 3); name.add("<"); } else if (ct == limitLeft.size() - 1) { jTable1.getModel().setValueAt("> " + limitLeft.get(j), ct, 1); jTable1.getModel().setValueAt("-", ct, 3); name.add(">"); } else { jTable1.getModel().setValueAt(limitLeft.get(j) + "-" + limitRight.get(j), ct, 1); jTable1.getModel().setValueAt(midpoint.get(j), ct, 3); name.add(midpoint.get(j) + ""); } jTable1.getModel().setValueAt(trueLimitLeft.get(j) + "-" + trueLimitRight.get(j), ct, 2); jTable1.getModel().setValueAt(frequency.get(j), ct, 4); jTable1.getModel().setValueAt(percent.get(j), ct, 5); jTable1.getModel().setValueAt(cf.get(j), ct, 6); jTable1.getModel().setValueAt(cp.get(j), ct, 7); ct++; } } else { for (int j = 0; j < limitLeft.size(); j++) { jTable1.getModel().setValueAt(limitLeft.get(j) + "-" + limitRight.get(j), ct, 1); jTable1.getModel().setValueAt(trueLimitLeft.get(j) + "-" + trueLimitRight.get(j), ct, 2); jTable1.getModel().setValueAt(midpoint.get(j), ct, 3); name.add(midpoint.get(j) + ""); jTable1.getModel().setValueAt(frequency.get(j), ct, 4); jTable1.getModel().setValueAt(percent.get(j), ct, 5); jTable1.getModel().setValueAt(cf.get(j), ct, 6); jTable1.getModel().setValueAt(cp.get(j), ct, 7); ct++; } } } if (Chart.isSelected() == true) { DefaultCategoryDataset chart = new DefaultCategoryDataset(); int h = 0; for (Integer z : frequency) { chart.setValue(z, "Frequency", name.get(h)); h++; } JFreeChart mychart = ChartFactory.createBarChart(Desc.getText() + "", "Midpoint", "Frequency", chart, PlotOrientation.VERTICAL, true, false, false); CategoryPlot p = (CategoryPlot) mychart.getPlot(); p.setDomainGridlinesVisible(true); p.getDomainAxis().setCategoryMargin(0.0); ChartFrame charteuFrame = new ChartFrame(Desc.getText(), mychart); charteuFrame.setVisible(true); charteuFrame.setSize(450, 500); } }
From source file:cn.androidy.androiddevelopmentpatterns.interactivechart.InteractiveLineGraphView.java
/** * Computes the set of axis labels to show given start and stop boundaries and an ideal number * of stops between these boundaries.//from w w w . j a v a2 s. c o m * * @param start The minimum extreme (e.g. the left edge) for the axis. * @param stop The maximum extreme (e.g. the right edge) for the axis. * @param steps The ideal number of stops to create. This should be based on available screen * space; the more space there is, the more stops should be shown. * @param outStops The destination {@link AxisStops} object to populate. */ private static void computeAxisStops(float start, float stop, int steps, AxisStops outStops) { double range = stop - start; if (steps == 0 || range <= 0) { outStops.stops = new float[] {}; outStops.numStops = 0; return; } double rawInterval = range / steps; double interval = roundToOneSignificantFigure(rawInterval); double intervalMagnitude = Math.pow(10, (int) Math.log10(interval)); int intervalSigDigit = (int) (interval / intervalMagnitude); if (intervalSigDigit > 5) { // Use one order of magnitude higher, to avoid intervals like 0.9 or 90 interval = Math.floor(10 * intervalMagnitude); } double first = Math.ceil(start / interval) * interval; double last = Math.nextUp(Math.floor(stop / interval) * interval); double f; int i; int n = 0; for (f = first; f <= last; f += interval) { ++n; } outStops.numStops = n; if (outStops.stops.length < n) { // Ensure stops contains at least numStops elements. outStops.stops = new float[n]; } for (f = first, i = 0; i < n; f += interval, ++i) { outStops.stops[i] = (float) f; } if (interval < 1) { outStops.decimals = (int) Math.ceil(-Math.log10(interval)); } else { outStops.decimals = 0; } }
From source file:org.esa.s1tbx.calibration.gpf.calibrators.TerraSARXCalibrator.java
/** * Called by the framework in order to compute a tile for the given target band. * <p>The default implementation throws a runtime exception with the message "not implemented".</p> * * @param targetBand The target band./*from w w w .j av a2s. com*/ * @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 OperatorException If an error occurs during computation of the target raster. */ public void computeTile(Band targetBand, Tile targetTile, ProgressMonitor pm) throws OperatorException { final Rectangle targetTileRectangle = targetTile.getRectangle(); final int x0 = targetTileRectangle.x; final int y0 = targetTileRectangle.y; final int w = targetTileRectangle.width; final int h = targetTileRectangle.height; //System.out.println("x0 = " + x0 + ", y0 = " + y0 + ", w = " + w + ", h = " + h); Tile sourceRaster1 = null; ProductData srcData1 = null; ProductData srcData2 = null; Band sourceBand1 = null; final String[] srcBandNames = targetBandNameToSourceBandName.get(targetBand.getName()); if (srcBandNames.length == 1) { sourceBand1 = sourceProduct.getBand(srcBandNames[0]); sourceRaster1 = calibrationOp.getSourceTile(sourceBand1, targetTileRectangle); srcData1 = sourceRaster1.getDataBuffer(); } else { sourceBand1 = sourceProduct.getBand(srcBandNames[0]); final Band sourceBand2 = sourceProduct.getBand(srcBandNames[1]); sourceRaster1 = calibrationOp.getSourceTile(sourceBand1, targetTileRectangle); final Tile sourceRaster2 = calibrationOp.getSourceTile(sourceBand2, targetTileRectangle); srcData1 = sourceRaster1.getDataBuffer(); srcData2 = sourceRaster2.getDataBuffer(); } Tile srcGIMTile = null; ProductData srcGIMData = null; if (useIncidenceAngleFromGIM) { srcGIMTile = calibrationOp.getSourceTile(sourceGIMProduct.getBand("band_1"), targetTileRectangle); srcGIMData = srcGIMTile.getDataBuffer(); } final Unit.UnitType tgtBandUnit = Unit.getUnitType(targetBand); final Unit.UnitType srcBandUnit = Unit.getUnitType(sourceBand1); final double noDataValue = sourceBand1.getNoDataValue(); // 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 = 0.0; if (pol != null) { Ks = calibrationFactor.get(pol); } double[][] tileNoise = null; if (!noiseCorrectedFlag) { tileNoise = new double[h][w]; computeTileNoise(pol, x0, y0, w, h, tileNoise); } final ProductData trgData = targetTile.getDataBuffer(); final TileIndex srcIndex = new TileIndex(sourceRaster1); final TileIndex tgtIndex = new TileIndex(targetTile); final int maxY = y0 + h; final int maxX = x0 + w; double sigma, dn, dn2, i, q, phaseTerm = 0.0; 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 (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("TerraSAR-X Calibration: unhandled unit"); } double inciAng; if (useIncidenceAngleFromGIM) { final int gim = srcGIMData.getElemIntAt(srcIdx); inciAng = (gim - (gim % 10)) / 100.0 * Constants.DTOR; } else { inciAng = incidenceAngle.getPixelDouble(x, y) * Constants.DTOR; } if (noiseCorrectedFlag) { sigma = Ks * dn2 * FastMath.sin(inciAng); } else { sigma = Ks * Math.abs(dn2 - tileNoise[y - y0][x - x0]) * FastMath.sin(inciAng); } 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:gov.nij.er.ui.EntityResolutionDemo.java
private void loadExcelData(File file) throws Exception { LOG.debug("Loading Excel data file " + file.getAbsolutePath()); InputStream inp = new FileInputStream(file); Workbook wb = WorkbookFactory.create(inp); // note that we read all the data out of the spreadsheet first, then // update the models. this way if there is // an error, we don't wipe out what the user already has. Sheet sheet = wb.getSheetAt(0);// w ww.j a va 2 s . c o m Row parametersRow = sheet.getRow(0); List<String> parameterNames = new ArrayList<String>(); for (Cell cell : parametersRow) { String v = cell.getStringCellValue(); if (parameterNames.contains(v)) { error("Duplicate field: " + v); return; } parameterNames.add(v); LOG.debug("Adding parameter " + v); } int parameterCount = parameterNames.size(); LOG.debug("Excel loading read " + parameterCount + " parameters"); List<ExternallyIdentifiableRecord> records = new ArrayList<ExternallyIdentifiableRecord>(); int rowCount = sheet.getLastRowNum(); LOG.debug("Loading " + (rowCount - 1) + " rows from " + sheet.getSheetName()); int digits = (int) (Math.floor(Math.log10(rowCount)) + 1); DataFormatter dataFormatter = new DataFormatter(); for (int rowIndex = 1; rowIndex <= rowCount; rowIndex++) { List<Attribute> attributes = new ArrayList<Attribute>(parameterCount); Row row = sheet.getRow(rowIndex); for (int i = 0; i < parameterCount; i++) { Cell cell = row.getCell(i); String v = dataFormatter.formatCellValue(cell); String parameterName = parameterNames.get(attributes.size()); attributes.add(new Attribute(parameterName, v)); // LOG.debug("Adding attribute, name=" + parameterName + ", v=" // + (v==null ? "null" : "'" + v + "'")); } records.add(new ExternallyIdentifiableRecord(makeAttributes(attributes.toArray(new Attribute[] {})), String.format("%0" + digits + "d", rowIndex))); } LOG.debug("Read " + records.size() + " records from Excel"); List<RecordWrapper> recordWrappers = EntityResolutionConversionUtils.convertRecords(records); rawDataTreeModel.init(recordWrappers); parametersTableModel.clear(); parametersTableModel.addParameters(parameterNames); }
From source file:edu.mbl.jif.imaging.mmtiff.MultipageTiffWriter.java
private void processSummaryMD(JSONObject summaryMD) throws MMScriptException, JSONException { rgb_ = MDUtils.isRGB(summaryMD);/*from ww w .ja v a 2 s . c om*/ numChannels_ = MDUtils.getNumChannels(summaryMD); numFrames_ = MDUtils.getNumFrames(summaryMD); numSlices_ = MDUtils.getNumSlices(summaryMD); imageWidth_ = MDUtils.getWidth(summaryMD); imageHeight_ = MDUtils.getHeight(summaryMD); String pixelType = MDUtils.getPixelType(summaryMD); if (pixelType.equals("GRAY8") || pixelType.equals("RGB32") || pixelType.equals("RGB24")) { byteDepth_ = 1; } else if (pixelType.equals("GRAY16") || pixelType.equals("RGB64")) { byteDepth_ = 2; } else if (pixelType.equals("GRAY32")) { byteDepth_ = 3; } else { byteDepth_ = 2; } bytesPerImagePixels_ = imageHeight_ * imageWidth_ * byteDepth_ * (rgb_ ? 3 : 1); //Tiff resolution tag values double cmPerPixel = 0.0001; if (summaryMD.has("PixelSizeUm")) { try { cmPerPixel = 0.0001 * summaryMD.getDouble("PixelSizeUm"); } catch (JSONException ex) { } } else if (summaryMD.has("PixelSize_um")) { try { cmPerPixel = 0.0001 * summaryMD.getDouble("PixelSize_um"); } catch (JSONException ex) { } } double log = Math.log10(cmPerPixel); if (log >= 0) { resDenomenator_ = (long) cmPerPixel; resNumerator_ = 1; } else { resNumerator_ = (long) (1 / cmPerPixel); resDenomenator_ = 1; } if (summaryMD.has("z-step_um") && !summaryMD.isNull("z-step_um")) { zStepUm_ = summaryMD.getDouble("z-step_um"); } }
From source file:de.tudarmstadt.lt.lm.app.StartLM.java
void computeNgramProbabilities() { if (_providerService == null) { System.out.println("LM Server is not runnning."); return;//w ww . j ava2 s.co m } for (String input_line = null; !":q".equals((input_line = readInput(String.format( "Enter ngram with space separated tokens, e.g. 'hello world'. Type ':q' to quit computing ngram probabilities: %n%s $> ", _name))));) { List<String> ngram = Arrays.asList(input_line.trim().split(" ")); try { if (ngram.size() > _providerService.getLmOrder()) { System.out.format("%s is too long. Try an ngram with max cardinality %d. ", ngram, _providerService.getLmOrder()); continue; } double log10_prob = _providerService.getNgramLog10Probability(ngram); double prob10 = Math.pow(10, log10_prob); double log2_prob = log10_prob / Math.log10(2); int[] ngram_ids = _providerService.getNgramAsIds(ngram); List<String> ngram_lm = _providerService.getNgramAsWords(ngram_ids); System.out.format("%s %n => %s %n => %s %n = %g (log10=%g, log2=%g) %n", ngram.toString(), Arrays.toString(ngram_ids).toString(), ngram_lm.toString(), prob10, log10_prob, log2_prob); } catch (Exception e) { LOG.warn(e.getMessage()); } } }
From source file:org.nd4j.linalg.util.BigDecimalMath.java
/** * The exponential function.//from w w w .j a v a 2 s . c o m * * @param x the argument. * @return exp(x). * The precision of the result is implicitly defined by the precision in the argument. * 16 * In particular this means that "Invalid Operation" errors are thrown if catastrophic * cancellation of digits causes the result to have no valid digits left. */ static public BigDecimal exp(BigDecimal x) { /* To calculate the value if x is negative, use exp(-x) = 1/exp(x) */ if (x.compareTo(BigDecimal.ZERO) < 0) { final BigDecimal invx = exp(x.negate()); /* Relative error in inverse of invx is the same as the relative errror in invx. * This is used to define the precision of the result. */ MathContext mc = new MathContext(invx.precision()); return BigDecimal.ONE.divide(invx, mc); } else if (x.compareTo(BigDecimal.ZERO) == 0) { /* recover the valid number of digits from x.ulp(), if x hits the * zero. The x.precision() is 1 then, and does not provide this information. */ return scalePrec(BigDecimal.ONE, -(int) (Math.log10(x.ulp().doubleValue()))); } else { /* Push the number in the Taylor expansion down to a small * value where TAYLOR_NTERM terms will do. If x<1, the n-th term is of the order * x^n/n!, and equal to both the absolute and relative error of the result * since the result is close to 1. The x.ulp() sets the relative and absolute error * of the result, as estimated from the first Taylor term. * We want x^TAYLOR_NTERM/TAYLOR_NTERM! < x.ulp, which is guaranteed if * x^TAYLOR_NTERM < TAYLOR_NTERM*(TAYLOR_NTERM-1)*...*x.ulp. */ final double xDbl = x.doubleValue(); final double xUlpDbl = x.ulp().doubleValue(); if (Math.pow(xDbl, TAYLOR_NTERM) < TAYLOR_NTERM * (TAYLOR_NTERM - 1.0) * (TAYLOR_NTERM - 2.0) * xUlpDbl) { /* Add TAYLOR_NTERM terms of the Taylor expansion (Eulers sum formula) */ BigDecimal resul = BigDecimal.ONE; /* x^i */ BigDecimal xpowi = BigDecimal.ONE; /* i factorial */ BigInteger ifac = BigInteger.ONE; /* TAYLOR_NTERM terms to be added means we move x.ulp() to the right * for each power of 10 in TAYLOR_NTERM, so the addition wont add noise beyond * whats already in x. */ MathContext mcTay = new MathContext(err2prec(1., xUlpDbl / TAYLOR_NTERM)); for (int i = 1; i <= TAYLOR_NTERM; i++) { ifac = ifac.multiply(new BigInteger("" + i)); xpowi = xpowi.multiply(x); final BigDecimal c = xpowi.divide(new BigDecimal(ifac), mcTay); resul = resul.add(c); if (Math.abs(xpowi.doubleValue()) < i && Math.abs(c.doubleValue()) < 0.5 * xUlpDbl) { break; } } /* exp(x+deltax) = exp(x)(1+deltax) if deltax is <<1. So the relative error * in the result equals the absolute error in the argument. */ MathContext mc = new MathContext(err2prec(xUlpDbl / 2.)); return resul.round(mc); } else { /* Compute exp(x) = (exp(0.1*x))^10. Division by 10 does not lead * to loss of accuracy. */ int exSc = (int) (1.0 - Math.log10(TAYLOR_NTERM * (TAYLOR_NTERM - 1.0) * (TAYLOR_NTERM - 2.0) * xUlpDbl / Math.pow(xDbl, TAYLOR_NTERM)) / (TAYLOR_NTERM - 1.0)); BigDecimal xby10 = x.scaleByPowerOfTen(-exSc); BigDecimal expxby10 = exp(xby10); /* Final powering by 10 means that the relative error of the result * is 10 times the relative error of the base (First order binomial expansion). * This looses one digit. */ MathContext mc = new MathContext(expxby10.precision() - exSc); /* Rescaling the powers of 10 is done in chunks of a maximum of 8 to avoid an invalid operation 17 * response by the BigDecimal.pow library or integer overflow. */ while (exSc > 0) { int exsub = Math.min(8, exSc); exSc -= exsub; MathContext mctmp = new MathContext(expxby10.precision() - exsub + 2); int pex = 1; while (exsub-- > 0) { pex *= 10; } expxby10 = expxby10.pow(pex, mctmp); } return expxby10.round(mc); } } }
From source file:org.esa.nest.gpf.ERSCalibrator.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.//from w ww .j a v a 2s.co m * @param targetTile The current tile associated with the target band to be computed. * @param pm A progress monitor which should be used to determine computation cancelation requests. * @throws org.esa.beam.framework.gpf.OperatorException If an error occurs during computation of the target raster. */ @Override public void computeTile(Band targetBand, Tile targetTile, ProgressMonitor pm) throws OperatorException { try { final Rectangle targetTileRectangle = targetTile.getRectangle(); final int x0 = targetTileRectangle.x; final int y0 = targetTileRectangle.y; final int w = targetTileRectangle.width; final int h = targetTileRectangle.height; //System.out.println("x0 = " + x0 + ", y0 = " + y0 + ", w = " + w + ", h = " + h); final ProductData trgData = targetTile.getDataBuffer(); Band sourceBand1 = null; Band sourceBand2 = null; Tile sourceRaster1 = null; Tile sourceRaster2 = null; ProductData srcData1 = null; ProductData srcData2 = null; final String[] srcBandNames = targetBandNameToSourceBandName.get(targetBand.getName()); if (srcBandNames.length == 1) { sourceBand1 = sourceProduct.getBand(srcBandNames[0]); sourceRaster1 = getSourceTile(sourceBand1, targetTileRectangle); srcData1 = sourceRaster1.getDataBuffer(); } else { sourceBand1 = sourceProduct.getBand(srcBandNames[0]); sourceBand2 = sourceProduct.getBand(srcBandNames[1]); sourceRaster1 = getSourceTile(sourceBand1, targetTileRectangle); sourceRaster2 = getSourceTile(sourceBand2, targetTileRectangle); srcData1 = sourceRaster1.getDataBuffer(); srcData2 = sourceRaster2.getDataBuffer(); } final Unit.UnitType bandUnit = Unit.getUnitType(sourceBand1); // copy band if unit is phase if (bandUnit == Unit.UnitType.PHASE) { targetTile.setRawSamples(sourceRaster1.getRawSamples()); return; } if (applyAntennaPatternCorrection && !isAntPattAvailable) { computeAntennaPatternCorrectionFactors(0, sourceImageWidth); } if (applyADCSaturationCorrection && !adcHasBeenTestedFlag) { testADC(sourceBand1, sourceBand2, bandUnit); } boolean applyADCSaturationCorrectionToCurrentTile = false; if (applyADCSaturationCorrection && h >= blockHeight && w >= blockWidth) { applyADCSaturationCorrectionToCurrentTile = true; } double[][] adcPowerLoss = null; if (applyADCSaturationCorrectionToCurrentTile) { adcPowerLoss = computeADCPowerLossValuesForCurrentTile(sourceBand1, sourceBand2, x0, y0, w, h, bandUnit); } final double k = calibrationConstant * FastMath.sin(referenceIncidenceAngle); double sigma, dn, i, q; int index; int adcJ = 0; for (int x = x0; x < x0 + w; x++) { final double sinIncidenceAngleByK = FastMath.sin(incidenceAngles[x]) / k; if (applyADCSaturationCorrectionToCurrentTile) { adcJ = Math.min(((x - x0) / blockWidth), adcPowerLoss[0].length - 1); } for (int y = y0; y < y0 + h; y++) { index = sourceRaster1.getDataBufferIndex(x, y); if (bandUnit == Unit.UnitType.AMPLITUDE) { dn = srcData1.getElemDoubleAt(index); sigma = dn * dn; } else if (bandUnit == Unit.UnitType.INTENSITY) { sigma = srcData1.getElemDoubleAt(index); } else { // COMPLEX i = srcData1.getElemDoubleAt(index); q = srcData2.getElemDoubleAt(index); sigma = i * i + q * q; } sigma *= sinIncidenceAngleByK; if (applyAntennaPatternCorrection) { sigma *= antennaPatternCorrFactor[x]; } if (applyRangeSpreadingLossCorrection) { sigma *= rangeSpreadingLoss[x]; } if (applyReplicaPowerCorrection) { sigma *= replicaPulseVariationsCorrectionFactor; } if (applyADCSaturationCorrectionToCurrentTile) { final int adcI = Math.min(((y - y0) / blockHeight), adcPowerLoss.length - 1); sigma *= adcPowerLoss[adcI][adcJ]; } if (outputImageScaleInDb) { // convert calibration result to dB if (sigma < underFlowFloat) { sigma = -underFlowFloat; } else { sigma = 10.0 * Math.log10(sigma); } } trgData.setElemDoubleAt(targetTile.getDataBufferIndex(x, y), sigma); } } } catch (Throwable e) { OperatorUtils.catchOperatorException("ERSCalibrator", e); } }
From source file:org.processmining.analysis.performance.dottedchart.ui.DottedChartPanel.java
public void adjustSlideBar() { int value = (int) (Math.log10((double) updWidth / (double) dca.getViewportSize().getWidth()) * 1000.0); if (value > 3000) value = 3000;/*from w w w.ja v a 2 s. c o m*/ dcOptionPanel.getZoomSliderX().setValue(value); dcOptionPanel.getZoomSliderX().repaint(); value = (int) (Math.log10((double) updHight / (double) dca.getViewportSize().getHeight()) * 1000.0); if (value > 3000) value = 3000; dcOptionPanel.getZoomSliderY().setValue(value); dcOptionPanel.getZoomSliderY().repaint(); }