protected AbstractModel(Context[] params, String[] predLabels, Map<String, Context> pmap, String[] outcomeNames) { this.pmap = pmap; this.outcomeNames = outcomeNames; this.evalParams = new EvalParameters(params,outcomeNames.length); }
public int getNumOutcomes() { return evalParams.getNumOutcomes(); }
/** * Provides the fundamental data structures which encode the maxent model * information. This method will usually only be needed by * GISModelWriters. The following values are held in the Object array * which is returned by this method: * <ul> * <li>index 0: opennlp.tools.ml.maxent.Context[] containing the model * parameters * <li>index 1: java.util.Map containing the mapping of model predicates * to unique integers * <li>index 2: java.lang.String[] containing the names of the outcomes, * stored in the index of the array which represents their * unique ids in the model. * </ul> * * @return An Object[] with the values as described above. */ public final Object[] getDataStructures() { Object[] data = new Object[3]; data[0] = evalParams.getParams(); data[1] = pmap; data[2] = outcomeNames; return data; }
static double[] eval(Context[] context, float[] values, double[] prior, EvalParameters model, boolean normalize) { Context[] params = model.getParams(); double[] activeParameters; int[] activeOutcomes; int numOutcomes = model.getNumOutcomes();
public final double[] eval(String[] context, float[] values) { return (eval(context, values, new double[evalParams.getNumOutcomes()])); }
public AbstractModel(Context[] params, String[] predLabels, String[] outcomeNames) { init(predLabels, params, outcomeNames); this.evalParams = new EvalParameters(params, outcomeNames.length); }
static double[] eval(int[] context, float[] values, double[] prior, EvalParameters model, boolean normalize) { Context[] scontexts = new Context[context.length]; for (int i = 0; i < context.length; i++) { scontexts[i] = model.getParams()[context[i]]; } return eval(scontexts, values, prior, model, normalize); }
public double[] eval(String[] context, float[] values) { return eval(context, values, new double[evalParams.getNumOutcomes()]); }
private MutableContext[] findParameters() { int[] allOutcomesPattern = new int[numOutcomes]; for (int oi = 0; oi < numOutcomes; oi++) allOutcomesPattern[oi] = oi; /* Stores the estimated parameter value of each predicate during iteration. */ MutableContext[] params = new MutableContext[numPreds]; for (int pi = 0; pi < numPreds; pi++) { params[pi] = new MutableContext(allOutcomesPattern, new double[numOutcomes]); for (int aoi = 0; aoi < numOutcomes; aoi++) params[pi].setParameter(aoi, 0.0); } EvalParameters evalParams = new EvalParameters(params, numOutcomes); double stepSize = 1; for (int ei = 0; ei < numUniqueEvents; ei++) { int targetOutcome = outcomeList[ei]; for (int ni = 0; ni < this.numTimesEventsSeen[ei]; ni++) { for (int ci = 0; ci < contexts[ei].length; ci++) { int pi = contexts[ei][ci]; if (values == null) { params[pi].updateParameter(targetOutcome, stepSize); } else { params[pi].updateParameter(targetOutcome, stepSize * values[ei][ci]); } } } } // Output the final training stats. trainingStats(evalParams); return params; }
static double[] eval(int[] context, float[] values, double[] prior, EvalParameters model, boolean normalize) { Context[] scontexts = new Context[context.length]; for (int i = 0; i < context.length; i++) { scontexts[i] = model.getParams()[context[i]]; } return eval(scontexts, values, prior, model, normalize); }
public double[] eval(String[] context, float[] values) { return eval(context, values, new double[evalParams.getNumOutcomes()]); }
protected AbstractModel(Context[] params, String[] predLabels, Map<String, Context> pmap, String[] outcomeNames) { this.pmap = pmap; this.outcomeNames = outcomeNames; this.evalParams = new EvalParameters(params,outcomeNames.length); }
/** * Use this model to evaluate a context and return an array of the likelihood * of each outcome given the specified context and the specified parameters. * * @param context * The integer values of the predicates which have been observed at * the present decision point. * @param values * The values for each of the parameters. * @param prior * The prior distribution for the specified context. * @param model * The set of parametes used in this computation. * @return The normalized probabilities for the outcomes given the context. * The indexes of the double[] are the outcome ids, and the actual * string representation of the outcomes can be obtained from the * method getOutcome(int i). */ static double[] eval(int[] context, float[] values, double[] prior, EvalParameters model) { Context[] scontexts = new Context[context.length]; for (int i = 0; i < context.length; i++) { scontexts[i] = model.getParams()[context[i]]; } return GISModel.eval(scontexts, values, prior, model); }
public double[] eval(String[] context, float[] values) { return eval(context,values,new double[evalParams.getNumOutcomes()]); }
protected AbstractModel(Context[] params, String[] predLabels, Map<String, Context> pmap, String[] outcomeNames) { this.pmap = pmap; this.outcomeNames = outcomeNames; this.evalParams = new EvalParameters(params,outcomeNames.length); }
/** * Provides the fundamental data structures which encode the maxent model * information. This method will usually only be needed by * GISModelWriters. The following values are held in the Object array * which is returned by this method: * <ul> * <li>index 0: opennlp.tools.ml.maxent.Context[] containing the model * parameters * <li>index 1: java.util.Map containing the mapping of model predicates * to unique integers * <li>index 2: java.lang.String[] containing the names of the outcomes, * stored in the index of the array which represents their * unique ids in the model. * </ul> * * @return An Object[] with the values as described above. */ public final Object[] getDataStructures() { Object[] data = new Object[3]; data[0] = evalParams.getParams(); data[1] = pmap; data[2] = outcomeNames; return data; }
/** * Use this model to evaluate a context and return an array of the likelihood * of each outcome given that context. * * @param context * The names of the predicates which have been observed at the * present decision point. * @return The normalized probabilities for the outcomes given the context. * The indexes of the double[] are the outcome ids, and the actual * string representation of the outcomes can be obtained from the * method getOutcome(int i). */ public final double[] eval(String[] context) { return (eval(context, new double[evalParams.getNumOutcomes()])); }
EvalParameters evalParams = new EvalParameters(params, numOutcomes);
/** * Provides the fundamental data structures which encode the maxent model * information. This method will usually only be needed by * GISModelWriters. The following values are held in the Object array * which is returned by this method: * <ul> * <li>index 0: opennlp.tools.ml.maxent.Context[] containing the model * parameters * <li>index 1: java.util.Map containing the mapping of model predicates * to unique integers * <li>index 2: java.lang.String[] containing the names of the outcomes, * stored in the index of the array which represents their * unique ids in the model. * </ul> * * @return An Object[] with the values as described above. */ public final Object[] getDataStructures() { Object[] data = new Object[3]; data[0] = evalParams.getParams(); data[1] = pmap; data[2] = outcomeNames; return data; }
public double[] eval(String[] context) { return eval(context, new double[evalParams.getNumOutcomes()]); }