blog
Class Clause

java.lang.Object
  extended by blog.Clause

public class Clause
extends java.lang.Object

Represents a clause in dependency statements and number statements. Each clause has a predicate, a conditional probability distribution (CPD), and a list of arguments to this conditional probability distribution. Each argument is assumed to be of class ArgSpec. If the condition is checked and turns out to be true, then the arguments are evaluated and the CPD is used to sample a value for these arguments.


Constructor Summary
Clause(Formula cond, java.lang.Class cpdClass, java.util.List cpdParams, java.util.List cpdArgs)
          Creates a new clause.
Clause(Formula cond, CondProbDistrib cpd, java.util.List cpdArgs)
          Creates a new clause using the given CondProbDistrib object.
 
Method Summary
 boolean checkTypesAndScope(Model model, java.util.Map scope, Type childType)
           
 int compile(java.util.LinkedHashSet callStack)
          Creates the CPD object for this clause (if it doesn't already exist), and does any necessary compilation on the condition and CPD arguments.
 java.util.List getArgs()
           
 Formula getCond()
           
 CondProbDistrib getCPD()
           
 java.lang.Class getCPDClass()
           
 DependencyModel.Distrib getDistrib(EvalContext context)
          Returns this clause's CPD, and the values of this clause's arguments evaluated in the given context.
 BasicVar getEqualParent(EvalContext context)
          If, in the given context, this clause specifies that the child is equal to one of its parents, then this method returns that "equal parent".
 java.lang.Object getLocation()
          Returns the object specified by the last call to setLocation.
 void setLocation(java.lang.Object loc)
          Sets the location of this clause, for instance, the file name and line number where it appears.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Clause

public Clause(Formula cond,
              java.lang.Class cpdClass,
              java.util.List cpdParams,
              java.util.List cpdArgs)
Creates a new clause.

Parameters:
cond - the condition under which this clause applies
cpdClass - the class of the conditional probability distribution used in this clause
cpdParams - List of ArgSpec objects representing CPD parameters. These must be non-random and must contain no free variables.
cpdArgs - List of ArgSpec objects whose denotations will be passed to the CPD each time it is invoked

Clause

public Clause(Formula cond,
              CondProbDistrib cpd,
              java.util.List cpdArgs)
Creates a new clause using the given CondProbDistrib object.

Parameters:
cond - the condition under which this clause applies
cpd - conditional probability distribution for this clause
cpdArgs - List of ArgSpec objects whose denotations will be passed to the CPD each time it is invoked
Method Detail

getCond

public Formula getCond()

getCPDClass

public java.lang.Class getCPDClass()

getCPD

public CondProbDistrib getCPD()

getArgs

public java.util.List getArgs()
Returns:
List of ArgSpec objects

getDistrib

public DependencyModel.Distrib getDistrib(EvalContext context)
Returns this clause's CPD, and the values of this clause's arguments evaluated in the given context. Returns null if the partial world in the given context is not complete enough to evaluate the arguments.


getEqualParent

public BasicVar getEqualParent(EvalContext context)
If, in the given context, this clause specifies that the child is equal to one of its parents, then this method returns that "equal parent". Otherwise it returns null. This method also returns null if the given context is not complete enough to determine the equal parent.


checkTypesAndScope

public boolean checkTypesAndScope(Model model,
                                  java.util.Map scope,
                                  Type childType)

compile

public int compile(java.util.LinkedHashSet callStack)
Creates the CPD object for this clause (if it doesn't already exist), and does any necessary compilation on the condition and CPD arguments. Prints messages to standard error if any errors occur. Returns the number of errors encountered.

Parameters:
callStack - Set of objects whose compile methods are parents of this method invocation. Ordered by invocation order. Used to detect cycles.

setLocation

public void setLocation(java.lang.Object loc)
Sets the location of this clause, for instance, the file name and line number where it appears. The location can be any object whose toString method returns an identifying string that can be used in error messages.


getLocation

public java.lang.Object getLocation()
Returns the object specified by the last call to setLocation. If setLocation has not been called, returns the string "(no location)".


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object