opennlp.maxent
Class GISModel

java.lang.Object
  extended by opennlp.maxent.GISModel
All Implemented Interfaces:
MaxentModel

public final class GISModel
extends java.lang.Object
implements MaxentModel

A maximum entropy model which has been trained using the Generalized Iterative Scaling procedure (implemented in GIS.java).

Version:
$Revision: 1.22 $, $Date: 2007/04/12 17:22:31 $
Author:
Tom Morton and Jason Baldridge

Constructor Summary
GISModel(Context[] params, java.lang.String[] predLabels, java.lang.String[] outcomeNames, int correctionConstant, double correctionParam)
          Creates a new model with the specified parameters, outcome names, and predicate/feature labels.
GISModel(Context[] params, java.lang.String[] predLabels, java.lang.String[] outcomeNames, int correctionConstant, double correctionParam, Prior prior)
          Creates a new model with the specified parameters, outcome names, and predicate/feature labels.
 
Method Summary
static double[] eval(int[] context, double[] prior, EvalParameters model)
          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.
static double[] eval(int[] context, float[] values, double[] prior, EvalParameters model)
          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.
 double[] eval(java.lang.String[] context)
          Use this model to evaluate a context and return an array of the likelihood of each outcome given that context.
 double[] eval(java.lang.String[] context, double[] outsums)
          Evaluates a context.
 double[] eval(java.lang.String[] context, float[] values)
          Evaluates a contexts with the specified context values.
 double[] eval(java.lang.String[] context, float[] values, double[] outsums)
          Use this model to evaluate a context and return an array of the likelihood of each outcome given that context.
 java.lang.String getAllOutcomes(double[] ocs)
          Return a string matching all the outcome names with all the probabilities produced by the eval(String[] context) method.
 java.lang.String getBestOutcome(double[] ocs)
          Return the name of the outcome corresponding to the highest likelihood in the parameter ocs.
 java.lang.Object[] getDataStructures()
          Provides the fundamental data structures which encode the maxent model information.
 int getIndex(java.lang.String outcome)
          Gets the index associated with the String name of the given outcome.
 int getNumOutcomes()
          Returns the number of outcomes for this model.
 java.lang.String getOutcome(int i)
          Return the name of an outcome corresponding to an int id.
static void main(java.lang.String[] args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GISModel

public GISModel(Context[] params,
                java.lang.String[] predLabels,
                java.lang.String[] outcomeNames,
                int correctionConstant,
                double correctionParam)
Creates a new model with the specified parameters, outcome names, and predicate/feature labels.

Parameters:
params - The parameters of the model.
predLabels - The names of the predicates used in this model.
outcomeNames - The names of the outcomes this model predicts.
correctionConstant - The maximum number of active features which occur in an event.
correctionParam - The parameter associated with the correction feature.

GISModel

public GISModel(Context[] params,
                java.lang.String[] predLabels,
                java.lang.String[] outcomeNames,
                int correctionConstant,
                double correctionParam,
                Prior prior)
Creates a new model with the specified parameters, outcome names, and predicate/feature labels.

Parameters:
params - The parameters of the model.
predLabels - The names of the predicates used in this model.
outcomeNames - The names of the outcomes this model predicts.
correctionConstant - The maximum number of active features which occur in an event.
correctionParam - The parameter associated with the correction feature.
prior - The prior to be used with this model.
Method Detail

eval

public final double[] eval(java.lang.String[] context)
Use this model to evaluate a context and return an array of the likelihood of each outcome given that context.

Specified by:
eval in interface MaxentModel
Parameters:
context - The names of the predicates which have been observed at the present decision point.
Returns:
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).

eval

public final double[] eval(java.lang.String[] context,
                           float[] values)
Description copied from interface: MaxentModel
Evaluates a contexts with the specified context values.

Specified by:
eval in interface MaxentModel
Parameters:
context - A list of String names of the contextual predicates which are to be evaluated together.
values - The values associated with each context.
Returns:
an array of the probabilities for each of the different outcomes, all of which sum to 1.

eval

public static double[] eval(int[] context,
                            double[] prior,
                            EvalParameters model)
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.

Parameters:
context - The integer values of the predicates which have been observed at the present decision point.
prior - The prior distribution for the specified context.
model - The set of parametes used in this computation.
Returns:
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).

eval

public static double[] eval(int[] context,
                            float[] values,
                            double[] prior,
                            EvalParameters model)
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.

Parameters:
context - The integer values of the predicates which have been observed at the present decision point.
values - The values for each of the parameters.
prior - The prior distribution for the specified context.
model - The set of parametes used in this computation.
Returns:
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).

eval

public final double[] eval(java.lang.String[] context,
                           double[] outsums)
Description copied from interface: MaxentModel
Evaluates a context.

Specified by:
eval in interface MaxentModel
Parameters:
context - A list of String names of the contextual predicates which are to be evaluated together.
outsums - An array which is populated with the probabilities for each of the different outcomes, all of which sum to 1.
Returns:
an array of the probabilities for each of the different outcomes, all of which sum to 1.

eval

public final double[] eval(java.lang.String[] context,
                           float[] values,
                           double[] outsums)
Use this model to evaluate a context and return an array of the likelihood of each outcome given that context.

Parameters:
context - The names of the predicates which have been observed at the present decision point.
outsums - This is where the distribution is stored.
Returns:
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).

getBestOutcome

public final java.lang.String getBestOutcome(double[] ocs)
Return the name of the outcome corresponding to the highest likelihood in the parameter ocs.

Specified by:
getBestOutcome in interface MaxentModel
Parameters:
ocs - A double[] as returned by the eval(String[] context) method.
Returns:
The name of the most likely outcome.

getAllOutcomes

public final java.lang.String getAllOutcomes(double[] ocs)
Return a string matching all the outcome names with all the probabilities produced by the eval(String[] context) method.

Specified by:
getAllOutcomes in interface MaxentModel
Parameters:
ocs - A double[] as returned by the eval(String[] context) method.
Returns:
String containing outcome names paired with the normalized probability (contained in the double[] ocs) for each one.

getOutcome

public final java.lang.String getOutcome(int i)
Return the name of an outcome corresponding to an int id.

Specified by:
getOutcome in interface MaxentModel
Parameters:
i - An outcome id.
Returns:
The name of the outcome associated with that id.

getIndex

public int getIndex(java.lang.String outcome)
Gets the index associated with the String name of the given outcome.

Specified by:
getIndex in interface MaxentModel
Parameters:
outcome - the String name of the outcome for which the index is desired
Returns:
the index if the given outcome label exists for this model, -1 if it does not.

getNumOutcomes

public int getNumOutcomes()
Description copied from interface: MaxentModel
Returns the number of outcomes for this model.

Specified by:
getNumOutcomes in interface MaxentModel
Returns:
The number of outcomes.

getDataStructures

public final java.lang.Object[] getDataStructures()
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:
  • index 0: opennlp.maxent.Context[] containing the model parameters
  • index 1: java.util.Map containing the mapping of model predicates to unique integers
  • 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.
  • index 3: java.lang.Integer containing the value of the models correction constant
  • index 4: java.lang.Double containing the value of the models correction parameter

    Specified by:
    getDataStructures in interface MaxentModel
    Returns:
    An Object[] with the values as described above.

  • main

    public static void main(java.lang.String[] args)
                     throws java.io.IOException
    Throws:
    java.io.IOException


    Copyright © 2005 Jason Baldridge, Gann Bierner, and Thomas Morton. All Rights Reserved.