List of usage examples for java.lang Math log10
@HotSpotIntrinsicCandidate public static double log10(double a)
From source file:javatranslation.matlab.dfa.java
public static double[] logspace(double d3, double d4) { int n = 50;/*from ww w . j a v a2 s . c o m*/ double base = 10; double d1 = Math.log10(d3); double d2 = Math.log10(d4); double[] y = new double[n]; double[] p = linspace(d1, d2, n); for (int i = 0; i < y.length - 1; i++) { y[i] = Math.pow(base, p[i]); } y[y.length - 1] = Math.pow(base, d2); return y; }
From source file:org.apache.hadoop.mapreduce.lib.input.TestMRSequenceFileInputFilter.java
public void testRegexFilter() throws Exception { // set the filter class LOG.info("Testing Regex Filter with patter: \\A10*"); SequenceFileInputFilter.setFilterClass(job, SequenceFileInputFilter.RegexFilter.class); SequenceFileInputFilter.RegexFilter.setPattern(job.getConfiguration(), "\\A10*"); // clean input dir fs.delete(inDir, true);/* ww w . j ava2 s . c om*/ // for a variety of lengths for (int length = 1; length < MAX_LENGTH; length += random.nextInt(MAX_LENGTH / 10) + 1) { LOG.info("******Number of records: " + length); createSequenceFile(length); int count = countRecords(0); assertEquals(count, length == 0 ? 0 : (int) Math.log10(length) + 1); } // clean up fs.delete(inDir, true); }
From source file:me.ziccard.secureit.fragment.MicrophoneFragment.java
public void onSignalReceived(short[] signal) { /*// ww w. j a v a 2 s .c o m * We do and average of the 512 samples */ int total = 0; int count = 0; for (short peak : signal) { //Log.i("MicrophoneFragment", "Sampled values are: "+peak); if (peak != 0) { total += Math.abs(peak); count++; } } Log.i("MicrophoneFragment", "Total value: " + total); int average = 0; if (count > 0) average = total / count; /* * We compute a value in decibels */ double averageDB = 0.0; if (average != 0) { averageDB = 20 * Math.log10(Math.abs(average) / 1); } microphoneText.setText("Sampled DBs: " + averageDB); picker.setValues(averageDB, averageDB); picker.invalidate(); if (averageDB > NOISE_THRESHOLD) { Message message = new Message(); message.what = UploadService.MICROPHONE_MESSAGE; try { if (serviceMessenger != null) serviceMessenger.send(message); } catch (RemoteException e) { // Cannot happen } } }
From source file:io.woolford.processors.nifibenford.BenfordsLaw.java
private static double[] getBenfordsArray() { // this is the expected distribtion of first digits for Benford's Law double[] benfordsArray = new double[9]; for (int i = 1; i < 10; i++) { double benfordValue = 100 * Math.log10(1 + 1.0 / i); benfordsArray[i - 1] = benfordValue; }// w w w . j a v a 2 s.c o m return benfordsArray; }
From source file:org.broadinstitute.gatk.utils.MathUtilsUnitTest.java
@DataProvider(name = "log10OneMinusPow10Data") public Iterator<Object[]> log10OneMinusPow10Data() { final double[] inValues = new double[] { Double.NaN, 10, 1, 0, -1, -3, -10, -30, -100, -300, -1000, -3000 }; return new Iterator<Object[]>() { private int i = 0; @Override/*from w w w . j a va2 s . c om*/ public boolean hasNext() { return i < inValues.length; } @Override public Object[] next() { final double input = inValues[i++]; final double output = Math.log10(1 - Math.pow(10, input)); return new Object[] { input, output }; } @Override public void remove() { throw new UnsupportedOperationException(); } }; }
From source file:nz.ac.otago.psyanlab.common.util.FileUtils.java
/** * Format Bytes to a human readable quantity. * // ww w. j a v a 2s . com * @param fileSize File size in bytes. * @return Human readable string of bytes. e.g. 1.2 TiB. */ public static String formatBytes(long fileSize) { if (fileSize <= 0) { return "0 B"; } final String[] units = new String[] { "B", "KiB", "MiB", "GiB", "TiB" }; int digitGroups = (int) (Math.log10(fileSize) / Math.log10(1024)); return new DecimalFormat("#,##0.#").format(fileSize / Math.pow(1024, digitGroups)) + " " + units[digitGroups]; }
From source file:org.easyrec.plugin.pearson.impl.PearsonServiceImpl.java
private void calculateWeights(final Integer tenantId, final Integer actionTypeId, final Integer itemTypeId, final List<User> users, final Map<Integer, Double> averageRatings) { final int userCount = users.size(); final int perc25 = (int) (userCount * 0.25); final int perc50 = (int) (userCount * 0.5); final int perc75 = (int) (userCount * 0.75); for (int i = 0; i < userCount; i++) { final User activeUser = users.get(i); final double averageActive = averageRatings.get(activeUser.getUser()); if (logger.isInfoEnabled()) { if (i == perc25) logger.info("Weight calculation at 25%"); if (i == perc50) logger.info("Weight calculation at 50%"); if (i == perc75) logger.info("Weight calculation at 75%"); if (i % 10 == 0) logger.info(String.format("Weight calculation at user %d of %d", i, userCount)); }//from w w w.ja v a 2 s. co m for (int j = i + 1; j < userCount; j++) { final User otherUser = users.get(j); final List<RatedTogether<Integer, Integer>> ratedTogether = latestActionDao .getItemsRatedTogetherByUsers(tenantId, itemTypeId, activeUser.getUser(), otherUser.getUser(), actionTypeId); // users don't have common rated items if (ratedTogether.size() == 0) continue; final double averageOther = averageRatings.get(otherUser.getUser()); double frequency = 1.0; if (settings.isUseInverseUserFrequency()) { frequency = userCount / ratedTogether.size(); frequency = Math.log10(frequency); if (frequency == 0.0) continue; } double frequencySum = 0.0; double expectedBoth = 0.0; double expectedActive = 0.0; double expectedOther = 0.0; double expectedActiveSquare = 0.0; double expectedOtherSquare = 0.0; for (final RatedTogether<Integer, Integer> rating : ratedTogether) { final double ratingActive = rating.getRating1().getRatingValue(); final double ratingOther = rating.getRating2().getRatingValue(); frequencySum += frequency; expectedBoth += frequency * ratingActive * ratingOther; expectedActive += frequency * ratingActive; expectedOther += frequency * ratingOther; expectedActiveSquare += frequency * Math.pow(ratingActive, 2.0); expectedOtherSquare += frequency * Math.pow(ratingOther, 2.0); } // TODO replace EX^2 - (EX)^2 with E((X-EX)^2) for better stability final double varianceActive = frequencySum * expectedActiveSquare - Math.pow(expectedActive, 2.0); final double varianceOther = frequencySum * expectedOtherSquare - Math.pow(expectedOther, 2.0); double numerator1 = frequencySum * expectedBoth; double numerator2 = expectedActive * expectedOther; final double denominator = Math.sqrt(varianceActive * varianceOther); numerator1 /= denominator; numerator2 /= denominator; final double weight = numerator1 - numerator2; if (Double.isNaN(weight) || Double.isInfinite(weight)) { if (logger.isWarnEnabled()) logger.warn(String.format( "Weight is %s for users %d and %d (vAct=%.2f, vOth=%.2f, Eact2=%.2f, Eoth2=%.2f, " + "Ebot=%.2f, Eact=%.2f, Eoth=%.2f, fre=%.2f fsum=%.2f, num1=%.2f, " + "numer2=%.2f, den=%.2f)", Double.isNaN(weight) ? "NaN" : "Inf", i, j, varianceActive, varianceOther, expectedActiveSquare, expectedOtherSquare, expectedBoth, expectedActive, expectedOther, frequency, frequencySum, numerator1, numerator2, denominator)); continue; } final Weight weightObj = new Weight(activeUser, otherUser, weight); weightDao.insertOrUpdateWeightSymmetric(weightObj); } } }
From source file:net.sf.maltcms.chromaui.foldChangeViewer.tasks.FoldChangeViewLoaderWorker.java
@Override public void run() { ProgressHandle handle = ProgressHandleFactory.createHandle("Creating fold change plot"); try {// ww w.ja va2s .c o m handle.setDisplayName("Loading fold change elements");//+new File(this.files.getResourceLocation()).getName()); handle.start(5); handle.progress("Reading settings", 1); RTUnit rtAxisUnit = RTUnit.valueOf(sp.getProperty("rtAxisUnit", "SECONDS")); handle.progress("Retrieving data", 2); XYShapeRenderer renderer = new XYShapeRenderer() { @Override protected Paint getPaint(XYDataset dataset, int series, int item) { double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); if (Math.abs(x) < 1.0) { Paint p = super.getPaint(dataset, series, item); if (p instanceof Color) { Color color = (Color) p; float[] values = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), new float[3]); Color hsb = new Color( Color.HSBtoRGB(values[0], (float) Math.max(0.1, values[1] - 0.9), values[2])); return new Color(hsb.getRed(), hsb.getGreen(), hsb.getBlue(), 64); } } return super.getPaint(dataset, series, item); } }; renderer.setAutoPopulateSeriesFillPaint(true); renderer.setAutoPopulateSeriesOutlinePaint(true); renderer.setBaseCreateEntities(true); handle.progress("Building plot", 3); XYPlot plot = new XYPlot(dataset, new NumberAxis("log2 fold change"), new NumberAxis("-log10 p-value"), renderer); BasicStroke dashed = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 5.0f, new float[] { 5.0f }, 0.0f); ValueMarker marker = new ValueMarker(-Math.log10(0.05), Color.RED, dashed); marker.setLabel("p-value=0.05"); marker.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT); marker.setLabelOffset(new RectangleInsets(UnitType.ABSOLUTE, 0, 50, 10, 0)); marker.setLabelOffsetType(LengthAdjustmentType.EXPAND); marker.setLabelPaint(Color.LIGHT_GRAY); plot.addRangeMarker(marker); Font font1 = new Font("SansSerif", Font.PLAIN, 12); SelectionAwareXYTooltipGenerator tooltipGenerator = cvtc.getLookup() .lookup(SelectionAwareXYTooltipGenerator.class); if (tooltipGenerator == null) { tooltipGenerator = new SelectionAwareXYTooltipGenerator(tooltipGenerator) { @Override public String createSelectionAwareTooltip(XYDataset xyd, int i, int i1) { FoldChangeDataset dataset = (FoldChangeDataset) xyd; FoldChangeElement fce = dataset.getNamedElementProvider().get(i).get(i1); StringBuilder sb = new StringBuilder(); sb.append("<html>"); sb.append(fce.getPeakGroup().getMajorityDisplayName()); sb.append("<br>"); sb.append("log2 fold change="); sb.append(fce.getFoldChange()); sb.append("<br>"); sb.append("p-value="); sb.append(Math.pow(10, -fce.getPvalue())); sb.append("</html>"); return sb.toString(); } }; } tooltipGenerator.setXYToolTipGenerator(new XYToolTipGenerator() { @Override public String generateToolTip(XYDataset xyd, int i, int i1) { Comparable comp = xyd.getSeriesKey(i); double x = xyd.getXValue(i, i1); double y = xyd.getYValue(i, i1); StringBuilder sb = new StringBuilder(); sb.append("<html>"); sb.append(comp); sb.append("<br>"); sb.append("log2 fold change="); sb.append(x); sb.append("<br>"); sb.append("p-value="); sb.append(sb.append(Math.pow(10, -y))); sb.append("</html>"); return sb.toString(); } }); plot.getRenderer().setBaseToolTipGenerator(tooltipGenerator); handle.progress("Configuring plot", 4); configurePlot(plot, rtAxisUnit); final FoldChangeViewPanel cmhp = cvtc.getLookup().lookup(FoldChangeViewPanel.class); Range domainRange = null; Range valueRange = null; if (cmhp != null) { XYPlot xyplot = cmhp.getPlot(); if (xyplot != null) { ValueAxis domain = xyplot.getDomainAxis(); domainRange = domain.getRange(); ValueAxis range = xyplot.getRangeAxis(); valueRange = range.getRange(); } } if (domainRange != null) { plot.getDomainAxis().setRange(domainRange); } if (valueRange != null) { Logger.getLogger(getClass().getName()).info("Setting previous value range!"); } handle.progress("Adding plot to panel", 5); final XYPlot targetPlot = plot; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { final FoldChangeViewPanel cmhp = cvtc.getLookup().lookup(FoldChangeViewPanel.class); cmhp.setPlot(targetPlot); cvtc.requestActive(); } }); } finally { handle.finish(); } }
From source file:org.esa.beam.util.math.FastMathPerformance.java
public void testLog10() { System.gc();//from www . j ava 2s .c o m double x = 0; long time = System.nanoTime(); for (int i = 0; i < RUNS; i++) x += StrictMath.log10(Math.PI + i/* 1.0 + i/1e9 */); long strictMath = System.nanoTime() - time; System.gc(); double y = 0; time = System.nanoTime(); for (int i = 0; i < RUNS; i++) y += FastMath.log10(Math.PI + i/* 1.0 + i/1e9 */); long fastTime = System.nanoTime() - time; System.gc(); double z = 0; time = System.nanoTime(); for (int i = 0; i < RUNS; i++) z += Math.log10(Math.PI + i/* 1.0 + i/1e9 */); long mathTime = System.nanoTime() - time; report("log10", x + y + z, strictMath, fastTime, mathTime); }
From source file:biz.itcons.wsdm.hw2_2.NaiveBayes.java
/** * A classification for document. Based on the train data, an attempt to * classify a document.//from w w w . j ava2 s.c o m * @param document A document to be classfied. * @return Most probable classification for given document. */ public String classifyDocument(String document) { Map<String, Integer> docTokens = StringTokenization.getTokensWithMultiplicity(document); double totalProbability = Double.NEGATIVE_INFINITY; String totalClassification = ""; for (Map.Entry<String, ClassificationItem> e : parsedEntries.entrySet()) { double priorProb = ((double) e.getValue().getDocumentCount()) / globalTrainingCount; double currentClassProb = Math.log10(priorProb) + e.getValue().calcCondProbDoc(docTokens, vocabulary.size()); if (currentClassProb > totalProbability) { totalProbability = currentClassProb; totalClassification = e.getKey(); } } return totalClassification; }