Class MlBayesImObs
- All Implemented Interfaces:
- BayesIm,- Simulator,- VariableSource,- Im,- TetradSerializable,- Serializable
- getWordRatio(int nodeIndex, int rowIndex, int colIndex); and,
- setProbability(int nodeIndex, int rowIndex, int colIndex, int probability).
- getNodeIndex(Node node).
- getRowIndex(int[] parentVals).
- getParents(int nodeIndex)
- getCategoryIndex(Node node)
Thanks to Pucktada Treeratpituk, Frank Wimberly, and Willie Wheeler for advise and earlier versions.> 0
- Version:
- $Id: $Id
- Author:
- josephramsey
- See Also:
- 
Constructor SummaryConstructorsConstructorDescriptionMlBayesImObs(BayesIm bayesIm) Constructor for MlBayesImObs.MlBayesImObs(BayesPm bayesPm) Constructs a new BayesIm from the given BayesPm, initializing all values as Double.NaN ("?").MlBayesImObs(BayesPm bayesPm, int initializationMethod) Constructs a new BayesIm from the given BayesPm, initializing values either as MANUAL or RANDOM.MlBayesImObs(BayesPm bayesPm, BayesIm oldBayesIm, int initializationMethod) Constructs a new BayesIm from the given BayesPm, initializing values either as MANUAL or RANDOM, but using values from the old BayesIm provided where posssible.
- 
Method SummaryModifier and TypeMethodDescriptionvoidclearRow(int nodeIndex, int rowIndex) Assigns random probability values to the child values of this row that add to 1.voidclearTable(int nodeIndex) Randomizes every row in the table for the given node index.voidcreateRandomCellTable.booleanReturns true iff this Bayes net is equal to the given Bayes net.Getter for the fieldbayesImObs.Getter for the fieldbayesPm.intgetCorrespondingNodeIndex(int nodeIndex, BayesIm otherBayesIm) Returns the index of the given node in the given BayesIm.getDag()getDag.getJPD()getJPD.getMeasuredNodes.getNode(int nodeIndex) Returns the name of the given node.getNode.intgetNodeIndex(Node node) Returns the index of the given node.intgetNumColumns(int nodeIndex) Returns the number of columns.intgetNumNodes.intgetNumParents(int nodeIndex) Returns the number of parents for the given node.intgetNumRows.intgetNumRows(int nodeIndex) Returns the number of rows.intgetParent(int nodeIndex, int parentIndex) Returns the ith parent of the givne node.intgetParentDim(int nodeIndex, int parentIndex) Returns the dimension of the given parent for the given node.int[]getParentDims(int nodeIndex) Returns the dimensions of the pararents of the given node.int[]getParents(int nodeIndex) Returns the parents of the given node.intgetParentValue(int nodeIndex, int rowIndex, int colIndex) Returns the given parent value.int[]getParentValues(int nodeIndex, int rowIndex) Returns the parents values of the given node.doublegetProbability(int rowIndex) getProbability.doublegetProbability(int nodeIndex, int rowIndex, int colIndex) Returns the probability for the given cell in the given CPT.intgetRowIndex(int nodeIndex, int[] values) getRowIndex.int[]getRowValues(int rowIndex) getRowValues.getVariableNames.getVariables.booleanisIncomplete(int nodeIndex) Returns true iff the given node has a Double.NaN value in it.booleanisIncomplete(int nodeIndex, int rowIndex) Returns true iff the given row in the given node has a Double.NaN value in it.voidNormalizes all rows in the tables associated with each of node in turn.voidnormalizeNode(int nodeIndex) Normalizes all rows in the table associated with a given node.voidnormalizeRow(int nodeIndex, int rowIndex) Normalizes the given row.voidrandomizeIncompleteRows(int nodeIndex) Randomizes any row in the table for the given node index that has a Double.NaN value in it.voidrandomizeRow(int nodeIndex, int rowIndex) Assigns random probability values to the child values of this row that add to 1.voidrandomizeTable(int nodeIndex) Randomizes every row in the table for the given node index.static MlBayesImObsGenerates a simple exemplar of this class to test serialization.voidsetProbability(int rowIndex, double value) setProbability.voidsetProbability(int nodeIndex, double[][] probMatrix) Sets the probability for the given node.voidsetProbability(int nodeIndex, int rowIndex, int colIndex, double value) Sets the probability for the given node at a given row and column in the table for that node.simulateData(int sampleSize, boolean latentDataSaved) Simulates a data set with the specified number of rows.simulateData(DataSet dataSet, boolean latentDataSaved) Simulates data based on the provided data set and saves the latent data if specified.toString()Prints out the probability table for each variable.Methods inherited from class java.lang.ObjectgetClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface edu.cmu.tetrad.bayes.BayesImgetCptMapType
- 
Constructor Details- 
MlBayesImObsConstructs a new BayesIm from the given BayesPm, initializing all values as Double.NaN ("?").- Parameters:
- bayesPm- the given Bayes PM. Carries with it the underlying graph model.
- Throws:
- IllegalArgumentException- if the array of nodes provided is not a permutation of the nodes contained in the bayes parametric model provided.
 
- 
MlBayesImObsConstructs a new BayesIm from the given BayesPm, initializing values either as MANUAL or RANDOM. If initialized manually, all values will be set to Double.NaN ("?") in each row; if initialized randomly, all values will distributed randomly in each row.- Parameters:
- bayesPm- the given Bayes PM. Carries with it the underlying graph model.
- initializationMethod- either MANUAL or RANDOM.
- Throws:
- IllegalArgumentException- if the array of nodes provided is not a permutation of the nodes contained in the bayes parametric model provided.
 
- 
MlBayesImObspublic MlBayesImObs(BayesPm bayesPm, BayesIm oldBayesIm, int initializationMethod) throws IllegalArgumentException Constructs a new BayesIm from the given BayesPm, initializing values either as MANUAL or RANDOM, but using values from the old BayesIm provided where posssible. If initialized manually, all values that cannot be retrieved from oldBayesIm will be set to Double.NaN ("?") in each such row; if initialized randomly, all values that cannot be retrieved from oldBayesIm will distributed randomly in each such row.- Parameters:
- bayesPm- the given Bayes PM. Carries with it the underlying graph model.
- oldBayesIm- an already-constructed BayesIm whose values may be used where possible to initialize this BayesIm. May be null.
- initializationMethod- either MANUAL or RANDOM.
- Throws:
- IllegalArgumentException- if the array of nodes provided is not a permutation of the nodes contained in the bayes parametric model provided.
 
- 
MlBayesImObsConstructor for MlBayesImObs. - Parameters:
- bayesIm- a- BayesImobject
- Throws:
- IllegalArgumentException- if any.
 
 
- 
- 
Method Details- 
serializableInstanceGenerates a simple exemplar of this class to test serialization.- Returns:
- a MlBayesImObsobject
 
- 
getBayesPmGetter for the field bayesPm.- Specified by:
- getBayesPmin interface- BayesIm
- Returns:
- this PM.
 
- 
getDaggetDag. 
- 
getNumNodespublic int getNumNodes()getNumNodes. - Specified by:
- getNumNodesin interface- BayesIm
- Returns:
- the number of nodes in the model.
 
- 
getNodeReturns the name of the given node.
- 
getNodegetNode. 
- 
getNodeIndexReturns the index of the given node.- Specified by:
- getNodeIndexin interface- BayesIm
- Parameters:
- node- the given node.
- Returns:
- the index for that node, or -1 if the node is not in the BayesIm.
 
- 
getVariablesgetVariables. - Specified by:
- getVariablesin interface- BayesIm
- Specified by:
- getVariablesin interface- VariableSource
- Returns:
- a Listobject
 
- 
getMeasuredNodesgetMeasuredNodes. - Specified by:
- getMeasuredNodesin interface- BayesIm
- Returns:
- the list of measured variableNodes.
 
- 
getVariableNamesgetVariableNames. - Specified by:
- getVariableNamesin interface- BayesIm
- Specified by:
- getVariableNamesin interface- VariableSource
- Returns:
- a Listobject
 
- 
getNumColumnspublic int getNumColumns(int nodeIndex) Returns the number of columns.- Specified by:
- getNumColumnsin interface- BayesIm
- Parameters:
- nodeIndex- the index of the node.
- Returns:
- the number of columns in the table of the given node N with index 'nodeIndex'--that is, the number of possible values that N can take on. That is, if P(N=v0 | P1=v1, P2=v2, ... Pn=vn) is a conditional probability stored in 'probs', then the maximum number of rows in the table for N is #vals(N).
- See Also:
 
- 
getNumRowspublic int getNumRows(int nodeIndex) Returns the number of rows.- Specified by:
- getNumRowsin interface- BayesIm
- Parameters:
- nodeIndex- the index of the node.
- Returns:
- the number of rows in the table of the given node, which would be the total number of possible combinations of parent values for a given node. That is, if P(N=v0 | P1=v1, P2=v2, ... Pn=vn) is a conditional probability stored in 'probs', then the maximum number of rows in the table for N is #vals(P1) x #vals(P2) x ... x #vals(Pn).
- See Also:
 
- 
getNumParentspublic int getNumParents(int nodeIndex) Returns the number of parents for the given node.- Specified by:
- getNumParentsin interface- BayesIm
- Parameters:
- nodeIndex- the given node.
- Returns:
- the number of parents of the given node.
 
- 
getParentpublic int getParent(int nodeIndex, int parentIndex) Returns the ith parent of the givne node.
- 
getParentDimpublic int getParentDim(int nodeIndex, int parentIndex) Returns the dimension of the given parent for the given node.- Specified by:
- getParentDimin interface- BayesIm
- Parameters:
- nodeIndex- the index of the node.
- parentIndex- the index of the parent.
- Returns:
- the dimension of the given parent for the given node.
 
- 
getParentDimspublic int[] getParentDims(int nodeIndex) Returns the dimensions of the pararents of the given node.- Specified by:
- getParentDimsin interface- BayesIm
- Parameters:
- nodeIndex- the index of the node.
- Returns:
- (a defensive copy of) the array representing the dimensionality of each parent of a node, that is, the number of values which that node can take on. The order of entries in this array is the same as the order of entries of nodes returned by getParents() for that node.
- See Also:
 
- 
getParentspublic int[] getParents(int nodeIndex) Returns the parents of the given node.- Specified by:
- getParentsin interface- BayesIm
- Parameters:
- nodeIndex- the index of the node.
- Returns:
- (a defensive copy of) the array containing all of the parents of a given node in the order in which they are stored internally.
- See Also:
 
- 
getParentValuespublic int[] getParentValues(int nodeIndex, int rowIndex) Returns the parents values of the given node.- Specified by:
- getParentValuesin interface- BayesIm
- Parameters:
- nodeIndex- the index of the node.
- rowIndex- the index of the row in question.
- Returns:
- an array containing the combination of parent values for a given node and given row in the probability table for that node. To get the combination of parent values from the row number, the row number is represented using a variable-base place value system, where the bases for each place value are the dimensions of the parents in the order in which they are given by getParentDims(). For instance, if the row number (base 10) is 103 and the parent dimension array is [3 5 7], we calculate the first value as 103 / 7 = 14 with a remainder of 5. We then divide 14 / 5 = 2 with a remainder of 4. We then divide 2 / 3 = 0 with a remainder of 2. The variable place value representation is [2 4 5], which is the combination of parent values. This is the inverse function of getRowIndex().
- See Also:
 
- 
getParentValuepublic int getParentValue(int nodeIndex, int rowIndex, int colIndex) Returns the given parent value.- Specified by:
- getParentValuein interface- BayesIm
- Parameters:
- nodeIndex- the index of the node.
- rowIndex- the index of the row in question.
- colIndex- the index of the column in question.
- Returns:
- the value in the probability table for the given node, at the given row and column.
 
- 
getProbabilitypublic double getProbability(int nodeIndex, int rowIndex, int colIndex) Returns the probability for the given cell in the given CPT.- Specified by:
- getProbabilityin interface- BayesIm
- Parameters:
- nodeIndex- the index of the node in question.
- rowIndex- the row in the table for this for node which represents the combination of parent values in question.
- colIndex- the column in the table for this node which represents the value of the node in question.
- Returns:
- the probability for the given node at the given row and column in the table for that node. To get the node index, use getNodeIndex(). To get the row index, use getRowIndex(). To get the column index, use getCategoryIndex() from the underlying BayesPm(). The value returned will represent a conditional probability of the form P(N=v0 | P1=v1, P2=v2, ... , Pn=vn), where N is the node referenced by nodeIndex, v0 is the value referenced by colIndex, and the combination of parent values indicated is the combination indicated by rowIndex.
- See Also:
 
- 
getRowIndexpublic int getRowIndex(int nodeIndex, int[] values) getRowIndex. - Specified by:
- getRowIndexin interface- BayesIm
- Parameters:
- nodeIndex- a int
- values- an array of objects
- Returns:
- the row in the table for the given node and combination of parent values.
- See Also:
 
- 
normalizeAllpublic void normalizeAll()Normalizes all rows in the tables associated with each of node in turn.- Specified by:
- normalizeAllin interface- BayesIm
 
- 
normalizeNodepublic void normalizeNode(int nodeIndex) Normalizes all rows in the table associated with a given node.Normalizes all rows in the table associated with a given node. - Specified by:
- normalizeNodein interface- BayesIm
- Parameters:
- nodeIndex- the index of the node in question.
 
- 
normalizeRowpublic void normalizeRow(int nodeIndex, int rowIndex) Normalizes the given row.Normalizes the given row. - Specified by:
- normalizeRowin interface- BayesIm
- Parameters:
- nodeIndex- the index of the node in question.
- rowIndex- the index of the row in question.
 
- 
setProbabilitypublic void setProbability(int nodeIndex, double[][] probMatrix) Sets the probability for the given node. The matrix row represent row index, the row in the table for this for node which represents the combination of parent values in question. of the CPT. The matrix column represent column index, the column in the table for this node which represents the value of the node in question.Sets the probability for the given node. The matrix row represent row index, the row in the table for this for node which represents the combination of parent values in question. of the CPT. The matrix column represent column index, the column in the table for this node which represents the value of the node in question. - Specified by:
- setProbabilityin interface- BayesIm
- Parameters:
- nodeIndex- the index of the node in question.
- probMatrix- a matrix containing probabilities of a node along with its parents
 
- 
setProbabilitypublic void setProbability(int nodeIndex, int rowIndex, int colIndex, double value) Sets the probability for the given node at a given row and column in the table for that node. To get the node index, use getNodeIndex(). To get the row index, use getRowIndex(). To get the column index, use getCategoryIndex() from the underlying BayesPm(). The value returned will represent a conditional probability of the form P(N=v0 | P1=v1, P2=v2, ... , Pn=vn), where N is the node referenced by nodeIndex, v0 is the value referenced by colIndex, and the combination of parent values indicated is the combination indicated by rowIndex.Sets the probability for the given node at a given row and column in the table for that node. To get the node index, use getNodeIndex(). To get the row index, use getRowIndex(). To get the column index, use getCategoryIndex() from the underlying BayesPm(). The value returned will represent a conditional probability of the form P(N=v0 | P1=v1, P2=v2, ... , Pn=vn), where N is the node referenced by nodeIndex, v0 is the value referenced by colIndex, and the combination of parent values indicated is the combination indicated by rowIndex. - Specified by:
- setProbabilityin interface- BayesIm
- Parameters:
- nodeIndex- the index of the node in question.
- rowIndex- the row in the table for this for node which represents the combination of parent values in question.
- colIndex- the column in the table for this node which represents the value of the node in question.
- value- the desired probability to be set.
- See Also:
 
- 
getCorrespondingNodeIndexReturns the index of the given node in the given BayesIm.- Specified by:
- getCorrespondingNodeIndexin interface- BayesIm
- Parameters:
- nodeIndex- the index of the node in this BayesIm.
- otherBayesIm- the BayesIm in which the node is to be found.
- Returns:
- the index of the node with the given name in the specified BayesIm.
 
- 
clearRowpublic void clearRow(int nodeIndex, int rowIndex) Assigns random probability values to the child values of this row that add to 1.Assigns random probability values to the child values of this row that add to 1. 
- 
randomizeRowpublic void randomizeRow(int nodeIndex, int rowIndex) Assigns random probability values to the child values of this row that add to 1.Assigns random probability values to the child values of this row that add to 1. - Specified by:
- randomizeRowin interface- BayesIm
- Parameters:
- nodeIndex- the node for the table that this row belongs to.
- rowIndex- the index of the row.
 
- 
randomizeIncompleteRowspublic void randomizeIncompleteRows(int nodeIndex) Randomizes any row in the table for the given node index that has a Double.NaN value in it.Randomizes any row in the table for the given node index that has a Double.NaN value in it. - Specified by:
- randomizeIncompleteRowsin interface- BayesIm
- Parameters:
- nodeIndex- the node for the table whose incomplete rows are to be randomized.
 
- 
randomizeTablepublic void randomizeTable(int nodeIndex) Randomizes every row in the table for the given node index.Randomizes every row in the table for the given node index. - Specified by:
- randomizeTablein interface- BayesIm
- Parameters:
- nodeIndex- the node for the table to be randomized.
 
- 
clearTablepublic void clearTable(int nodeIndex) Randomizes every row in the table for the given node index.Randomizes every row in the table for the given node index. - Specified by:
- clearTablein interface- BayesIm
- Parameters:
- nodeIndex- the node for the table to be randomized.
 
- 
isIncompletepublic boolean isIncomplete(int nodeIndex, int rowIndex) Returns true iff the given row in the given node has a Double.NaN value in it.- Specified by:
- isIncompletein interface- BayesIm
- Parameters:
- nodeIndex- the node for the table whose incomplete rows are to be checked.
- rowIndex- the index of the row in question.
- Returns:
- true iff one of the values in the given row is Double.NaN.
 
- 
isIncompletepublic boolean isIncomplete(int nodeIndex) Returns true iff the given node has a Double.NaN value in it.- Specified by:
- isIncompletein interface- BayesIm
- Parameters:
- nodeIndex- the node for the table whose incomplete rows are to be checked.
- Returns:
- true iff any value in the table for the given node is Double.NaN.
 
- 
simulateDataSimulates a data set with the specified number of rows.Simulates a sample with the given sample size. - Specified by:
- simulateDatain interface- BayesIm
- Specified by:
- simulateDatain interface- Simulator
- Parameters:
- sampleSize- the number of rows to simulate.
- latentDataSaved- if true, latent variables are saved in the data set.
- Returns:
- the simulated data set.
 
- 
simulateDataSimulates data based on the provided data set and saves the latent data if specified.- Specified by:
- simulateDatain interface- BayesIm
- Parameters:
- dataSet- the data set to simulate data for
- latentDataSaved- a boolean value indicating whether the latent data should be saved or not
- Returns:
- the simulated data set
 
- 
equalsReturns true iff this Bayes net is equal to the given Bayes net. The sense of equality may vary depending on the type of Bayes net.
- 
toStringPrints out the probability table for each variable.
- 
getBayesImObsGetter for the field bayesImObs.- Returns:
- a BayesImobject
 
- 
getJPDgetJPD. - Returns:
- a StoredCellProbsObsobject
 
- 
getNumRowspublic int getNumRows()getNumRows. - Returns:
- a int
 
- 
getRowValuespublic int[] getRowValues(int rowIndex) getRowValues. - Parameters:
- rowIndex- a int
- Returns:
- an array of objects
 
- 
getProbabilitypublic double getProbability(int rowIndex) getProbability. - Parameters:
- rowIndex- a int
- Returns:
- a double
 
- 
setProbabilitypublic void setProbability(int rowIndex, double value) setProbability. - Parameters:
- rowIndex- a int
- value- a double
 
- 
createRandomCellTablepublic void createRandomCellTable()createRandomCellTable. 
 
-