Continuous inference

<< Click to Display Table of Contents >>

Navigation:  Using SMILE Wrappers > Continuous models >

Continuous inference

To run inference in a continuous (equation-based) model, use Network.update_beliefs, the same method employed for discrete networks.

Inference in continuous networks is performed using stochastic sampling when there is no evidence in the network, or when evidence is present only in nodes without parents, or when evidence is provided in nodes with parents but all parents also have evidence. In all other cases, inference is performed on a temporary discrete network derived from the original continuous model. The definitions of the temporary discrete nodes are obtained from the discretization intervals specified for each continuous node.

Both types of inference algorithms use the lower and upper bounds defined for each equation node. To specify these bounds, use the Network.set_node_equation_bounds method. During stochastic sampling, a sample may be rejected if its value falls outside the defined bounds. This behavior can be controlled with Network.set_outlier_rejection_enabled; by default, outlier rejection is disabled.

Stochastic inference in continuous networks is controlled using the same mechanisms as in discrete networks. Specifically, the number of samples generated by the stochastic algorithm can be adjusted with Network.set_sample_count, and repeatable results can be obtained by setting the pseudorandom generator seed with Network.set_rand_seed. These methods allow consistent control over the quality and reproducibility of the sampling-based approximation of the continuous model.

The discretization algorithm is controlled by Network.set_discretization_sample_count. Using a larger number of samples generally improves the approximation of the solution to the system of equations represented by the continuous network, but requires more computation time. Additionally, the Network.set_zero_avoidance_enabled method can be used to enable zero avoidance. When zero avoidance is enabled, the algorithm avoids placing zeros in the CPTs, even if no samples are generated for a given parameter. Zeros in probability distributions can cause theoretical issues and should be used with caution—only when it is certain that the probability should be zero. Once a zero is set, that probability cannot be changed, regardless of the strength of the evidence against it.

To define a node’s discretization intervals, use Network.set_node_equation_discretization. This method accepts an array of DiscretizationInterval objects as its argument. Each interval is defined by an optional identifier (not used for inference) and an upper bound. The lower bound of an interval with index j is taken from the upper bound of the preceding interval (index j-1). The lower bound of the first interval is defined by the node’s lower bound, which is set with Network.set_node_equation_bounds.

Discretization intervals are used to generate CPTs for the temporary discrete network. Each CPT column is calculated by drawing a number of samples specified at the network level. The size of the resulting discretized CPT is the product of the number of intervals of the node and the number of intervals of its parent nodes. These CPTs are used internally during inference to approximate the continuous model. For performance reasons, the discretized CPTs are cached and reused in subsequent inference calls, as long as there are no relevant changes in the network (such as modifications to node equations or discretization intervals). Note that these cached CPTs are not stored in the XDSL file. Be aware that high memory usage may occur when a discretized equation node has many parents.

The results of inference in a continuous model can be either samples or discretized beliefs, depending on the inference algorithm used:

Sampling algorithm – Produces a set of samples for each node. Network.get_node_value returns an array of these samples, and Network.get_node_sample_stats provides simple statistics for the sample set (mean, standard deviation, minimum, and maximum). You can also retrieve the mean and standard deviation directly with Network.get_node_mean and Network.get_node_std_dev. Network.is_value_discretized returns false.

Discretizing algorithm – Produces a probability distribution over the discretization intervals. Network.get_node_value returns this distribution, and Network.is_value_discretized returns true.

The following methods provide access to inference results, evidence, and discretization settings for continuous (equation-based) nodes in SMILE.

Python

is_outlier_rejection_enabled() -> bool

set_outlier_rejection_enabled(enabled: bool) -> None

get_discretization_sample_count() -> int

set_discretization_sample_count(discretization_sample_count: int) -> None

is_zero_avoidance_enabled() -> bool

set_zero_avoidance_enabled(enabled: bool) -> None

set_node_equation_bounds(node: int | str, lo: float, hi: float) -> None

get_node_equation_bounds(node: int | str) -> List[float]

set_node_equation_discretization(node: int | str, intervals: List[DiscretizationInterval]) -> None

set_node_equation_uniform_discretization(node: int | str, interval_count: int) -> None

get_node_equation_discretization(node: int | str) -> List[DiscretizationInterval]

is_value_discretized(node: int | str) -> bool

get_node_sample_stats(node: int | str) -> List[float]

get_node_mean(node: int | str) -> float

get_node_stddev(node: int | str) -> float

Java

boolean isOutlierRejectionEnabled();

void setOutlierRejectionEnabled(boolean enabled);

int getDiscretizationSampleCount();

void setDiscretizationSampleCount(int discretizationSampleCount);

boolean isZeroAvoidanceEnabled();

void setZeroAvoidanceEnabled(boolean enable);

void setNodeEquationBounds(int nodeHandle, double lo, double hi);

void setNodeEquationBounds(String nodeId, double lo, double hi);

double[] getNodeEquationBounds(int nodeHandle);

double[] getNodeEquationBounds(String nodeId);

void setNodeEquationDiscretization(int nodeHandle, DiscretizationInterval[] intervals);

void setNodeEquationDiscretization(String nodeId, DiscretizationInterval[] intervals);

void setNodeEquationUniformDiscretization(int nodeHandle, int intervalCount);

void setNodeEquationUniformDiscretization(String nodeId, int intervalCount);

DiscretizationInterval[] getNodeEquationDiscretization(int nodeHandle);

DiscretizationInterval[] getNodeEquationDiscretization(String nodeId);

boolean isValueDiscretized(int nodeHandle);

boolean isValueDiscretized(String nodeId);

double[] getNodeSampleStats(int nodeHandle);

double[] getNodeSampleStats(String nodeId);

double getNodeMean(int nodeHandle);

double getNodeMean(String nodeId);

double getNodeStdDev(int nodeHandle);

double getNodeStdDev(String nodeId);

C#

bool OutlierRejectionEnabled { get; set; }

int DiscretizationSampleCount { get; set; }

bool ZeroAvoidanceEnabled { get; set; }

void SetNodeEquationBounds(int nodeHandle, double lo, double hi);

void SetNodeEquationBounds(string nodeId, double lo, double hi);

double[] GetNodeEquationBounds(int nodeHandle);

double[] GetNodeEquationBounds(string nodeId);

void SetNodeEquationDiscretization(int nodeHandle, DiscretizationInterval[] intervals);

void SetNodeEquationDiscretization(string nodeId, DiscretizationInterval[] intervals);

void SetNodeEquationUniformDiscretization(int nodeHandle, int intervalCount);

void SetNodeEquationUniformDiscretization(string nodeId, int intervalCount);

DiscretizationInterval[] GetNodeEquationDiscretization(int nodeHandle);

DiscretizationInterval[] GetNodeEquationDiscretization(string nodeId);

bool IsValueDiscretized(int nodeHandle);

bool IsValueDiscretized(string nodeId);

double[] GetNodeSampleStats(int nodeHandle);

double[] GetNodeSampleStats(string nodeId);

double GetNodeMean(int nodeHandle);

double GetNodeMean(string nodeId);

double GetNodeStdDev(int nodeHandle);

double GetNodeStdDev(string nodeId);

R

outlierEnabled <- isOutlierRejectionEnabled()

setOutlierRejectionEnabled(enabled)

discSampleCount <- getDiscretizationSampleCount()

setDiscretizationSampleCount(discSampleCount)

zeroAvoidanceEnabled <- isZeroAvoidanceEnabled()

setZeroAvoidanceEnabled(enabled)

setNodeEquationBounds(nodeIdOrHandle, lo, hi)

bounds <- getNodeEquationBounds(nodeIdOrHandle)

setNodeEquationDiscretization(nodeIdOrHandle, intervals)

setNodeEquationUniformDiscretization(nodeIdOrHandle, intervalCount)

intervals <- getNodeEquationDiscretization(nodeIdOrHandle)

valueDiscretized <- isValueDiscretized(nodeIdOrHandle)

sampleStats <- getNodeSampleStats(nodeIdOrHandle)

meanValue <- getNodeMean(nodeIdOrHandle)

stdDev <- getNodeStdDev(nodeIdOrHandle)