blog
Class DependencyModel

java.lang.Object
  extended by blog.DependencyModel

public class DependencyModel
extends java.lang.Object

Represents dependency statements for functions and number statements for potential object patterns. It consists of a list of clauses the dependency/number statement consists of. Each DependencyModel also has a default value: if none of the clauses are satisfied, then the child variable has the default value with probability 1. The default value is Boolean.FALSE for Boolean functions, null for all other functions, and Integer(0) for POPs.

See Also:
Function, POP

Nested Class Summary
static class DependencyModel.Distrib
          Nested class representing a distribution over child values, in the form of a CPD and a list of values for the CPD's arguments.
 
Constructor Summary
DependencyModel(java.util.List cl, Type childType, java.lang.Object defaultVal)
           
 
Method Summary
 boolean checkTypesAndScope(Model model, java.util.Map scope)
           
 int compile(java.util.LinkedHashSet callStack)
          Creates CPD objects for this dependency model, and does any necessary compilation on the conditions and CPD arguments.
 Clause getActiveClause(EvalContext context)
          Returns the first clause in this dependency model whose condition is satisfied in the given context.
 java.util.List getClauseList()
           
 int getCreationIndex()
          Returns an index indicating when this dependency model was defined.
 java.lang.Object getDefaultValue()
           
 DependencyModel.Distrib getDistrib(EvalContext context)
          Returns the CPD and argument values for the first satisfied clause in the given context.
 DependencyModel.Distrib getDistribWithBinding(EvalContext context, LogicalVar[] vars, java.lang.Object[] objs, java.lang.Object valueWhenArgsDontExist)
          Returns the CPD and argument values for the first satisfied clause in the context obtained by binding the given variables to the given objects.
 BasicVar getEqualParent(EvalContext context)
          If, in the given context, this dependency model specifies that the child is equal to one of its parents, then this method returns that "equal parent".
 void print(java.io.PrintStream s)
          Prints this dependency model to the given stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DependencyModel

public DependencyModel(java.util.List cl,
                       Type childType,
                       java.lang.Object defaultVal)
Method Detail

getClauseList

public java.util.List getClauseList()

getDefaultValue

public java.lang.Object getDefaultValue()

getDistribWithBinding

public DependencyModel.Distrib getDistribWithBinding(EvalContext context,
                                                     LogicalVar[] vars,
                                                     java.lang.Object[] objs,
                                                     java.lang.Object valueWhenArgsDontExist)
Returns the CPD and argument values for the first satisfied clause in the context obtained by binding the given variables to the given objects. If any of the given objects does not exist, returns a distribution that is deterministically equal to the given valueWhenArgsDontExist. If the context is not complete enough to determine the first satisfied clause and its argument values, this method returns null.


getDistrib

public DependencyModel.Distrib getDistrib(EvalContext context)
Returns the CPD and argument values for the first satisfied clause in the given context. If the context is not complete enough to determine the first satisfied clause and its argument values, then this method returns null.


getActiveClause

public Clause getActiveClause(EvalContext context)
Returns the first clause in this dependency model whose condition is satisfied in the given context. If no clause's condition is satisfied, this method returns an automatically-constructed default clause whose condition is "true" and whose CPD is an EqualsCPD with an argument denoting this dependency model's default value. If the given context is not complete enough to determine the first satisfied clause, this method returns null.


getEqualParent

public BasicVar getEqualParent(EvalContext context)
If, in the given context, this dependency model 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.


print

public void print(java.io.PrintStream s)
Prints this dependency model to the given stream. Each clause is printed on a separate line, and each line is indented 1 tab. The first clause begins with "if"; all subsequent clauses begin with "elseif".


checkTypesAndScope

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

compile

public int compile(java.util.LinkedHashSet callStack)
Creates CPD objects for this dependency model, and does any necessary compilation on the conditions 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.

getCreationIndex

public int getCreationIndex()
Returns an index indicating when this dependency model was defined.