List of usage examples for java.lang Math log10
@HotSpotIntrinsicCandidate public static double log10(double a)
From source file:cn.androidy.androiddevelopmentpatterns.interactivechart.InteractiveLineGraphView.java
/** * Rounds the given number to the given number of significant digits. Based on an answer on * <a href="http://stackoverflow.com/questions/202302">Stack Overflow</a>. *//*w w w . ja v a 2 s . co m*/ private static float roundToOneSignificantFigure(double num) { final float d = (float) Math.ceil((float) Math.log10(num < 0 ? -num : num)); final int power = 1 - (int) d; final float magnitude = (float) Math.pow(10, power); final long shifted = Math.round(num * magnitude); return shifted / magnitude; }
From source file:de.tudarmstadt.lt.lm.app.StartLM.java
void computeSequenceProbabilities() { if (_providerService == null) { System.out.println("LM Server is not runnning."); return;//from www . ja v a 2 s .co m } for (String input_line = null; !":q".equals((input_line = readInput(String.format( "Enter sequence, e.g. 'hello world'. Type ':q' to quit computing sequence probabilities: %n%s $> ", _name))));) { input_line = input_line.trim(); try { _providerService.resetPerplexity(); double log10_prob_ = _providerService.getSequenceLog10Probability(input_line); double prob10_ = Math.pow(10, log10_prob_); double log2_prob_ = log10_prob_ / Math.log10(2); System.out.format("+++%nprob=%g (log10=%g, log2=%g) %n", prob10_, log10_prob_, log2_prob_); double perp = _providerService.getPerplexity(input_line, false); System.out.format("perp=%g %n%n", perp); perp = _providerService.getPerplexity(input_line, true); System.out.format("perp (no-oov)=%g %n%n", perp); double log10_prob, prob10, log2_prob; List<String>[] ngram_sequence = _providerService.getNgrams(input_line); System.out.format("+++ #ngrams= %d +++ %n", ngram_sequence.length); System.out.format("[initial cumulative Perp=%g] %n%n", _providerService.getPerplexity()); for (int i = 0; i < ngram_sequence.length; i++) { List<String> ngram = ngram_sequence[i]; log10_prob = _providerService.getNgramLog10Probability(ngram); prob10 = Math.pow(10, log10_prob); 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 = %g (log10=%g, log2=%g) %n", ngram.toString(), ngram_lm.toString(), prob10, log10_prob, log2_prob); _providerService.addToPerplexity(ngram); System.out.format(" [cumulative perp=%g] %n%n", _providerService.getPerplexity()); } System.out.format("+++ #ngrams= %d +++ %n", ngram_sequence.length); System.out.format("prob=%g (log10=%g, log2=%g) %n", prob10_, log10_prob_, log2_prob_); System.out.format("perp=%g %n%n", perp); } catch (Exception e) { LOG.warn("{}: {}", e.getClass().getSimpleName(), e.getMessage()); } } }
From source file:com.facebook.presto.operator.scalar.MathFunctions.java
@Description("logarithm to base 10") @ScalarFunction//from w w w .j a v a 2s.c o m @SqlType(StandardTypes.DOUBLE) public static double log10(@SqlType(StandardTypes.DOUBLE) double num) { return Math.log10(num); }
From source file:org.broadinstitute.sting.utils.recalibration.RecalDatumNode.java
/** * Calculate the phred-scaled p-value for a chi^2 test for independent among subnodes of this node. * * The chi^2 value indicates the degree of independence of the implied error rates among the * immediate subnodes//from w w w . ja va 2 s . co m * * @return the phred-scaled p-value for chi2 penalty, or 0.0 if it cannot be calculated */ private double calcPenalty() { if (isLeaf() || freeToMerge()) return 0.0; else if (subnodes.size() == 1) // only one value, so its free to merge away return 0.0; else { final long[][] counts = new long[subnodes.size()][2]; int i = 0; for (final RecalDatumNode<T> subnode : subnodes) { // use the yates correction to help avoid all zeros => NaN counts[i][0] = Math.round(subnode.getRecalDatum().getNumMismatches()) + 1L; counts[i][1] = subnode.getRecalDatum().getNumObservations() + 2L; i++; } try { final double chi2PValue = new ChiSquareTestImpl().chiSquareTest(counts); final double penalty = -10.0 * Math.log10(Math.max(chi2PValue, SMALLEST_CHI2_PVALUE)); // make sure things are reasonable and fail early if not if (Double.isInfinite(penalty) || Double.isNaN(penalty)) throw new ReviewedStingException("chi2 value is " + chi2PValue + " at " + getRecalDatum()); return penalty; } catch (MathException e) { throw new ReviewedStingException("Failed in calculating chi2 value", e); } } }
From source file:org.nuxeo.ecm.automation.server.jaxrs.batch.BatchManagerFixture.java
@Test public void testFileConcurrency() throws Exception { // Initialize a batch BatchManager bm = Framework.getService(BatchManager.class); String batchId = bm.initBatch(); // Add files concurrently int nbFiles = 100; ThreadPoolExecutor tpe = new ThreadPoolExecutor(5, 5, 500L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(nbFiles + 1)); for (int i = 0; i < nbFiles; i++) { final String fileIndex = String.valueOf(i); tpe.submit(new Runnable() { @Override/*w w w .ja va 2s . c o m*/ public void run() { try { bm.addStream(batchId, fileIndex, new ByteArrayInputStream( ("SomeContent_" + fileIndex).getBytes(StandardCharsets.UTF_8)), fileIndex + ".txt", "text/plain"); } catch (IOException e) { fail(e.getMessage()); } } }); } tpe.shutdown(); boolean finish = tpe.awaitTermination(20, TimeUnit.SECONDS); assertTrue("timeout", finish); // Check blobs List<Blob> blobs = bm.getBlobs(batchId); assertEquals(nbFiles, blobs.size()); // Test indexes 0, 9, 99, ..., nbFiles - 1 int nbDigits = (int) (Math.log10(nbFiles) + 1); int divisor = nbFiles; for (int i = 0; i < nbDigits; i++) { int fileIndex = nbFiles / divisor - 1; assertEquals(fileIndex + ".txt", blobs.get(fileIndex).getFilename()); assertEquals("SomeContent_" + fileIndex, blobs.get(fileIndex).getString()); divisor = divisor / 10; } // Check storage size TransientStore ts = bm.getTransientStore(); assertTrue(((AbstractTransientStore) ts).getStorageSize() > 12 * nbFiles); // Clean batch bm.clean(batchId); assertEquals(ts.getStorageSizeMB(), 0); }
From source file:org.noise_planet.noisecapture.MeasurementService.java
public void setPause(boolean newState) { isPaused.set(newState);/* w w w. jav a2 s . c o m*/ LOGGER.info("Measurement pause = " + String.valueOf(newState)); audioProcess.setDoFastLeq(!newState); audioProcess.setDoOneSecondLeq(!newState); if (newState && deletedLeqOnPause > 0 && recordId > -1) { // Delete last recorded leq int deletedLeq = measurementManager.deleteLastLeqs(recordId, System.currentTimeMillis() - (deletedLeqOnPause * 1000)); leqAdded.set(Math.max(0, leqAdded.get() - deletedLeq)); // Recompute LeqStats altered by the removed leq LeqStats newLeqStats = new LeqStats(); // Query database List<Integer> frequencies = new ArrayList<Integer>(); List<Float[]> leqValues = new ArrayList<Float[]>(); measurementManager.getRecordLeqs(recordId, frequencies, leqValues, null); // parse each leq window time for (Float[] leqFreqs : leqValues) { double rms = 0; for (float leqValue : leqFreqs) { rms += Math.pow(10, leqValue / 10); } newLeqStats.addLeq(10 * Math.log10(rms)); } leqStats = newLeqStats; leqStatsFast = new LeqStats(newLeqStats); } else if (newState && recordId > -1) { leqStatsFast = new LeqStats(); } }
From source file:edu.umn.cs.spatialHadoop.nasa.MultiHDFPlot.java
/** * Draws a scale used with the heat map/*from www . j a v a 2 s . co m*/ * @param output * @param valueRange * @param width * @param height * @throws IOException */ private static void drawHorizontalScale(Path output, double min, double max, int width, int height, OperationsParams params) throws IOException { BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = image.createGraphics(); g.setBackground(Color.BLACK); g.clearRect(0, 0, width, height); int fontSize = 24; // fix this part to work according to color1, color2 and gradient type HDFPlot.HDFRasterizer gradient = new HDFPlot.HDFRasterizer(); gradient.configure(params); HDFRasterLayer gradientLayer = (HDFRasterLayer) gradient.createCanvas(0, 0, new Rectangle()); for (int x = 0; x < width; x++) { Color color = gradientLayer.calculateColor(x, 0, width); g.setColor(color); g.drawRect(x, height - (fontSize - 5), 1, fontSize - 5); } g.setFont(new Font("Arial", Font.BOLD, fontSize)); double step = (max - min) * fontSize * 5 / width; step = (int) (Math.pow(10.0, Math.round(Math.log10(step)))); double min_value = Math.floor(min / step) * step; double max_value = Math.floor(max / step) * step; g.setColor(Color.WHITE); for (double value = min_value; value <= max_value; value += step) { double x = ((value - min) * (width - fontSize) + (max - value)) / (max - min); g.drawString(String.valueOf((int) value), (int) x, fontSize); } g.dispose(); FileSystem fs = output.getFileSystem(new Configuration()); FSDataOutputStream outStream = fs.create(output, true); ImageIO.write(image, "png", outStream); outStream.close(); }
From source file:org.processmining.analysis.performance.dottedchart.ui.DottedChartPanel.java
/** * adjusts the viewable are of the log (zoom) *//* w ww . j a v a2s. co m*/ public void setViewportZoomIn() { Dimension d = dca.getViewportSize(); int width = Math.abs(p1.x - p2.x); int height = Math.abs(p1.y - p2.y); int value = (int) (Math.log10( (double) this.getWidth() * (d.getWidth() / width) / (double) dca.getViewportSize().getWidth()) * 1000.0); if (value > 3000) return; value = (int) (Math.log10( (double) this.getHeight() * (d.getHeight() / height) / (double) dca.getViewportSize().getHeight()) * 1000.0); if (value > 3000) return; updWidth = (int) ((double) this.getWidth() * (d.getWidth() / width)); updHight = (int) ((double) this.getHeight() * (d.getHeight() / height)); Dimension dim = new Dimension(updWidth, updHight); int pos_x = Math.min(p1.x, p2.x); int pos_y = Math.min(p1.y, p2.y); Point p = new Point((int) (pos_x * d.getWidth() / width), (int) (pos_y * d.getHeight() / height)); this.setPreferredSize(dim); updateMilli2pixelsRatio(); this.revalidate(); dca.setScrollBarPosition(p); p1 = null; p2 = null; adjustSlideBar(); }
From source file:org.esa.nest.gpf.MultilookOp.java
/** * Compute the mean value of pixels of the source image in the sliding window. * * @param tx The x coordinate of a pixel in the current target tile. * @param ty The y coordinate of a pixel in the current target tile. * @param srcData1 The product data for i band in case of complex product. * @param srcData2 The product data for q band in case of complex product. * @param nRgLooks number of range looks * @param nAzLooks number of azimuth looks * @return The mean value.//from www . j ava 2s . c o m */ private static double getMeanValue(final int tx, final int ty, final ProductData srcData1, final ProductData srcData2, final TileIndex srcIndex, final int nRgLooks, final int nAzLooks, final boolean isdB, final boolean isComplex, final boolean isPolsar) { final int xStart = tx * nRgLooks; final int yStart = ty * nAzLooks; final int xEnd = xStart + nRgLooks; final int yEnd = yStart + nAzLooks; double meanValue = 0.0; int offset; if (isdB) { for (int y = yStart; y < yEnd; y++) { offset = srcIndex.calculateStride(y); for (int x = xStart; x < xEnd; x++) { meanValue += FastMath.pow(10, srcData1.getElemDoubleAt(x - offset) / 10.0); // dB to linear } } meanValue /= (nRgLooks * nAzLooks); return 10.0 * Math.log10(meanValue); // linear to dB } else if (isComplex && !isPolsar) { // COMPLEX double i, q; int index; for (int y = yStart; y < yEnd; y++) { offset = srcIndex.calculateStride(y); for (int x = xStart; x < xEnd; x++) { index = x - offset; i = srcData1.getElemDoubleAt(index); q = srcData2.getElemDoubleAt(index); meanValue += i * i + q * q; } } } else { for (int y = yStart; y < yEnd; y++) { offset = srcIndex.calculateStride(y); for (int x = xStart; x < xEnd; x++) { meanValue += srcData1.getElemDoubleAt(x - offset); } } } return meanValue / (nRgLooks * nAzLooks); }
From source file:com.commontime.cordova.audio.AudioPlayer.java
/** * Get db Recording Level./*from ww w . ja v a 2s . c om*/ * * @return double dbLevel */ public float getRecordDbLevel() { double reference = 0.00002; // Pa reference minimum if (this.state == STATE.MEDIA_RUNNING) { int maxAmplitude = this.recorder.getMaxAmplitude(); /* / Warning! / / This is a desperate attempt to determine dB (SPL). / Without proper calibration for each device, the reference value is a best guess. / Please do not count on these values for anything other than to provide at least some feedback that / something is being recorded. / / The pascal pressure is calculated based on the idea that the max amplitude (being a value between 0 and 32767) / is relative to the pressure. / The value 51805.5336 used below is derived from the assumption that when x = 32767, pressure = 0.6325 Pa and that / when x = 1, pressure = 0.0002 Pa (the reference value) / */ double pressure = maxAmplitude / 51805.5336; double dB = 20 * Math.log10(pressure / reference); return (float) dB; } else { return -1; } }