blog
Class InstantiatingEvalContext

java.lang.Object
  extended by blog.DefaultEvalContext
      extended by blog.ParentRecEvalContext
          extended by blog.InstantiatingEvalContext
All Implemented Interfaces:
EvalContext

public class InstantiatingEvalContext
extends ParentRecEvalContext

Implementation of the EvalContext interface that instantiates new basic random variables as necessary in response to method calls. To instantiate a variable, it first instantiates all that variable's active parents, then samples a value for the variable using its CPD given those parent values.

When it becomes necessary to instantiate a random variable, a new InstantiatingEvalContext is created to evaluate its dependency model and determine its CPD. We say that the random variable to be instantiated is responsible for the creation of this new InstantiatingEvalContext. For any given InstantiatingEvalContext, there is a sequence of responsible variables that led to its creation. This sequence is passed into the InstantiatingEvalContext constructor (except in the default case where the sequence is empty), in the form of an ordered map from responsible variables to the evaluation contexts that led to those variables.

Storing this sequence of responsible variables is useful for debugging, but it also allows us to detect cyclic dependencies. If an InstantiatingEvalContext is about to try determining the CPD for a random variable that's already among its responsible variables, then it raises a fatal error rather than entering an infinite loop.


Field Summary
 
Fields inherited from class blog.ParentRecEvalContext
latestUninstParent, parents
 
Fields inherited from class blog.DefaultEvalContext
errorIfUndet, world
 
Constructor Summary
InstantiatingEvalContext(PartialWorld world)
          Creates a new InstantiatingEvalContext using the given world.
 
Method Summary
 double getLogProbability()
          Returns the log of the probability of this InstantiatingEvalContext assigning the values it has assigned to the variables it has instantiated.
 java.lang.Object getValue(BasicVar var)
          Returns the value of the given basic random variable in this partial world, or null if the given variable is not instantiated.
 boolean isInstantiated(BasicVar var)
           
 
Methods inherited from class blog.ParentRecEvalContext
getLatestUninstParent, getParents, getPOPAppSatisfied
 
Methods inherited from class blog.DefaultEvalContext
assign, assignTuple, getAssignmentStr, getLogicalVarValue, getLogicalVarValues, getSatisfiers, handleMissingVar, objectExists, popEvaluee, printEvalTrace, pushEvaluee, unassign, unassignTuple, usesIdentifiers
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InstantiatingEvalContext

public InstantiatingEvalContext(PartialWorld world)
Creates a new InstantiatingEvalContext using the given world. Its sequence of responsible variables is empty.

Method Detail

isInstantiated

public boolean isInstantiated(BasicVar var)

getValue

public java.lang.Object getValue(BasicVar var)
Description copied from interface: EvalContext
Returns the value of the given basic random variable in this partial world, or null if the given variable is not instantiated.

Specified by:
getValue in interface EvalContext
Overrides:
getValue in class ParentRecEvalContext

getLogProbability

public double getLogProbability()
Returns the log of the probability of this InstantiatingEvalContext assigning the values it has assigned to the variables it has instantiated.