public DCGScorer(final int k) { this.k = k; //init cache if we haven't already done so if (discount == null) { discount = new double[5000]; for (int i = 0; i < discount.length; i++) { discount[i] = 1.0 / SimpleMath.logBase2(i + 2); } gain = new double[6]; for (int i = 0; i < 6; i++) { gain[i] = (1 << i) - 1;//2^i - 1 } } }
public void printTrainingTime() { System.out.println("Training time: " + SimpleMath.round((trainingTime)/1e9, 2) + " seconds"); } }
final double alpha_t = 0.5 * SimpleMath.ln((Z_t + R_t) / (Z_t - R_t));//@current_r is computed in learnWeakRanker() Double.toString(SimpleMath.round(wr.getThreshold(), 4)), Double.toString(SimpleMath.round(R_t, 4)) }); if (t % 1 == 0) { printLog(new int[] { 9 }, new String[] { Double.toString(SimpleMath.round(scorer.score(rank(samples)), 4)) }); if (validationSamples != null) { final double score = scorer.score(rank(validationSamples)); bestModelWeights.addAll(rWeight); printLog(new int[] { 9 }, new String[] { Double.toString(SimpleMath.round(score, 4)) }); scoreOnTrainingData = SimpleMath.round(scorer.score(rank(samples)), 4); logger.info(() -> "Finished sucessfully."); logger.info(() -> scorer.name() + " on training data: " + scoreOnTrainingData); if (validationSamples != null) { bestScoreOnValidationData = scorer.score(rank(validationSamples)); logger.info(() -> scorer.name() + " on validation data: " + SimpleMath.round(bestScoreOnValidationData, 4));
final double alpha_t = 0.5 * SimpleMath.ln(num / denom); rweight.add(alpha_t); printLog(new int[] { 8, 9, }, new String[] { Integer.toString(bestWR.getFID()), Double.toString(SimpleMath.round(trainedScore, 4)) }); if (t % 1 == 0 && validationSamples != null) { final double scoreOnValidation = scorer.score(rank(validationSamples)); updateBestModelOnValidation(); printLog(new int[] { 9, 9 }, new String[] { Double.toString(SimpleMath.round(scoreOnValidation, 4)), status }); } else { printLog(new int[] { 9, 9 }, new String[] { "", status });
public void printTrainingTime() { logger.info(() -> "Training time: " + SimpleMath.round((trainingTime) / 1e9, 2) + " seconds"); } }
double alpha_t = (double) (0.5 * SimpleMath.ln(num/denom)); rweight.add(alpha_t); PRINT(new int[]{8, 9, }, new String[]{bestWR.getFID()+"", SimpleMath.round(trainedScore, 4)+""}); if(t % 1==0 && validationSamples != null) updateBestModelOnValidation(); PRINT(new int[]{9, 9}, new String[]{SimpleMath.round(scoreOnValidation, 4)+"", status});
public DCGScorer() { this.k = 10; //init cache if we haven't already done so if (discount == null) { discount = new double[5000]; for (int i = 0; i < discount.length; i++) { discount[i] = 1.0 / SimpleMath.logBase2(i + 2); } gain = new double[6]; for (int i = 0; i < 6; i++) { gain[i] = (1 << i) - 1;//2^i-1 } } }
/** * Evaluate the performance (in -metric2T) of the input rankings * @param testFile Input rankings */ public void test(String testFile) { List<RankList> test = readInput(testFile); double rankScore = evaluate(null, test); System.out.println(testScorer.name() + " on test data: " + SimpleMath.round(rankScore, 4)); } public void test(String testFile, String prpFile)
break; double alpha_t = (double) (0.5 * SimpleMath.ln((Z_t+R_t)/(Z_t-R_t)));//@current_r is computed in learnWeakRanker() PRINT(new int[]{7, 8, 9, 9}, new String[]{t+"", wr.getFid()+"", SimpleMath.round(wr.getThreshold(), 4)+"", SimpleMath.round(R_t, 4)+""}); if(t % 1 == 0) PRINT(new int[]{9}, new String[]{SimpleMath.round(scorer.score(rank(samples)), 4)+""}); if(validationSamples != null) bestModelWeights.addAll(rWeight); PRINT(new int[]{9}, new String[]{SimpleMath.round(score, 4)+""}); scoreOnTrainingData = SimpleMath.round(scorer.score(rank(samples)), 4); PRINTLN("--------------------------------------------------------------------"); PRINTLN("Finished sucessfully."); PRINTLN(scorer.name() + " on validation data: " + SimpleMath.round(bestScoreOnValidationData, 4));
public DCGScorer(int k) { this.k = k; //init cache if we haven't already done so if(discount == null) { discount = new double[5000]; for(int i=0;i<discount.length;i++) discount[i] = 1.0/SimpleMath.logBase2(i+2); gain = new double[6]; for(int i=0;i<6;i++) gain[i] = (1<<i) - 1;//2^i - 1 } } public MetricScorer copy()
/** * Evaluate the performance (in -metric2T) of the input rankings * @param testFile Input rankings */ public void test(final String testFile) { final List<RankList> test = readInput(testFile); final double rankScore = evaluate(null, test); logger.info(() -> testScorer.name() + " on test data: " + SimpleMath.round(rankScore, 4)); }
public DCGScorer() { this.k = 10; //init cache if we haven't already done so if(discount == null) { discount = new double[5000]; for(int i=0;i<discount.length;i++) discount[i] = 1.0/SimpleMath.logBase2(i+2); gain = new double[6]; for(int i=0;i<6;i++) gain[i] = (1<<i) - 1;//2^i-1 } } public DCGScorer(int k)
public void test(String testFile, String prpFile) { List<RankList> test = readInput(testFile); double rankScore = 0.0; List<String> ids = new ArrayList<String>(); List<Double> scores = new ArrayList<Double>(); for(int i=0;i<test.size();i++) { RankList l = test.get(i); double score = testScorer.score(l); ids.add(l.getID()); scores.add(score); rankScore += score; } rankScore /= test.size(); ids.add("all"); scores.add(rankScore); System.out.println(testScorer.name() + " on test data: " + SimpleMath.round(rankScore, 4)); if(prpFile.compareTo("") != 0) { savePerRankListPerformanceFile(ids, scores, prpFile); System.out.println("Per-ranked list performance saved to: " + prpFile); } } /**
protected double crossEntropy(double o1, double o2, double targetValue) { double oij = o1 - o2; double ce = -targetValue * oij + SimpleMath.logBase2(1+Math.exp(oij)); return (double) ce; } protected void estimateLoss()
public void test(final String testFile, final String prpFile) { final List<RankList> test = readInput(testFile); double rankScore = 0.0; final List<String> ids = new ArrayList<>(); final List<Double> scores = new ArrayList<>(); for (final RankList l : test) { final double score = testScorer.score(l); ids.add(l.getID()); scores.add(score); rankScore += score; } rankScore /= test.size(); ids.add("all"); scores.add(rankScore); if (logger.isLoggable(Level.INFO)) { logger.info(testScorer.name() + " on test data: " + SimpleMath.round(rankScore, 4)); } if (!prpFile.isEmpty()) { savePerRankListPerformanceFile(ids, scores, prpFile); logger.info(() -> "Per-ranked list performance saved to: " + prpFile); } }
protected double crossEntropy(final double o1, final double o2, final double targetValue) { final double oij = o1 - o2; return -targetValue * oij + SimpleMath.logBase2(1 + Math.exp(oij)); }
/** * Generate a ranking in Indri's format from the input ranking * @param testFile * @param indriRanking */ public void rank(final String testFile, final String indriRanking) { final List<RankList> test = readInput(testFile); try (final BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(indriRanking), "UTF-8"))) { for (final RankList l : test) { for (int j = 0; j < l.size(); j++) { final String str = l.getID() + " Q0 " + l.get(j).getDescription().replace("#", "").trim() + " " + (j + 1) + " " + SimpleMath.round(1.0 - 0.0001 * j, 5) + " indri"; out.write(str); out.newLine(); } } } catch (final IOException ex) { throw RankLibError.create("Error in Evaluator::rank(): ", ex); } }
protected double discount(final int index) { if (index < discount.length) { return discount[index]; } //we need to expand our cache int cacheSize = discount.length + 1000; while (cacheSize <= index) { cacheSize += 1000; } final double[] tmp = new double[cacheSize]; System.arraycopy(discount, 0, tmp, 0, discount.length); for (int i = discount.length; i < tmp.length; i++) { tmp[i] = 1.0 / SimpleMath.logBase2(i + 2); } discount = tmp; return discount[index]; }
logger.info(() -> FileUtils.getFileName(baseFile) + " [baseline]\t" + SimpleMath.round(base.get("all").doubleValue(), 4)); for (int i = 0; i < rs.length; i++) { if (rs[i].status == 0) { final double delta = targets.get(i).get("all") - base.get("all"); final double dp = delta * 100 / base.get("all"); logger.info(FileUtils.getFileName(targetFiles.get(i)) + "\t" + SimpleMath.round(targets.get(i).get("all").doubleValue(), 4) + "\t" + ((delta > 0) ? "+" : "") + SimpleMath.round(delta, 4) + " (" + ((delta > 0) ? "+" : "") + SimpleMath.round(dp, 2) + "%)" + "\t" + rs[i].win + "\t" + rs[i].loss + "\t" + randomizedTest.test(targets.get(i), base)); } else {
protected double discount(int index) { if(index < discount.length) return discount[index]; //we need to expand our cache int cacheSize = discount.length + 1000; while(cacheSize <= index) cacheSize += 1000; double[] tmp = new double[cacheSize]; System.arraycopy(discount, 0, tmp, 0, discount.length); for(int i=discount.length;i<tmp.length;i++) tmp[i] = 1.0/SimpleMath.logBase2(i+2); discount = tmp; return discount[index]; } protected double gain(int rel)