List of usage examples for java.lang Math log10
@HotSpotIntrinsicCandidate public static double log10(double a)
From source file:arun.com.chromer.browsing.article.view.ElasticDragDismissFrameLayout.java
private void dragScale(int scroll) { if (scroll == 0) return;/*from w ww .j a v a 2s .c o m*/ totalDrag += scroll; View child = getChildAt(0); // track the direction & set the pivot point for scaling // don't double track i.e. if play dragging down and then reverse, keep tracking as // dragging down until they reach the 'natural' position if (scroll < 0 && !draggingUp && !draggingDown) { draggingDown = true; if (shouldScale) child.setPivotY(getHeight()); } else if (scroll > 0 && !draggingDown && !draggingUp) { draggingUp = true; if (shouldScale) child.setPivotY(0f); } // how far have we dragged relative to the distance to perform a dismiss // (01 where 1 = dismiss distance). Decreasing logarithmically as we approach the limit float dragFraction = (float) Math.log10(1 + (Math.abs(totalDrag) / dragDismissDistance)); // calculate the desired translation given the drag fraction float dragTo = dragFraction * dragDismissDistance * dragElasticity; if (draggingUp) { // as we use the absolute magnitude when calculating the drag fraction, need to // re-apply the drag direction dragTo *= -1; } child.setTranslationY(dragTo); if (draggingBackground == null) { draggingBackground = new RectF(); draggingBackground.left = 0; draggingBackground.right = getWidth(); } if (shouldScale) { final float scale = 1 - ((1 - dragDismissScale) * dragFraction); child.setScaleX(scale); child.setScaleY(scale); } // if we've reversed direction and gone past the settle point then clear the flags to // allow the list to get the scroll events & reset any transforms if ((draggingDown && totalDrag >= 0) || (draggingUp && totalDrag <= 0)) { totalDrag = dragTo = dragFraction = 0; draggingDown = draggingUp = false; child.setTranslationY(0f); child.setScaleX(1f); child.setScaleY(1f); } // draw the background above or below the view where it has scrolled at if (draggingUp) { draggingBackground.bottom = getHeight(); draggingBackground.top = getHeight() + dragTo; invalidate(); } else if (draggingDown) { draggingBackground.top = 0; draggingBackground.bottom = dragTo; invalidate(); } dispatchDragCallback(dragFraction, dragTo, Math.min(1f, Math.abs(totalDrag) / dragDismissDistance), totalDrag); }
From source file:marytts.util.string.StringUtils.java
public static String[] indexedNameGenerator(String preName, int numFiles, int startIndex, String postName, String extension, int numDigits) { String[] fileList = null;// www . ja v a 2s . c o m if (numFiles > 0) { if (startIndex < 0) startIndex = 0; int tmpDigits = (int) Math.floor(Math.log10(startIndex + numFiles - 1)); if (tmpDigits > numDigits) numDigits = tmpDigits; fileList = new String[numFiles]; String strNum; for (int i = startIndex; i < startIndex + numFiles; i++) { strNum = String.valueOf(i); //Add sufficient 0s in the beginning while (strNum.length() < numDigits) strNum = "0" + strNum; // fileList[i - startIndex] = preName + strNum + postName + extension; } } return fileList; }
From source file:org.lanes.text.mining.Similarity.java
public double distributedSimilarity(String phrase1, String phrase2) { double similarity = 0; if (phrase1.toLowerCase().equals(phrase2.toLowerCase())) { similarity = 1;/*from w w w. j av a2 s . c o m*/ } else { double n1 = getDocCount(phrase1); double n2 = getDocCount(phrase2); double n12 = getDocCount(phrase1, phrase2); if (N > 0 && n1 > 0 && n2 > 0 && n12 > 0) { double logN = Math.log10(N * N); double logn1 = Math.log10(n1 * n1); double logn2 = Math.log10(n2 * n2); double logn12 = Math.log10(n12 * n12); double max_logn2n1 = 0; double min_logn2n1 = 0; if (logn1 < logn2) { max_logn2n1 = logn2; min_logn2n1 = logn1; } else { max_logn2n1 = logn1; min_logn2n1 = logn2; } double nwd = 0; if ((logN - min_logn2n1) > 0) { nwd = (max_logn2n1 - logn12) / (logN - min_logn2n1); if (nwd > 0) similarity = Math.exp(-0.6 * nwd); } } } similarity = CommonData.roundDecimal(similarity, "#.####"); return similarity; }
From source file:org.b3log.symphony.service.VoteMgmtService.java
/** * Gets Reddit score./*from ww w . ja va2s .c om*/ * * @param ups the specified vote up count * @param downs the specified vote down count * @param t time (epoch seconds) * @return reddit score */ public static double redditScore(final int ups, final int downs, final long t) { final int x = ups - downs; final double z = Math.max(Math.abs(x), 1); int y = 0; if (x > 0) { y = 1; } else if (x < 0) { y = -1; } return Math.log10(z) + y * (t - 1353745196) / 45000; }
From source file:io.plaidapp.ui.widget.ElasticDragDismissFrameLayout.java
private void dragScale(int scroll) { if (scroll == 0) return;// w w w. ja va2 s . c o m totalDrag += scroll; // track the direction & set the pivot point for scaling // don't double track i.e. if start dragging down and then reverse, keep tracking as // dragging down until they reach the 'natural' position // if (scroll < 0 && !draggingUp && !draggingDown) { // draggingDown = true; if (shouldScale) setPivotY(getHeight()); } else if (scroll > 0 && !draggingDown && !draggingUp) { // draggingUp = true; if (shouldScale) setPivotY(0f); } // how far have we dragged relative to the distance to perform a dismiss // (01 where 1 = dismiss distance). Decreasing logarithmically as we approach the limit float dragFraction = (float) Math.log10(1 + (Math.abs(totalDrag) / dragDismissDistance)); // calculate the desired translation given the drag fraction float dragTo = dragFraction * dragDismissDistance * dragElacticity; if (draggingUp) { // as we use the absolute magnitude when calculating the drag fraction, need to // re-apply the drag direction dragTo *= -1; } setTranslationY(dragTo); if (shouldScale) { final float scale = 1 - ((1 - dragDismissScale) * dragFraction); setScaleX(scale); setScaleY(scale); } // if we've reversed direction and gone past the settle point then clear the flags to // allow the list to get the scroll events & reset any transforms // ???? View??? if ((draggingDown && totalDrag >= 0) || (draggingUp && totalDrag <= 0)) { totalDrag = dragTo = dragFraction = 0; draggingDown = draggingUp = false; setTranslationY(0f); setScaleX(1f); setScaleY(1f); } dispatchDragCallback(dragFraction, dragTo, Math.min(1f, Math.abs(totalDrag) / dragDismissDistance), totalDrag); }
From source file:savant.util.MiscUtils.java
public static int[] getTickPositions(double min, double max) { // The 0.35 is a factor which gives us roughly the right density of ticks at all magnifications. int log = (int) Math.floor(Math.log10(max - min) - 0.35); int step = log > 0 ? (int) Math.pow(10, log) : 1; int[] result = new int[(int) (max - min) / step + 1]; int p0 = ((((int) min - 1) / step) + 1) * step; for (int i = 0; i < result.length; i++) { result[i] = p0;// www . j a v a2s . c o m p0 += step; } return result; }
From source file:org.canova.api.util.MathUtils.java
/** * Inverse document frequency: the total docs divided by the number of times the word * appeared in a document/*from w ww .ja va 2 s.c om*/ * * @param totalDocs the total documents for the data applyTransformToDestination * @param numTimesWordAppearedInADocument the number of times the word occurred in a document * @return log(10) (totalDocs/numTImesWordAppearedInADocument) */ public static double idf(double totalDocs, double numTimesWordAppearedInADocument) { return totalDocs > 0 ? Math.log10(totalDocs / numTimesWordAppearedInADocument) : 0; }
From source file:org.deeplearning4j.clustering.util.MathUtils.java
/** * Inverse document frequency: the total docs divided by the number of times the word * appeared in a document/*from w w w . j a v a 2 s. com*/ * @param totalDocs the total documents for the data applyTransformToDestination * @param numTimesWordAppearedInADocument the number of times the word occurred in a document * @return log(10) (totalDocs/numTImesWordAppearedInADocument) */ public static double idf(double totalDocs, double numTimesWordAppearedInADocument) { //return totalDocs > 0 ? Math.log10(totalDocs/numTimesWordAppearedInADocument) : 0; if (totalDocs == 0) return 0; double idf = Math.log10(totalDocs / numTimesWordAppearedInADocument); return idf; }
From source file:com.bigdata.dastor.gms.FailureDetector.java
double phi(long tnow) { int size = arrivalIntervals_.size(); double log = 0d; if (size > 0) { double t = tnow - tLast_; double probability = p(t); log = (-1) * Math.log10(probability); }// w w w.j a v a2 s . com return log; }
From source file:org.apache.pig.piggybank.storage.FixedWidthStorer.java
@SuppressWarnings("unchecked") private String writeFieldAsString(ResourceFieldSchema field, FixedWidthLoader.FixedWidthField column, int offset, Object d) throws IOException { StringBuilder sb = new StringBuilder(); if (offset < column.start) { int spaces = column.start - offset; for (int i = 0; i < spaces; i++) { sb.append(' '); }/*from ww w . jav a2s . co m*/ } int width = column.end - column.start; String fieldStr = null; if (d != null) { if (DataType.findType(d) == DataType.DATETIME) fieldStr = ((DateTime) d).toDateTime(DateTimeZone.UTC).toString(); else fieldStr = d.toString(); } // write nulls as spaces if (fieldStr == null) { for (int i = 0; i < width; i++) { sb.append(' '); } return sb.toString(); } // If the field is too big to fit in column if (fieldStr.length() > width) { // If it is float or double, try to round it to fit byte fieldType = field.getType(); if (fieldType == DataType.FLOAT || fieldType == DataType.DOUBLE) { double doubleVal = ((Number) d).doubleValue(); int numDigitsLeftOfDecimal = (int) Math.ceil(Math.log10(Math.abs(doubleVal))); // Field can be rounded to fit if (numDigitsLeftOfDecimal <= width + 2) { int numDigitsRightOfDecimal = width - numDigitsLeftOfDecimal - 1; // should be at least 1 String truncated = String.format("%." + numDigitsRightOfDecimal + "f", doubleVal); warn("Cannot fit " + fieldStr + " in field starting at column " + column.start + " and ending at column " + (column.end - 1) + ". " + "Since the field is a decimal type, truncating it to " + truncated + " " + "to fit in the column.", PigWarning.UDF_WARNING_1); sb.append(truncated); } else { // Field is float or double but cannot be rounded to fit warn("Cannot fit " + fieldStr + " in field starting at column " + column.start + " and ending at column " + (column.end - 1) + ". " + "Writing null (all spaces) instead.", PigWarning.UDF_WARNING_2); for (int i = 0; i < width; i++) { sb.append(' '); } } } else { warn("Cannot fit " + fieldStr + " in field starting at column " + column.start + " and ending at column " + (column.end - 1) + ". " + "Writing null (all spaces) instead.", PigWarning.UDF_WARNING_2); for (int i = 0; i < width; i++) { sb.append(' '); } } } else { // Field can fit. Right-justify it. int spaces = width - fieldStr.length(); for (int i = 0; i < spaces; i++) { sb.append(' '); } sb.append(fieldStr); } return sb.toString(); }