/** * Bob Jenkins One-at-a-Time hash function * <p/> * @return hashcode for the given input; */ public static int hashCode(int... v) { return finishHash(combineHash(31, v)); }
@Override public int hashCode() { return MathTools.finishHash(MathTools.hashCode(synid.hashCode())); }
@Override public int getPartition(IntWritable key, Object value, int numPartitions) { return MathTools.mod(key.get(), numPartitions); }
@Override public int hashCode() { if (hashcode == -1) hashcode = MathTools.hashCode(termid); return hashcode; }
public static int combineHash(int seed, long... v) { if (v != null) { for (int i = 0; i < v.length; i++) { seed = combineHash(seed, (int)(v[i] >>> 32), (int)v[i]); } } return seed; }
/** * * @param p * @return */ public static int StdNormalOneTailed(double p) { double z = MathTools.stdNormalZ(0.5 + p / 2); double r = getStdNormal(); r = (r < 0) ? -r : r; int dev = (int) java.lang.Math.floor(r / z); return dev; } static double StdNormalOneTailedCompCorrection = 0.79 / (0.282 / (0.282 + 0.115));
@Override public double metricAtPosition(int position, double previousscore, int relevant) { if (position == 0) { return relevant; } return previousscore + relevant / MathTools.log2(position + 1); }
/** * * @param p * @return */ public static double stdNormalZ(double p) { // compute Z given P double Z_EPSILON = 0.000001; /* Accuracy of z approximation */ double minz = -Z_MAX; double maxz = Z_MAX; double zval = 0.0; double pval; if (p < 0.0 || p > 1.0) { return -1; } while ((maxz - minz) > Z_EPSILON) { pval = stdNormalP(zval); if (pval > p) { maxz = zval; } else { minz = zval; } zval = (maxz + minz) * 0.5; } return (zval); }
static double gamma(double x) { return Math.exp(logGamma(x)); }
/** * * @param d * @param precision * @return */ public static String roundPrecisionStr(double d, int precision) { char decimal = new DecimalFormatSymbols().getDecimalSeparator(); d = roundPrecision(d, precision); String s = sprintf("%f", d); for (int i = 0; i < s.length() && (s.charAt(i) == '0' || s.charAt(i) == decimal); i++) { if (s.charAt(i) == '0') { precision++; } } if (precision > s.length()) { precision = 1; } if (precision < s.length() - 1 && s.indexOf(decimal) < precision) { return s.substring(0, precision + 1); } else { return s.substring(0, precision); } }
protected void setDuplicateDependency() { ArrayList<ProximityTermDupl> list = first.dupl; HashSet<Long> dep = new HashSet<Long>(); for (int i = (1 << first.dupl.size()) - 1; i > 0; i--) { if (MathTools.numberOfSetBits(i) == (initshift + 1)) { long pattern = 0; int b = 1; for (int j = 0; b <= i; j++, b <<= 1) { if ((i & b) != 0) { pattern |= ProximitySet.this.dependency[first.dupl.get(j).sequence]; } } dep.add(convertDuplicatesInPattern(pattern, sequence)); } } HashSet<Long> dep1 = new HashSet<Long>(); SKIP: for (long d : dep) { for (long m : dep) { if (m != d && (d & m) == m) { continue SKIP; } } dep1.add(d); } dependency = ArrayTools.toLongArray(dep1); }
@Override public int hashCode() { return MathTools.hashCode(query.hashCode()); }
/** * * @param p * @return */ public static int StdNormalOneTailedComp(double p) { double z = MathTools.stdNormalZ(0.5 + p / 2); double r = getStdNormal(); r = (r < 0) ? -r : r; double v = r / z; int dev = (int) java.lang.Math.floor(v); if (dev > 0) { dev = (int) java.lang.Math.floor(v * StdNormalOneTailedCompCorrection); } return dev; }
public static int hashCode(long... v) { return finishHash(combineHash(31, v)); }
@Override public int hashCode() { return MathTools.finishHash(MathTools.hashCode(query.hashCode())); }
public static int getPartition(String docid, int partitions) { return MathTools.mod(docid.hashCode(), partitions); }
@Override public int hashCode() { return MathTools.hashCode(value1.hashCode(), value2.hashCode()); }
@Override public int hashCode() { int hash = 31; for (Map.Entry<String, String> e : parameters.entrySet()) { hash = MathTools.combineHash(hash, e.getKey().hashCode()); hash = MathTools.combineHash(hash, e.getValue().hashCode()); } return MathTools.finishHash(hash); }
@Override public int hashCode() { return MathTools.finishHash(MathTools.hashCode(query.hashCode())); }
@Override public int getPartition(IntIntWritable key, Object value, int numPartitions) { return MathTools.mod(key.get(), numPartitions); }