<< Click to Display Table of Contents >> Navigation: Using SMILE > Continuous models > Continuous inference |
To run inference in a continuous model, use DSL_network::UpdateBeliefs, the same method that is used in discrete networks.
Inference in continuous networks is based on stochastic sampling when there is no evidence in the network, or when the evidence is specified only for nodes without parents. Otherwise, inference is performed on a temporary discrete network, derived from the original continuous model. The definitions for the temporary discrete nodes are derived from the discretization intervals defined in each continuous node.
Equation nodes have their values represented by DSL_equationEvaluation class derived from DSL_nodeVal. Since the representation of the equation node value uses either stochastic samples or discretized beliefs, the DSL_equationEvaluation defines multiple methods not present in DSL_nodeVal. However, for setting and getting the evidence we can use (overridden) methods SetDefintion and GetDefinition without casting the DSL_nodeVal pointer to DSL_equationEvaluation.
To set evidence in an equation node, use SetEvidence(double) overload. In the snippet below we are assuming that evNodeHandle is the handle of the equation node.
int evNodeHandle = …
DSL_nodeVal *evVal = net.GetNode(evNodeHandle)->Val();
evVal.SetEvidence(1.5); // 1.5 is the evidence value
To retrieve the evidence, use GetEvidence(double &).
Both types of inference algorithms use the lower and upper bounds defined for each equation node. To set the bounds, use DSL_equation::SetBounds method. Stochastic sampling can reject a sample when its value falls outside of the bounds defined for the node. You can control this behavior by DSL_network::EnableRejectOutlierSamples method. By default, outlier rejection is disabled.
Stochastic sampling can be controlled by setting the sample count with DSL_network::SetNumberOfDiscretizationSamples. Large number of samples provides better approximation of the joint probability distribution represented by the set of equations embedded in the continuous network but requires more time to complete. Output samples can be accessed directly with DSL_equationEvaluation::GetSamples. They can be also returned as histogram bins from DSL_equationEvaluation::GetHistogram. Statistics for the collected samples are available from DSL_equationEvaluation::GetStats, or GetMean and GetStdDev. If there were samples out of bounds, DSL_equationEvaluation::HasSamplesOutOfBounds returns true.
When discretization was used to perform inference, samples are not available. SMILE creates a temporary discrete model, where nodes are derived from the original model's equations and discretization intervals. The discretization intervals, just like equation bounds, are stored in equation node definitions (DSL_equation objects).
To set the discretization intervals, use DSL_equation::SetDiscIntervals. The method accepts a vector of intervals as its argument. The vector consists of string/double pairs. The first element of the pair is the interval identifier, which is not used during inference. The second element of the pair is the upper bound of the discretization interval. The lower bound of the interval with index j is defined by upper interval of the interval with index j-1. The lower bound of the first interval is defined by the lower bound defined for the node with a DSL_equation::SetBounds call.
Discretization intervals are used to obtain CPTs for the temporary discrete network. The CPTs are calculated by drawing a number of samples specified at the network level for each CPT column. The number of discretization samples is set to 10,000 by default but can be changed using the DSL_network::SetNumberOfDiscretizationSamples method. The size of the discretized CPT is a product of the number of node intervals and parent node intervals. Note that this may lead to excessive memory use when the node has many parents.
When discretization algorithm is used, the equation node value stores discretized beliefs (not samples). To check which inference algorithm was executed, use DSL_equationEvaluation::IsDiscretized. When IsDiscretized returns true, use DSL_equationEvaluation::GetDiscBeliefs to get access to the discretized beliefs. Note that mean and standard deviation are still available through DSL_equationEvaluation::GetMean and GetStdDev (but not GetSampleStats, because there are no samples).
See the DSL_equationEvaluation reference for more information.