LBJ2.infer
Class Inference

java.lang.Object
  extended by LBJ2.infer.Inference
Direct Known Subclasses:
GLPK, ILPInference

public abstract class Inference
extends java.lang.Object

An object of this class keeps track of all the information necessary to perform inference. Once that inference has been performed, constrained classifiers access the results through this class's interface to determine what their constrained predictions are.


Field Summary
protected  Constraint constraint
          The constraints which must be satisfied by the inference algorithm.
protected  java.lang.Object head
          Objects of this class are differentiated by their "head" objects.
protected  java.util.LinkedHashMap variables
          The values of this map are the variables we perform inference over; they are the actual FirstOrderVariable objects found in this inference's constraints.
 
Constructor Summary
Inference()
          Default constructor.
Inference(java.lang.Object h)
          Initializes the head object.
 
Method Summary
static java.lang.String exampleToString(java.lang.Object example)
          Produces a string representation of an example object.
 java.lang.Object getHead()
          Retrieves the head object.
 java.lang.String[] getHeadFinderTypes()
          Returns the fully qualified names of the types of objects for which head finder methods have been defined.
 java.lang.String getHeadType()
          Returns the fully qualified name of the type of the head object for this inference.
 Normalizer getNormalizer(Learner c)
          Returns the normalization function associated with the given classifier in this inference.
 FirstOrderVariable getVariable(FirstOrderVariable v)
          Retrieves the requested variable, creating it first if it doesn't yet exist.
 PropositionalVariable getVariable(PropositionalVariable v)
          Retrieves the requested variable, creating it first if it doesn't yet exist.
protected abstract  void infer()
          Derived classes implement this method to perform the inference, setting the values of the variables such that they maximize the objective function while satisfying the constraints.
 boolean satisfied()
          Determines if the constraints are satisfied by the current variable assignments.
abstract  java.lang.String valueOf(Learner c, java.lang.Object o)
          Retrieves the value of the specified variable as identified by the classifier and the object that produce that variable.
 void visit(AtLeastQuantifier c)
          Derived classes override this method to do some type of processing on constraints of the parameter's type.
 void visit(AtMostQuantifier c)
          Derived classes override this method to do some type of processing on constraints of the parameter's type.
 void visit(ExistentialQuantifier c)
          Derived classes override this method to do some type of processing on constraints of the parameter's type.
 void visit(FirstOrderConjunction c)
          Derived classes override this method to do some type of processing on constraints of the parameter's type.
 void visit(FirstOrderConstant c)
          Derived classes override this method to do some type of processing on constraints of the parameter's type.
 void visit(FirstOrderDisjunction c)
          Derived classes override this method to do some type of processing on constraints of the parameter's type.
 void visit(FirstOrderDoubleImplication c)
          Derived classes override this method to do some type of processing on constraints of the parameter's type.
 void visit(FirstOrderEqualityTwoValues c)
          Derived classes override this method to do some type of processing on constraints of the parameter's type.
 void visit(FirstOrderEqualityWithValue c)
          Derived classes override this method to do some type of processing on constraints of the parameter's type.
 void visit(FirstOrderEqualityWithVariable c)
          Derived classes override this method to do some type of processing on constraints of the parameter's type.
 void visit(FirstOrderImplication c)
          Derived classes override this method to do some type of processing on constraints of the parameter's type.
 void visit(FirstOrderNegation c)
          Derived classes override this method to do some type of processing on constraints of the parameter's type.
 void visit(PropositionalAtLeast c)
          Derived classes override this method to do some type of processing on constraints of the parameter's type.
 void visit(PropositionalConjunction c)
          Derived classes override this method to do some type of processing on constraints of the parameter's type.
 void visit(PropositionalConstant c)
          Derived classes override this method to do some type of processing on constraints of the parameter's type.
 void visit(PropositionalDisjunction c)
          Derived classes override this method to do some type of processing on constraints of the parameter's type.
 void visit(PropositionalDoubleImplication c)
          Derived classes override this method to do some type of processing on constraints of the parameter's type.
 void visit(PropositionalImplication c)
          Derived classes override this method to do some type of processing on constraints of the parameter's type.
 void visit(PropositionalNegation c)
          Derived classes override this method to do some type of processing on constraints of the parameter's type.
 void visit(PropositionalVariable c)
          Derived classes override this method to do some type of processing on constraints of the parameter's type.
 void visit(QuantifiedConstraintInvocation c)
          Derived classes override this method to do some type of processing on constraints of the parameter's type.
 void visit(UniversalQuantifier c)
          Derived classes override this method to do some type of processing on constraints of the parameter's type.
 void visitAll(Constraint c)
          The default method for visiting a constraint simply visits that constraint's children.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

variables

protected java.util.LinkedHashMap variables
The values of this map are the variables we perform inference over; they are the actual FirstOrderVariable objects found in this inference's constraints. The keys are also objects of type FirstOrderVariable, but they are not necessarily the actual objects found in the constraints. This map is populated by the first evaluation of the constraints.


constraint

protected Constraint constraint
The constraints which must be satisfied by the inference algorithm.


head

protected java.lang.Object head
Objects of this class are differentiated by their "head" objects.

Constructor Detail

Inference

public Inference()
Default constructor.


Inference

public Inference(java.lang.Object h)
Initializes the head object.

Parameters:
h - The head object.
Method Detail

exampleToString

public static java.lang.String exampleToString(java.lang.Object example)
Produces a string representation of an example object. This method is used mainly for debugging messages.

Parameters:
example - The example object, which may be an array.
Returns:
A string representation of example.

getHead

public java.lang.Object getHead()
Retrieves the head object.


infer

protected abstract void infer()
                       throws java.lang.Exception
Derived classes implement this method to perform the inference, setting the values of the variables such that they maximize the objective function while satisfying the constraints. When implementing this method in a derived class Foo, it may be assumed that the constraint member field has already been filled in appropriately, since the LBJ compiler will generate a class extending Foo whose constructor does so.

Throws:
java.lang.Exception

valueOf

public abstract java.lang.String valueOf(Learner c,
                                         java.lang.Object o)
                                  throws java.lang.Exception
Retrieves the value of the specified variable as identified by the classifier and the object that produce that variable.

Parameters:
c - The classifier producing the variable.
o - The object from which the variable is produced.
Returns:
The current value of the requested variable.
Throws:
java.lang.Exception

getNormalizer

public Normalizer getNormalizer(Learner c)
Returns the normalization function associated with the given classifier in this inference. Derived classes that implement an inference algorithm for use in an LBJ source file are required to call this method to normalize the scores produced by classifiers before making use of those scores. By default, this method returns the IdentityNormalizer.

Parameters:
c - The classifier.
Returns:
The normalization function associated with the classifier.

getHeadType

public java.lang.String getHeadType()
Returns the fully qualified name of the type of the head object for this inference. By default, this method returns "java.lang.Object". It should be overridden by derived classes.


getHeadFinderTypes

public java.lang.String[] getHeadFinderTypes()
Returns the fully qualified names of the types of objects for which head finder methods have been defined. This method must be overridden by derived classes, since by default it returns a 0-length array and every Inference is required to have at least one head finder. Inference classes written by the compiler automatically override this method appropriately.


satisfied

public boolean satisfied()
Determines if the constraints are satisfied by the current variable assignments.


getVariable

public PropositionalVariable getVariable(PropositionalVariable v)
Retrieves the requested variable, creating it first if it doesn't yet exist.

Parameters:
v - A variable containing the same classifier, object, and prediction value as the desired variable.
Returns:
The Boolean variable corresponding to the event classifier(object) == prediction.

getVariable

public FirstOrderVariable getVariable(FirstOrderVariable v)
Retrieves the requested variable, creating it first if it doesn't yet exist.

Parameters:
v - A variable containing the same classifier and object as the desired variable.
Returns:
The variable corresponding to the application of the classifier on the object.

visitAll

public void visitAll(Constraint c)
The default method for visiting a constraint simply visits that constraint's children.


visit

public void visit(FirstOrderDoubleImplication c)
Derived classes override this method to do some type of processing on constraints of the parameter's type.

Parameters:
c - The constraint to process.

visit

public void visit(FirstOrderImplication c)
Derived classes override this method to do some type of processing on constraints of the parameter's type.

Parameters:
c - The constraint to process.

visit

public void visit(FirstOrderConjunction c)
Derived classes override this method to do some type of processing on constraints of the parameter's type.

Parameters:
c - The constraint to process.

visit

public void visit(FirstOrderDisjunction c)
Derived classes override this method to do some type of processing on constraints of the parameter's type.

Parameters:
c - The constraint to process.

visit

public void visit(FirstOrderEqualityTwoValues c)
Derived classes override this method to do some type of processing on constraints of the parameter's type.

Parameters:
c - The constraint to process.

visit

public void visit(FirstOrderEqualityWithValue c)
Derived classes override this method to do some type of processing on constraints of the parameter's type.

Parameters:
c - The constraint to process.

visit

public void visit(FirstOrderEqualityWithVariable c)
Derived classes override this method to do some type of processing on constraints of the parameter's type.

Parameters:
c - The constraint to process.

visit

public void visit(FirstOrderNegation c)
Derived classes override this method to do some type of processing on constraints of the parameter's type.

Parameters:
c - The constraint to process.

visit

public void visit(FirstOrderConstant c)
Derived classes override this method to do some type of processing on constraints of the parameter's type.

Parameters:
c - The constraint to process.

visit

public void visit(UniversalQuantifier c)
Derived classes override this method to do some type of processing on constraints of the parameter's type.

Parameters:
c - The constraint to process.

visit

public void visit(ExistentialQuantifier c)
Derived classes override this method to do some type of processing on constraints of the parameter's type.

Parameters:
c - The constraint to process.

visit

public void visit(AtLeastQuantifier c)
Derived classes override this method to do some type of processing on constraints of the parameter's type.

Parameters:
c - The constraint to process.

visit

public void visit(AtMostQuantifier c)
Derived classes override this method to do some type of processing on constraints of the parameter's type.

Parameters:
c - The constraint to process.

visit

public void visit(QuantifiedConstraintInvocation c)
Derived classes override this method to do some type of processing on constraints of the parameter's type.

Parameters:
c - The constraint to process.

visit

public void visit(PropositionalDoubleImplication c)
Derived classes override this method to do some type of processing on constraints of the parameter's type.

Parameters:
c - The constraint to process.

visit

public void visit(PropositionalImplication c)
Derived classes override this method to do some type of processing on constraints of the parameter's type.

Parameters:
c - The constraint to process.

visit

public void visit(PropositionalConjunction c)
Derived classes override this method to do some type of processing on constraints of the parameter's type.

Parameters:
c - The constraint to process.

visit

public void visit(PropositionalDisjunction c)
Derived classes override this method to do some type of processing on constraints of the parameter's type.

Parameters:
c - The constraint to process.

visit

public void visit(PropositionalAtLeast c)
Derived classes override this method to do some type of processing on constraints of the parameter's type.

Parameters:
c - The constraint to process.

visit

public void visit(PropositionalConstant c)
Derived classes override this method to do some type of processing on constraints of the parameter's type.

Parameters:
c - The constraint to process.

visit

public void visit(PropositionalNegation c)
Derived classes override this method to do some type of processing on constraints of the parameter's type.

Parameters:
c - The constraint to process.

visit

public void visit(PropositionalVariable c)
Derived classes override this method to do some type of processing on constraints of the parameter's type.

Parameters:
c - The constraint to process.