Multidimensional arrays

<< Click to Display Table of Contents >>

Navigation:  Using SMILE > Anatomy of a node >

Multidimensional arrays

To represent conditional probability tables (CPTs), SMILE uses DSL_Dmatrix class. CPT describes the interaction between a node and its immediate predecessors. The number of dimensions and the total size of a conditional probability table are determined by the number of parents, the number of states of each of these parents, and the number of states of the child node. Essentially, there is a probability for every state of the child node for every combination of the states of the parents. Nodes that have no predecessors are specified by a prior probability distribution table, which is a vector specifying the prior probability of every state of the node.

Conditional probability tables are stored as vectors of doubles that are a flattened versions of multidimensional tables with as many dimensions as there are parents plus one for the node itself. The order of the coordinates reflects the order in which the arcs to the node were created. The most significant (leftmost) coordinate will represent the state of the first parent. The state of the node itself corresponds to the least significant (rightmost) coordinate.

The image below is an annotated screenshot of GeNIe’s node properties window open for the Forecast node in the model created in Tutorial 1. Forecast has three outcomes and two parents: Success of the venture and State of the economy, with two and three outcomes, respectively. Therefore, the total size of the CPT is 2 x 3 x 3 = 18. The arrows in the image (not part of the actual GeNIe window) show the ordering of the entries in the linear buffer that DSL_Dmatrix uses internally. The first (or rather, the zero-th, because all indices in SMILE are zero-based) element, the one with the value of 0.7 and yellow background, represents P(Forecast=Good | Success of the venture=Success & State of the economy=Up). It is followed by the probabilties for Moderate and Poor outcomes given the same parent configuration. The next parent configuration is Success of the venture=Success & State of the economy=Flat, etc.

multidimensional_array

In addition to linear indexing, DSL_Dmatrix allows access to its elements through coordinate system by overloading operator[] and Subscript methods. The coordinates are specified by DSL_intArray object containing values for each parent and node for which CPT is defined. For example, the element for

Success of the venture=Failure

State of the economy=Up

Forecast=Poor

would have the coordinates [1, 0, 2]. It’s linear index is 11. DSL_Dmatrix provides CoordinatesToIndex and IndexToCoordinates methods for conversion between coordinates and linear indices and vice versa. The NextCoordinates and PrevCoordinates methods can be used to shift the coordinates forward or backward in odometer-like fashion (with the rightmost/least significant entry representing node for which the CPT is defined changing every time).

Note that DSL_Dmatrix is not used exclusively for CPTs. Other uses of this class in SMILE include (but are not limited to) expected utility tables and marginal probability distributions, both of which can be indexed.