package mpqa_seq_reranker; import se.lth.cs.nlp.nlputils.ml_long.*; public class RerankingDefinition extends ProblemDefinition { private static final long serialVersionUID = 0; public double cost(NBestRepresentation x, Integer y, Integer ybar) { return x.costs[ybar] - x.costs[y]; } public Integer argmax(NBestRepresentation x, Model model, SparseVector sv, double[] result) { double maxScore = Double.NEGATIVE_INFINITY; int max = -1; for(int i = 0; i < x.reps.length; i++) { double score = model.score(x.reps[i]); if(score > maxScore) { maxScore = score; max = i; } } result[0] = maxScore; encode(x, max, sv); return max; } // TODO för svmstruct borde det nog inte vara sqrt private static final boolean SQRT = true; // 110407: f->t //false; public Integer maxLoss(NBestRepresentation x, Integer y, Model model, SparseVector sv, double[] result) { double maxScore = Double.NEGATIVE_INFINITY; int max = -1; for(int i = 0; i < x.reps.length; i++) { double score = model.score(x.reps[i]); if(SQRT) score += Math.sqrt(x.costs[i] - x.costs[y]); else score += x.costs[i] - x.costs[y]; if(score > maxScore) { maxScore = score; max = i; } } result[0] = model.score(x.reps[max]); result[1] = x.costs[max] - x.costs[y]; encode(x, max, sv); return max; } public void encode(NBestRepresentation x, Integer y, SparseVector sv) { sv.clear(); sv.putAll(x.reps[y]); } public void setMaxFeatureIndex(int n) { System.out.println("Warning: setMaxFeatureIndex ignored"); } }