List of usage examples for java.lang Math log10
@HotSpotIntrinsicCandidate public static double log10(double a)
From source file:com.joptimizer.algebra.MatrixLogSumRescaler.java
/** * Gauss-Seidel scaling for a sparse matrix: * <br>AScaled = U.A.V, with A mxn matrix, U, V diagonal. * Returns the two scaling matrices//from w ww. j a va 2s . c o m * <br>U[i,i] = base^x[i], i=0,...,m * <br>V[i,i] = base^y[i], i=0,...,n * * @see Gajulapalli, Lasdon "Scaling Sparse Matrices for Optimization Algorithms", algorithms 1 and 2 */ public DoubleMatrix1D[] getMatrixScalingFactors(DoubleMatrix2D A) { int m = A.rows(); int n = A.columns(); final double log10_b = Math.log10(base); //Setup for Gauss-Seidel Iterations final int[] R = new int[m]; final int[] C = new int[n]; final double[] t = new double[1]; final double[] a = new double[m]; final double[] b = new double[n]; final boolean[][] Z = new boolean[m][n]; A.forEachNonZero(new IntIntDoubleFunction() { public double apply(int i, int j, double aij) { R[i] = R[i] + 1; C[j] = C[j] + 1; Z[i][j] = true; t[0] = -(Math.log10(Math.abs(aij)) / log10_b + 0.5);// log(b, x) = log(k, x) / log(k, b) a[i] = a[i] + t[0]; b[j] = b[j] + t[0]; return aij; } }); for (int i = 0; i < m; i++) { a[i] = a[i] / R[i]; } for (int j = 0; j < n; j++) { b[j] = b[j] / C[j]; } // log.debug("a: " + ArrayUtils.toString(a)); // log.debug("b: " + ArrayUtils.toString(b)); // log.debug("R: " + ArrayUtils.toString(R)); // log.debug("C: " + ArrayUtils.toString(C)); int[] xx = new int[m]; int[] yy = new int[n]; int[] previousXX = null; int[] previousYY = null; boolean stopX = false; boolean stopY = false; int maxIteration = 3; int l = 0; for (l = 0; l <= maxIteration && !(stopX && stopY); l++) { double[] tt = new double[m]; System.arraycopy(a, 0, tt, 0, m); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { boolean[] ZI = Z[i]; if (ZI[j]) { tt[i] = tt[i] - ((double) yy[j]) / R[i]; } } } for (int k = 0; k < m; k++) { xx[k] = (int) Math.round(tt[k]); } if (previousXX == null) { previousXX = xx; } else { boolean allEquals = true; for (int k = 0; k < m && allEquals; k++) { allEquals = (xx[k] == previousXX[k]); } stopX = allEquals; previousXX = xx; } tt = new double[n]; System.arraycopy(b, 0, tt, 0, n); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (Z[i][j]) { tt[j] = tt[j] - ((double) xx[i]) / C[j]; } } } for (int k = 0; k < n; k++) { yy[k] = (int) Math.round(tt[k]); } if (previousYY == null) { previousYY = yy; } else { boolean allEquals = true; for (int k = 0; k < n && allEquals; k++) { allEquals = (yy[k] == previousYY[k]); } stopY = allEquals; previousYY = yy; } } if (l == maxIteration) { //@TODO: just for test, remove this //throw new RuntimeException("max iterations reached"); } logger.debug("xx: " + ArrayUtils.toString(xx)); logger.debug("yy: " + ArrayUtils.toString(yy)); DoubleMatrix1D u = new DenseDoubleMatrix1D(m); for (int k = 0; k < m; k++) { u.setQuick(k, Math.pow(base, xx[k])); } DoubleMatrix1D v = new DenseDoubleMatrix1D(n); for (int k = 0; k < n; k++) { v.setQuick(k, Math.pow(base, yy[k])); } DoubleMatrix1D[] ret = new DoubleMatrix1D[] { u, v }; return ret; }
From source file:at.tuwien.ifs.commons.util.MathUtils.java
public static int numberOfDigits(long i) { return 1 + (int) Math.log10(Math.abs(i)); }
From source file:edu.jhu.pha.vospace.node.Node.java
public static String readableFileSize(long size) { if (size <= 0) return "0 B"; 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.openmeetings.app.data.file.FileUtils.java
public static String getHumanSize(File dir) { long size = getSize(dir); 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:com.bmwcarit.barefoot.markov.KStateTest.java
@Test public void TestKStateUnbound() { 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<>(); {/*from ww w .ja v a 2s . 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(7, state.size()); assertEquals(9, state.estimate().numid()); List<Integer> sequence = new LinkedList<>(Arrays.asList(2, 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(7, state.size()); assertEquals(13, state.estimate().numid()); List<Integer> sequence = new LinkedList<>(Arrays.asList(2, 6, 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(7, state.size()); assertEquals(13, state.estimate().numid()); List<Integer> sequence = new LinkedList<>(Arrays.asList(2, 6, 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:org.renjin.primitives.MathGroup.java
@Deferrable @Builtin//from w ww. ja v a2 s . c om @DataParallel(value = PreserveAttributeStyle.ALL, passNA = true) public static double log10(double d) { return Math.log10(d); }
From source file:hulo.localization.models.obs.GaussianProcessLDPLMeanMulti.java
double ITUModel(double[] xr, int id) { double[] xs = sourceLocs[id]; return -10.0 * paramsArray[id][0] * Math.log10(distance(xr, xs)) + paramsArray[id][1] - lossByFloorDiff(floorDiff(xr, xs), id); }
From source file:org.dkpro.similarity.experiments.rte.util.WordIdfValuesGenerator.java
public static void computeIdfScores(Dataset dataset) throws Exception { File outputFile = new File(UTILS_DIR + "/word-idf/" + RteUtil.getCommonDatasetName(dataset) + ".txt"); System.out.println("Computing word idf values"); if (outputFile.exists()) { System.out.println(" - skipping, already exists"); } else {//from w w w . j a v a2 s. co m System.out.println(" - this may take a while..."); // Input data File inputDir = new File(UTILS_DIR + "/plaintexts/" + RteUtil.getCommonDatasetName(dataset)); Collection<File> files = FileUtils.listFiles(inputDir, new String[] { "txt" }, false); // Map to hold the idf values Map<String, Double> idfValues = new HashMap<String, Double>(); // Build up token representations of texts Set<List<String>> docs = new HashSet<List<String>>(); for (File file : files) { List<String> doc = new ArrayList<String>(); Collection<Lemma> lemmas = getLemmas(FileUtils.readFileToString(file)); for (Lemma lemma : lemmas) { try { String token = lemma.getValue().toLowerCase(); doc.add(token); } catch (NullPointerException e) { System.err.println(" - unparsable token: " + lemma.getCoveredText()); } } docs.add(doc); } // Get the shared token list Set<String> tokens = new HashSet<String>(); for (List<String> doc : docs) { tokens.addAll(doc); } // Get the idf numbers for (String token : tokens) { double count = 0; for (List<String> doc : docs) { if (doc.contains(token)) { count++; } } idfValues.put(token, count); } // Compute the idf for (String lemma : idfValues.keySet()) { double idf = Math.log10(files.size() / idfValues.get(lemma)); idfValues.put(lemma, idf); } // Store persistently StringBuilder sb = new StringBuilder(); for (String key : idfValues.keySet()) { sb.append(key + "\t" + idfValues.get(key) + LF); } FileUtils.writeStringToFile(outputFile, sb.toString()); System.out.println(" - done"); } }
From source file:ua.aits.Carpath.functions.FileMethods.java
public String getReadableSize(String path, Integer format) { File folder = new File(path); String readableSize = ""; if (folder.exists()) { long size; if (folder.isFile()) { size = folder.length();/* w ww.j av a 2s .co m*/ } else { size = getFolderSize(folder); } String[] units = new String[] { "B", "KB", "MB", "GB", "TB" }; if (size == 0) { return "0 " + units[format]; } int unitIndex = (int) (Math.log10(size) / format); double unitValue = 1 << (unitIndex * 10); readableSize = new DecimalFormat("#,##0.#").format(size / unitValue) + " " + units[unitIndex]; } return readableSize; }
From source file:inflor.core.transforms.LogicleTransform.java
private double optimizeW(double[] data) { /**//from ww w .j a v a 2 s. c o m * Based on the percentile method suggested by Parks/Moore. */ double lowerBound = new Percentile().evaluate(data, LOGICLE_W_PERCENTILE); if (lowerBound < 0) { this.w = (m - Math.log10(t / Math.abs(lowerBound))) / 2; } else { this.w = 0.2;//TODO: Reasonable? } //TODO HACKZ if (w <= 0) w = 0.2; return w; }