public double[] computeAnswerTypeProbs(Parse question) { String[] context = atcg.getContext(question);//<co id="atc.context"/> return model.eval(context, probs);//<co id="atc.evaluate"/> } /*
public double[] numberDist(Context c) { List<String> feats = getFeatures(c); return testModel.eval(feats.toArray(new String[feats.size()])); }
/** * Returns a number between 0 and 1 which represents the models belief that the specified mentions are compatible. * Value closer to 1 are more compatible, while values closer to 0 are less compatible. * @param mention1 The first mention to be considered. * @param mention2 The second mention to be considered. * @return a number between 0 and 1 which represents the models belief that the specified mentions are compatible. */ public double compatible(Context mention1, Context mention2) { List<String> feats = getFeatures(mention1, mention2); if (debugOn) System.err.println("SimilarityModel.compatible: feats="+feats); return (testModel.eval(feats.toArray(new String[feats.size()]))[SAME_INDEX]); }
public double[] genderDistribution(Context np1) { List<String> features = getFeatures(np1); if (debugOn) { //System.err.println("GenderModel.genderDistribution: "+features); } return testModel.eval(features.toArray(new String[features.size()])); }
public double getNonReferentialProbability(MentionContext mention) { List<String> features = getFeatures(mention); double r = model.eval(features.toArray(new String[features.size()]))[nonRefIndex]; if (debugOn) System.err.println(this +" " + mention.toText() + " -> null " + r + " " + features); return r; }
private void eval(Event event, boolean real) { String outcome = event.getOutcome(); // Is ignored String[] context = event.getContext(); double[] ocs; if (!real) { ocs = _model.eval(context); } else { float[] values = RealValueFileEventStream.parseContexts(context); ocs = _model.eval(context, values); } int numOutcomes = ocs.length; DoubleStringPair[] result = new DoubleStringPair[numOutcomes]; for (int i=0; i<numOutcomes; i++) result[i] = new DoubleStringPair(ocs[i], _model.getOutcome(i)); java.util.Arrays.sort(result); // Print the most likely outcome first, down to the least likely. for (int i=numOutcomes-1; i>=0; i--) System.out.print(result[i].stringValue + " " + result[i].doubleValue + " "); System.out.println(); }
@Override public List<Decision> decide(List<FeatureResult<?>> featureResults) { List<String> contextList = new ArrayList<String>(); List<Float> weightList = new ArrayList<Float>(); OpenNLPDecisionMaker.prepareData(featureResults, contextList, weightList); String[] contexts = new String[contextList.size()]; float[] weights = new float[weightList.size()]; int i = 0; for (String context : contextList) { contexts[i++] = context; } i = 0; for (Float weight : weightList) { weights[i++] = weight; } double[] probs = model.eval(contexts, weights); String[] outcomes = new String[probs.length]; for (i = 0; i < probs.length; i++) outcomes[i] = model.getOutcome(i); TreeSet<Decision> outcomeSet = new TreeSet<Decision>(); for (i = 0; i < probs.length; i++) { Decision decision = new Decision(outcomes[i], probs[i]); outcomeSet.add(decision); } List<Decision> decisions = new ArrayList<Decision>(outcomeSet); return decisions; }
private void eval(Event event, boolean real) { String outcome = event.getOutcome(); // Is ignored String[] context = event.getContext(); double[] ocs; if (!real) { ocs = _model.eval(context); } else { float[] values = RealValueFileEventStream.parseContexts(context); ocs = _model.eval(context, values); } int numOutcomes = ocs.length; DoubleStringPair[] result = new DoubleStringPair[numOutcomes]; for (int i=0; i<numOutcomes; i++) result[i] = new DoubleStringPair(ocs[i], _model.getOutcome(i)); java.util.Arrays.sort(result); // Print the most likely outcome first, down to the least likely. for (int i=numOutcomes-1; i>=0; i--) System.out.print(result[i].stringValue + " " + result[i].doubleValue + " "); System.out.println(); }
public static void eval(MaxentModel model, Reader r, Evalable e, boolean verbose) { float totPos=0, truePos=0, falsePos=0; Event[] events = (e.getEventCollector(r)).getEvents(true); //MaxentModel model = e.getModel(dir, name); String negOutcome = e.getNegativeOutcome(); for (Event event : events) { String guess = model.getBestOutcome(model.eval(event.getContext())); String ans = event.getOutcome(); if (verbose) System.out.println(ans + " " + guess); if (!ans.equals(negOutcome)) totPos++; if (!guess.equals(negOutcome) && !guess.equals(ans)) falsePos++; else if (ans.equals(guess)) truePos++; } System.out.println("Precision: " + truePos/(truePos+falsePos)); System.out.println("Recall: " + truePos/totPos); }
public static void eval(MaxentModel model, Reader r, Evalable e, boolean verbose) { float totPos=0, truePos=0, falsePos=0; Event[] events = (e.getEventCollector(r)).getEvents(true); //MaxentModel model = e.getModel(dir, name); String negOutcome = e.getNegativeOutcome(); for (Event event : events) { String guess = model.getBestOutcome(model.eval(event.getContext())); String ans = event.getOutcome(); if (verbose) System.out.println(ans + " " + guess); if (!ans.equals(negOutcome)) totPos++; if (!guess.equals(negOutcome) && !guess.equals(ans)) falsePos++; else if (ans.equals(guess)) truePos++; } System.out.println("Precision: " + truePos/(truePos+falsePos)); System.out.println("Recall: " + truePos/totPos); }
@Override public Map<OUTCOME_TYPE, Double> score(List<Feature> features) throws CleartkProcessingException { ContextValues contextValues = this.featuresEncoder.encodeAll(features); double[] evalResults = this.model.eval(contextValues.getContext(), contextValues.getValues()); String[] encodedOutcomes = (String[]) this.model.getDataStructures()[2]; Map<OUTCOME_TYPE, Double> returnValues = Maps.newHashMap(); for (int i = 0; i < evalResults.length; i++) { returnValues.put(outcomeEncoder.decode(encodedOutcomes[i]), evalResults[i]); } return returnValues; }
double[] outcomeProbs = loadedMaxentModel.eval(context); String outcome = loadedMaxentModel.getBestOutcome(outcomeProbs);
public OUTCOME_TYPE classify(List<Feature> features) throws CleartkProcessingException { ContextValues contextValues = this.featuresEncoder.encodeAll(features); String encodedOutcome = this.model.getBestOutcome(this.model.eval( contextValues.getContext(), contextValues.getValues())); return outcomeEncoder.decode(encodedOutcome); }
logger.info(Arrays.asList(context).toString()); float[] values = RealValueFileEventStream.parseContexts(context); double[] ocs = model.eval(context, values); int numOutcomes = ocs.length; DoubleStringPair[] result = new DoubleStringPair[numOutcomes];
String[] features = lfeatures.toArray(new String[lfeatures.size()]); try { candProbs[ei] = model.eval(features)[sameIndex];