Package edu.cmu.tetrad.bayes
Class CptMapProbs
java.lang.Object
edu.cmu.tetrad.bayes.CptMapProbs
- All Implemented Interfaces:
CptMap
,TetradSerializable
,Serializable
Represents a conditional probability table (CPT) in a Bayes net. This represents the CPT as a map from a unique
integer index for a particular node to the probability of that node taking on that value, where NaN's are not
stored.
- Author:
- josephramsey
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCptMapProbs
(double[][] probMatrix) Constructs a new probability map based on the given 2-dimensional array.CptMapProbs
(int numRows, int numColumns) Constructs a new probability map, a map from a unique integer index for a particular node to the probability of that node taking on that value, where NaN's are not stored. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Assigns the values in the provided vector to a specific row in the probability map.double
get
(int row, int column) Returns the probability of the node taking on the value specified by the given row and column.int
Returns the number of columns in the probability map.int
Returns the number of rows in the probability map.void
set
(int row, int column, double value) Sets the probability of the node taking on the value specified by the given row and column to the given value.
-
Constructor Details
-
CptMapProbs
public CptMapProbs(int numRows, int numColumns) Constructs a new probability map, a map from a unique integer index for a particular node to the probability of that node taking on that value, where NaN's are not stored. This probability map assumes that there is a certain number of rows and a certain number of columns in the table.- Parameters:
numRows
- the number of rows in the tablenumColumns
- the number of columns in the table
-
CptMapProbs
public CptMapProbs(double[][] probMatrix) Constructs a new probability map based on the given 2-dimensional array.- Parameters:
probMatrix
- the 2-dimensional array representing the probability matrix- Throws:
IllegalArgumentException
- if the number of columns in any row is different
-
-
Method Details
-
get
public double get(int row, int column) Returns the probability of the node taking on the value specified by the given row and column. -
set
public void set(int row, int column, double value) Sets the probability of the node taking on the value specified by the given row and column to the given value.- Parameters:
row
- the row of the nodecolumn
- the column of the nodevalue
- the probability of the node taking on the value specified by the given row and column (NaN to remove the value)
-
getNumRows
public int getNumRows()Returns the number of rows in the probability map.- Specified by:
getNumRows
in interfaceCptMap
- Returns:
- the number of rows in the probability map.
-
getNumColumns
public int getNumColumns()Returns the number of columns in the probability map.- Specified by:
getNumColumns
in interfaceCptMap
- Returns:
- the number of columns in the probability map.
-
assignRow
Assigns the values in the provided vector to a specific row in the probability map.- Parameters:
rowIndex
- the index of the row to be assignedvector
- the vector containing the values to be assigned to the row- Throws:
IllegalArgumentException
- if the size of the vector is not equal to the number of columns in the probability map
-