Package edu.cmu.tetrad.bayes
Class CptMapCounts
java.lang.Object
edu.cmu.tetrad.bayes.CptMapCounts
- 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 cell count for that node, where 0's are not stored. Row counts are also
stored, so that the probability of a cell can be calculated. A prior cell count of 0 is assumed for all cells,
but this may be set by the user to any non-negative count. (A prior count of 0 is equivalent to a maximum
likelihood estimate.)
- Author:
- josephramsey
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCptMapCounts
(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.CptMapCounts
(DataSet data) Constructs a new CptMap based on counts from a given dataset. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addCounts
(int row, int column, int count) Adds the specified count to the cell count at the given row and column.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.double
Retrieves the prior count for all cells in the CptMapCounts.void
setPriorCount
(double priorCount) Sets the prior count for all cells in the CptMapCounts.
-
Constructor Details
-
CptMapCounts
public CptMapCounts(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
-
CptMapCounts
Constructs a new CptMap based on counts from a given dataset.- Parameters:
data
- the DataSet object representing the probability matrix- Throws:
IllegalArgumentException
- if the data set is null or not discrete
-
-
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. -
addCounts
public void addCounts(int row, int column, int count) Adds the specified count to the cell count at the given row and column.- Parameters:
row
- the row index of the cell countcolumn
- the column index of the cell countcount
- the count to be added to the cell count- Throws:
IllegalArgumentException
- if the row or column is out of bounds
-
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.
-
getPriorCount
public double getPriorCount()Retrieves the prior count for all cells in the CptMapCounts.- Returns:
- the prior count for all cells in the CptMapCounts.
-
setPriorCount
public void setPriorCount(double priorCount) Sets the prior count for all cells in the CptMapCounts. The prior count is used in parameter estimation for Bayesian networks.- Parameters:
priorCount
- the value to set as the prior count.
-