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 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() { 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 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()
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)); }
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()
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]; }
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)
@Override protected void estimateLoss() { error = 0.0; double sumLabelExp = 0; double sumScoreExp = 0; for (int i = 0; i < samples.size(); i++) { final RankList rl = samples.get(i); final double[] scores = new double[rl.size()]; double err = 0; for (int j = 0; j < rl.size(); j++) { scores[j] = eval(rl.get(j)); sumLabelExp += Math.exp(rl.get(j).getLabel()); sumScoreExp += Math.exp(scores[j]); } for (int j = 0; j < rl.size(); j++) { final double p1 = Math.exp(rl.get(j).getLabel()) / sumLabelExp; final double p2 = (Math.exp(scores[j]) / sumScoreExp); err += -p1 * SimpleMath.logBase2(p2); } error += err / rl.size(); } lastError = error; }
protected void estimateLoss() { error = 0.0; double sumLabelExp = 0; double sumScoreExp = 0; for(int i=0;i<samples.size();i++) { RankList rl = samples.get(i); double[] scores = new double[rl.size()]; double err = 0; for(int j=0;j<rl.size();j++) { scores[j] = eval(rl.get(j)); sumLabelExp += Math.exp(rl.get(j).getLabel()); sumScoreExp += Math.exp(scores[j]); } for(int j=0;j<rl.size();j++) { double p1 = Math.exp(rl.get(j).getLabel())/sumLabelExp; double p2 = (Math.exp(scores[j])/sumScoreExp); err += - p1 * SimpleMath.logBase2(p2) ; } error += err/rl.size(); } //if(error > lastError && Neuron.learningRate > 0.0000001) //Neuron.learningRate *= 0.9; lastError = error; }
+ "Supported: MAP, NDCG@k, DCG@k, P@k, RR@k, ERR@k (default=ERR@10)"); logger.info(() -> "\t[ -gmax <label> ]\tHighest judged relevance label. It affects the calculation of ERR " + "(default=" + (int) SimpleMath.logBase2(ERRScorer.MAX) + ", i.e. 5-point scale {0,1,2,3,4})"); logger.info(() -> "\t[ -qrel <file> ]\tTREC-style relevance judgment file. It only affects MAP and NDCG (default=unspecified)"); logger.info(() -> "\t[ -silent ]\t\tDo not print progress messages (which are printed by default)"); logger.info(() -> "\t[ -metric2T <metric> ]\tMetric to evaluate on the test data (default=ERR@10)"); logger.info(() -> "\t[ -gmax <label> ]\tHighest judged relevance label. It affects the calculation of ERR (default=" + (int) SimpleMath.logBase2(ERRScorer.MAX) + ", i.e. 5-point scale {0,1,2,3,4})"); logger.info(() -> "\t[ -score <file>]\tStore ranker's score for each object being ranked (has to be used with -rank)"); logger.info(() -> "\t[ -qrel <file> ]\tTREC-style relevance judgment file. It only affects MAP and NDCG (default=unspecified)"); logger.info(() -> "Highest relevance label (to compute ERR): " + (int) SimpleMath.logBase2(ERRScorer.MAX)); logger.info(() -> "Highest relevance label (to compute ERR): " + (int) SimpleMath.logBase2(ERRScorer.MAX));
System.out.println("\t[ -gmax <label> ]\tHighest judged relevance label. It affects the calculation of ERR (default=" + (int)SimpleMath.logBase2(ERRScorer.MAX) + ", i.e. 5-point scale {0,1,2,3,4})"); System.out.println("\t[ -qrel <file> ]\tTREC-style relevance judgment file. It only affects MAP and NDCG (default=unspecified)"); System.out.println("\t[ -silent ]\t\tDo not print progress messages (which are printed by default)"); System.out.println("\t-rank <file>\t\tRank the samples in the specified file (specify either this or -test but not both)"); System.out.println("\t[ -metric2T <metric> ]\tMetric to evaluate on the test data (default=" + trainMetric + ")"); System.out.println("\t[ -gmax <label> ]\tHighest judged relevance label. It affects the calculation of ERR (default=" + (int)SimpleMath.logBase2(ERRScorer.MAX) + ", i.e. 5-point scale {0,1,2,3,4})"); System.out.println("\t[ -score <file>]\tStore ranker's score for each object being ranked (has to be used with -rank)"); System.out.println("\t[ -qrel <file> ]\tTREC-style relevance judgment file. It only affects MAP and NDCG (default=unspecified)"); System.out.println("Highest relevance label (to compute ERR): " + (int)SimpleMath.logBase2(ERRScorer.MAX)); if(qrelFile.compareTo("") != 0) System.out.println("TREC-format relevance judgment (only affects MAP and NDCG scores): " + qrelFile); System.out.println("Highest relevance label (to compute ERR): " + (int)SimpleMath.logBase2(ERRScorer.MAX));