Class MlBayesIm

java.lang.Object
edu.cmu.tetrad.bayes.MlBayesIm
All Implemented Interfaces:
BayesIm, Simulator, VariableSource, Im, TetradSerializable, Serializable

public final class MlBayesIm extends Object implements BayesIm
Stores a table of probabilities for a Bayes net and, together with BayesPm and Dag, provides methods to manipulate this table. The division of labor is as follows. The Dag is responsible for manipulating the basic graphical structure of the Bayes net. Dag also stores and manipulates the names of the nodes in the graph; there is no method in either BayesPm or BayesIm to do this. BayesPm stores and manipulates the *categories* of each node in a DAG, considered as a variable in a Bayes net. The number of categories for a variable can be changed there as well as the names for those categories. This class, BayesIm, stores the actual probability tables which are implied by the structures in the other two classes. The implied parameters take the form of conditional probabilities--e.g., P(N=v0|P1=v1, P2=v2, ...), for all nodes and all combinations of their parent categories. The set of all such probabilities is organized in this class as a three-dimensional table of double values. The first dimension corresponds to the nodes in the Bayes net. For each such node, the second dimension corresponds to a flat list of combinations of parent categories for that node. The third dimension corresponds to the list of categories for that node itself. Two methods allow these values to be set and retrieved: getWordRatio(int nodeIndex, int rowIndex, int colIndex); and setProbability(int nodeIndex, int rowIndex, int colIndex, int probability). To determine the index of the node in question, use the method getNodeIndex(Node node). To determine the index of the row in question, use the method getRowIndex(int[] parentVals). To determine the order of the parent values for a given node so that you can build the parentVals[] array, use the method getParents(int nodeIndex). To determine the index of a category, use the method getCategoryIndex(Node node) in BayesPm. The rest of the methods in this class are easily understood as variants of the methods above.

This version uses a sparse method for storing the probabilities, where NaNs are not stored. This allows BayesPms with many categories per variable to be estimated from small samples without overflowing memory. The old method of storing probabilities is kept here for backward compatibility, with an internal code flag to indicate which should be used.

Thanks to Pucktada Treeratpituk, Frank Wimberly, and Willie Wheeler for advice and earlier versions.

Version:
$Id: $Id
Author:
josephramsey
See Also: