<< Click to Display Table of Contents >> Navigation: Using SMILE Wrappers > Hybrid models |
Hybrid models are Bayesian networks that contain both discrete and continuous nodes. Arcs in such networks can connect any combination of node types, meaning that both discrete-to-continuous and continuous-to-discrete relationships are supported. Inference in hybrid models follows the same principles as in continuous networks: stochastic sampling is used when there is no evidence in nodes that have unobserved parents, while discretization is applied otherwise. Conceptually, hybrid models can be viewed as continuous models in which discrete nodes serve as specialized functions—namely, conditional probability tables (CPTs) defined by arrays of numeric values.
Arcs from discrete to continuous nodes are created by referencing the discrete node’s identifier in the equation of the continuous node, just as with arcs between continuous nodes. The following discussion assumes familiarity with the functions used to build node equations, which are described in detail in the Equations reference section of this manual.
For example, suppose node c is continuous and node d is discrete. The equation for c might be written as: c=Normal(If(d=1, 1, -1), 5). When evaluating a sample for c, one of its inputs will be the value of its parent node d. Discrete node values are integers from 0 to N−1, where N is the number of outcomes of the discrete node. In this example, the equation specifies that c should be drawn from a normal distribution with a standard deviation of 5, while the mean depends on the state of d: if d is in its state with zero-based index 1, the mean will be 1; otherwise, the mean will be −1.
To improve readability, parent discrete node outcomes can be represented as text literals. For example, if d has outcomes High, Medium, and Low, the previous equation can be written as c=Normal(If(d="Medium", 1, -1), 5).
Common functions for discrete parents include Switch and Choose. For instance, c=Normal(Switch(d, "High", 3.2, "Medium", 2.5, "Low", 1.4), 5) or equivalently c=Normal(Choose(d, 3.2, 2.5, 1.4), 5). These expressions let the mean of c’s normal distribution depend on the state of d.
Alternatively, the ternary operator ?: can be used to represent conditional expressions. For example, c=Normal(d="Medium" ? 1 : -1, 5) has the same effect as the If function, producing a mean of 1 when d is Medium, and -1 otherwise.
Important: SMILE does not modify text literals representing the outcomes of discrete parent nodes if the outcome identifiers are changed. If a text literal in an equation cannot be associated with any outcome of the parent node, its value is evaluated as -1.
In general, discrete nodes can appear anywhere in an equation where numerical values are allowed. For example, c=log(1+d) or c=2^d are valid expressions. These equations do not rely on text literals for discrete outcomes, as no comparison to specific outcomes is performed during evaluation.
To add an arc from a continuous node to a discrete node, use Network.add_arc, the same method used in purely discrete networks. In this case, the discretization intervals of the continuous parent node are treated as the equivalent of discrete outcomes, allowing the continuous value to influence the discrete child node appropriately.
Tutorial 8 contains a complete program demonstrating the use of hybrid models.