} else if (args[0].equals("-logAdd")) { System.out.println("Log adds of neg infinity numbers, etc."); System.out.println("(logs) -Inf + -Inf = " + logAdd(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY)); System.out.println("(logs) -Inf + -7 = " + logAdd(Double.NEGATIVE_INFINITY, -7.0)); System.out.println("(logs) -7 + -Inf = " + logAdd(-7.0, Double.NEGATIVE_INFINITY)); System.out.println("(logs) -50 + -7 = " + logAdd(-50.0, -7.0)); System.out.println("(logs) -11 + -7 = " + logAdd(-11.0, -7.0)); System.out.println("(logs) -7 + -11 = " + logAdd(-7.0, -11.0)); System.out.println("real 1/2 + 1/2 = " + logAdd(Math.log(0.5), Math.log(0.5))); } else if (args[0].equals("-fishers")) { int k = Integer.parseInt(args[1]); int r = Integer.parseInt(args[3]); int m = Integer.parseInt(args[4]); double ans = SloppyMath.hypergeometric(k, n, r, m); System.out.println("hypg(" + k + "; " + n + ", " + r + ", " + m + ") = " + ans); ans = SloppyMath.oneTailedFishersExact(k, n, r, m); System.out.println("1-tailed Fisher's exact(" + k + "; " + n + ", " + r + ", " + m + ") = " + ans); double ansChi = SloppyMath.chiSquare2by2(k, n, r, m); System.out.println("chiSquare(" + k + "; " + n + ", " + r + ", " + m + ") = " + ansChi); ans = SloppyMath.hypergeometric(k, n, r, m); System.out.println("hypg(" + k + "; " + n + ", " + m + ", " + r + ") = " + ans); int othrow = n - m; int cell21 = r - k; int cell22 = othrow - (r - k); ans = SloppyMath.hypergeometric(cell12, n, othcol, m); System.out.println("hypg(" + cell12 + "; " + n + ", " + othcol + ", " + m + ") = " + ans);
public static double poisson(int x, double lambda) { if (x<0 || lambda<=0.0) throw new RuntimeException("Bad arguments: " + x + " and " + lambda); double p = (Math.exp(-lambda) * Math.pow(lambda, x)) / factorial(x); if (Double.isInfinite(p) || p<=0.0) throw new RuntimeException(Math.exp(-lambda) +" "+ Math.pow(lambda, x) + ' ' + factorial(x)); return p; }
public void clean() { for (K1 key1 : Generics.newHashSet(map.keySet())) { ClassicCounter<K2> c = map.get(key1); for (K2 key2 : Generics.newHashSet(c.keySet())) { if (SloppyMath.isCloseTo(0.0, c.getCount(key2))) { c.remove(key2); } } if (c.keySet().isEmpty()) { map.remove(key1); } } }
void logIncrementValue(int index, double value) { table[index] = SloppyMath.logAdd(table[index], value); }
d[i][j] = SloppyMath.max(d[i - 1][j], d[i][j - 1], d[i - 1][j - 1] + 1); } else { d[i][j] = Math.max(d[i - 1][j], d[i][j - 1]);
/** * Returns a new Counter which is the input counter with log tf scaling * * @param c The counter to scale. It is not changed * @param base The base of the logarithm used for tf scaling by 1 + log tf * @return A new Counter which is the argument scaled by the given scale * factor. */ @SuppressWarnings("unchecked") public static <E, C extends Counter<E>> C tfLogScale(C c, double base) { C scaled = (C) c.getFactory().create(); for (E key : c.keySet()) { double cnt = c.getCount(key); double scaledCnt = 0.0; if (cnt > 0) { scaledCnt = 1.0 + SloppyMath.log(cnt, base); } scaled.setCount(key, scaledCnt); } return scaled; }
d[i][j] = SloppyMath.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
total += SloppyMath.hypergeometric(k0, n, r, m); total += SloppyMath.hypergeometric(k0, n, r, m);
private void logIncrementValue(int index, float value) { table[index] = SloppyMath.logAdd(table[index], value); }
/** * Returns a new Counter which is the input counter with log tf scaling * * @param c The counter to scale. It is not changed * @param base The base of the logarithm used for tf scaling by 1 + log tf * @return A new Counter which is the argument scaled by the given scale factor. */ @SuppressWarnings("unchecked") public static <E,C extends Counter<E>> C tfLogScale(C c, double base) { C scaled = (C) c.getFactory().create(); for (E key : c.keySet()) { double cnt = c.getCount(key); double scaledCnt = 0.0; if (cnt > 0) { scaledCnt = 1.0 + SloppyMath.log(cnt, base); } scaled.setCount(key, scaledCnt); } return scaled; }
d[i][j] = SloppyMath.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
total += SloppyMath.hypergeometric(k0, n, r, m); total += SloppyMath.hypergeometric(k0, n, r, m);
} else if (args[0].equals("-logAdd")) { System.out.println("Log adds of neg infinity numbers, etc."); System.out.println("(logs) -Inf + -Inf = " + logAdd(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY)); System.out.println("(logs) -Inf + -7 = " + logAdd(Double.NEGATIVE_INFINITY, -7.0)); System.out.println("(logs) -7 + -Inf = " + logAdd(-7.0, Double.NEGATIVE_INFINITY)); System.out.println("(logs) -50 + -7 = " + logAdd(-50.0, -7.0)); System.out.println("(logs) -11 + -7 = " + logAdd(-11.0, -7.0)); System.out.println("(logs) -7 + -11 = " + logAdd(-7.0, -11.0)); System.out.println("real 1/2 + 1/2 = " + logAdd(Math.log(0.5), Math.log(0.5))); } else if (args[0].equals("-fishers")) { int k = Integer.parseInt(args[1]); int r = Integer.parseInt(args[3]); int m = Integer.parseInt(args[4]); double ans = SloppyMath.hypergeometric(k, n, r, m); System.out.println("hypg(" + k + "; " + n + ", " + r + ", " + m + ") = " + ans); ans = SloppyMath.oneTailedFishersExact(k, n, r, m); System.out.println("1-tailed Fisher's exact(" + k + "; " + n + ", " + r + ", " + m + ") = " + ans); double ansChi = SloppyMath.chiSquare2by2(k, n, r, m); System.out.println("chiSquare(" + k + "; " + n + ", " + r + ", " + m + ") = " + ansChi); ans = SloppyMath.hypergeometric(k, n, r, m); System.out.println("hypg(" + k + "; " + n + ", " + m + ", " + r + ") = " + ans); int othrow = n - m; int cell21 = r - k; int cell22 = othrow - (r - k); ans = SloppyMath.hypergeometric(cell12, n, othcol, m); System.out.println("hypg(" + cell12 + "; " + n + ", " + othcol + ", " + m + ") = " + ans);
public void logIncrementValue(int[] label, float value) { int index = indexOf(label); table[index] = SloppyMath.logAdd(table[index], value); }
if (tree.numChildren() == 1) { UnaryRule ur = new UnaryRule(parent, firstChild); double score = SloppyMath.max(ug.scoreRule(ur), -10000.0) + validateBinarizedTree(tree.children()[0], start); double bound = iScore[start][start + tree.yield().size()][parent]; if (score > bound + epsilon) { double score = SloppyMath.max(bg.scoreRule(br), -10000.0) + validateBinarizedTree(tree.children()[0], start) + validateBinarizedTree(tree.children()[1], start + tree.children()[0].yield().size()); double bound = iScore[start][start + tree.yield().size()][parent]; if (score > bound + epsilon) {
public void clean() { for (K1 key1 : new HashSet<K1>(map.keySet())) { ClassicCounter<K2> c = map.get(key1); for (K2 key2 : new HashSet<K2>(c.keySet())) { if (SloppyMath.isCloseTo(0.0, c.getCount(key2))) { c.remove(key2); } } if (c.keySet().isEmpty()) { map.remove(key1); } } }
public static double poisson(int x, double lambda) { if (x<0 || lambda<=0.0) throw new RuntimeException("Bad arguments: " + x + " and " + lambda); double p = (Math.exp(-lambda) * Math.pow(lambda, x)) / factorial(x); if (Double.isInfinite(p) || p<=0.0) throw new RuntimeException(Math.exp(-lambda) +" "+ Math.pow(lambda, x) + ' ' + factorial(x)); return p; }
/** * Returns a new Counter which is the input counter with log tf scaling * * @param c The counter to scale. It is not changed * @param base The base of the logarithm used for tf scaling by 1 + log tf * @return A new Counter which is the argument scaled by the given scale * factor. */ @SuppressWarnings("unchecked") public static <E, C extends Counter<E>> C tfLogScale(C c, double base) { C scaled = (C) c.getFactory().create(); for (E key : c.keySet()) { double cnt = c.getCount(key); double scaledCnt = 0.0; if (cnt > 0) { scaledCnt = 1.0 + SloppyMath.log(cnt, base); } scaled.setCount(key, scaledCnt); } return scaled; }
d[i][j] = SloppyMath.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);