Module es.upm.fi.cig.multictbnc
Package es.upm.fi.cig.multictbnc.models
Class AbstractPGM<NodeType extends Node>
java.lang.Object
es.upm.fi.cig.multictbnc.models.AbstractPGM<NodeType>
- Type Parameters:
NodeType
- type of nodes used by the model, e.g., nodes with conditional probability tables (CPTNode
) or conditional intensity matrices (@code CIMNode)
- All Implemented Interfaces:
PGM<NodeType>
- Direct Known Subclasses:
BN
,CTBN
,MultiCTBNC
Contains common attributes and methods for PGM.
-
Constructor Summary
ConstructorDescriptionDefault constructor.AbstractPGM
(List<NodeType> nodes) Common initialisation for PGMs.AbstractPGM
(List<NodeType> nodes, Dataset dataset) Common initialisation for PGMs. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds the provided nodes to the PGM.boolean
Returns true if all the parameters were estimated.void
computeSufficientStatistics
(List<Integer> idxNodes) Computes the sufficient statistics for the nodes whose indexes are specified.void
display()
Displays the probabilistic graphical model.void
Displays the probabilistic graphical model.void
Displays the probabilistic graphical model.boolean[][]
Returns the adjacency matrix of the PGM by analysing the parents of each node.Returns the dataset used to learn the PGM.Returns the hyperparameters of the model the user sets.Returns the indexes of the nodes.int
getIndexOfNode
(Node node) Returns the index of the provided node.getNamesNodesByIndex
(List<Integer> indexes) Return the names of the nodes whose indexes are given.Returns the names of the variables of the PGM.getNodeByIndex
(int index) Obtains the node (feature or class variable) with a certain index.getNodeByName
(String nameVariable) Returns the node whose variable name is given.Returns the type of the nodes.protected NodeFactory<NodeType>
Returns aNodeFactory
for the nodes of the PGM.Returns the node indexer of the model.getNodes()
Returns all the nodes in the model.int
Returns the number of nodes.Returns the algorithm that is used to learn the parameters of the PGM.Returns the constraints that the PGM needs to meet.Returns the algorithm used to learn the structure of the PGM.void
initialiseModel
(Dataset dataset) Sets the dataset that will be used to estimate the structure and parameters of the model and creates its nodes.boolean
isStructureLegal
(boolean[][] adjacencyMatrix) Determines if the structure is legal.void
learn()
Learns the structure and parameters of the model.long
Learns the structure and parameters of the model from a given dataset.void
Learns the parameters and parent set of a model's node from a given dataset.void
Learns the parameters and parent set of some nodes of the model from a given dataset.void
Learns the parameters of the PGM.void
learnParameters
(Dataset dataset) Learns the parameters of the PGM using the provided dataset.void
learnParameters
(Dataset dataset, int idxNode) Learns the parameters of a certain node of the PGM using the provided dataset.void
learnParameters
(Integer idxNode) Learns the parameters of the node whose index is specified.void
learnParameters
(List<Integer> idxNodes) Learns the parameters of the nodes whose indexes are specified.void
learnParameters
(List<Integer> idxNodes, ParameterLearningAlgorithm parameterLearningAlg) Learns the parameters of the nodes whose indexes are specified using a provider parameter learning algorithm.void
Remove all edges between the nodes of the PGM.void
Removes all the nodes from the PGM.void
Saves the PGM graph to a file.void
setDataset
(Dataset dataset) Set the dataset used to learn the PGM.void
setNameVariables
(List<String> nameVariables) Set the name of the variables in the PGM.void
setParameterLearningAlgorithm
(ParameterLearningAlgorithm parameterLearningAlg) Establishes the algorithm that will be used to learn the parameters of the PGM.void
setStructure
(boolean[][] adjacencyMatrix) Modifies the structure of the PGM by changing the parents of the nodes.void
setStructure
(int idxNode, boolean[][] adjacencyMatrix) Updates the structure of the model only for the specified node.void
setStructure
(List<Integer> idxNodes, boolean[][] adjacencyMatrix) Updates the structure of the model only for the specified node.void
setStructureConstraints
(StructureConstraints structureConstraints) Establishes the constraints that the PGM needs to meet.void
setStructureLearningAlgorithm
(StructureLearningAlgorithm structureLearningAlg) Establishes the algorithm that will be used to learn the structure of the PGM.void
setStructureModifiedNodes
(boolean[][] newAdjacencyMatrix) Modifies the structure of the PGM by changing the parents and CPDs of those nodes which have different parents between the current adjacency matrix and the new one.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface es.upm.fi.cig.multictbnc.models.PGM
getModelIdentifier, getType
-
Constructor Details
-
AbstractPGM
Common initialisation for PGMs.- Parameters:
nodes
- nodes of the PGM
-
AbstractPGM
Common initialisation for PGMs. The provided dataset is used to learn the model. References to the provided nodes are stored.- Parameters:
nodes
- nodes of the PGMdataset
- dataset used to learn the model
-
AbstractPGM
public AbstractPGM()Default constructor.
-
-
Method Details
-
addNodes
Description copied from interface:PGM
Adds the provided nodes to the PGM. -
areParametersEstimated
public boolean areParametersEstimated()Description copied from interface:PGM
Returns true if all the parameters were estimated.- Specified by:
areParametersEstimated
in interfacePGM<NodeType extends Node>
- Returns:
- true if all the parameters were estimated
-
computeSufficientStatistics
Description copied from interface:PGM
Computes the sufficient statistics for the nodes whose indexes are specified.- Specified by:
computeSufficientStatistics
in interfacePGM<NodeType extends Node>
- Parameters:
idxNodes
- node indexes
-
display
public void display()Description copied from interface:PGM
Displays the probabilistic graphical model. -
display
Description copied from interface:PGM
Displays the probabilistic graphical model. -
display
Description copied from interface:PGM
Displays the probabilistic graphical model. -
getAdjacencyMatrix
public boolean[][] getAdjacencyMatrix()Returns the adjacency matrix of the PGM by analysing the parents of each node.- Specified by:
getAdjacencyMatrix
in interfacePGM<NodeType extends Node>
- Returns:
- two-dimensional
boolean
array representing the adjacency matrix
-
getIndexNodes
Description copied from interface:PGM
Returns the indexes of the nodes.- Specified by:
getIndexNodes
in interfacePGM<NodeType extends Node>
- Returns:
- node indexes
-
getNamesNodesByIndex
Description copied from interface:PGM
Return the names of the nodes whose indexes are given.- Specified by:
getNamesNodesByIndex
in interfacePGM<NodeType extends Node>
- Parameters:
indexes
- node indexes- Returns:
- node names
-
getNodeByIndex
Description copied from interface:PGM
Obtains the node (feature or class variable) with a certain index.- Specified by:
getNodeByIndex
in interfacePGM<NodeType extends Node>
- Parameters:
index
- node index- Returns:
- node with the specified index
-
getIndexOfNode
Description copied from interface:PGM
Returns the index of the provided node.- Specified by:
getIndexOfNode
in interfacePGM<NodeType extends Node>
- Parameters:
node
- node for which the index is needed- Returns:
- index of the node
-
getNodeByName
Description copied from interface:PGM
Returns the node whose variable name is given.- Specified by:
getNodeByName
in interfacePGM<NodeType extends Node>
- Parameters:
nameVariable
- name of the variable- Returns:
- requested node
-
getNodeIndexer
Returns the node indexer of the model.- Specified by:
getNodeIndexer
in interfacePGM<NodeType extends Node>
- Returns:
- node indexer
-
getNodes
Description copied from interface:PGM
Returns all the nodes in the model. -
getNumNodes
public int getNumNodes()Description copied from interface:PGM
Returns the number of nodes.- Specified by:
getNumNodes
in interfacePGM<NodeType extends Node>
- Returns:
- number of nodes
-
getParameterLearningAlg
Description copied from interface:PGM
Returns the algorithm that is used to learn the parameters of the PGM.- Specified by:
getParameterLearningAlg
in interfacePGM<NodeType extends Node>
- Returns:
- parameter learning algorithm
-
initialiseModel
Description copied from interface:PGM
Sets the dataset that will be used to estimate the structure and parameters of the model and creates its nodes.- Specified by:
initialiseModel
in interfacePGM<NodeType extends Node>
- Parameters:
dataset
- dataset used to learn the model
-
isStructureLegal
public boolean isStructureLegal(boolean[][] adjacencyMatrix) Determines if the structure is legal.- Specified by:
isStructureLegal
in interfacePGM<NodeType extends Node>
- Parameters:
adjacencyMatrix
- adjacency matrix- Returns:
- true if the structure is valid, false otherwise
-
learn
Description copied from interface:PGM
Learns the structure and parameters of the model.- Specified by:
learn
in interfacePGM<NodeType extends Node>
- Throws:
ErroneousValueException
- if a provided parameter is erroneous for the requested task
-
learn
Description copied from interface:PGM
Learns the structure and parameters of the model from a given dataset.- Specified by:
learn
in interfacePGM<NodeType extends Node>
- Parameters:
dataset
- dataset used to learn the model- Returns:
- time to learn the model
- Throws:
ErroneousValueException
- if a provided parameter is erroneous for the requested task
-
learn
Description copied from interface:PGM
Learns the parameters and parent set of a model's node from a given dataset.- Specified by:
learn
in interfacePGM<NodeType extends Node>
- Parameters:
dataset
- dataset used to learn the parameters and parent set of the nodeidxNode
- node index- Throws:
ErroneousValueException
- if a provided parameter is erroneous for the requested task
-
learn
Description copied from interface:PGM
Learns the parameters and parent set of some nodes of the model from a given dataset.- Specified by:
learn
in interfacePGM<NodeType extends Node>
- Parameters:
dataset
- dataset used to learn the parameters and parent set of the nodesidxNodes
- node indexes- Throws:
ErroneousValueException
- if a provided parameter is erroneous for the requested task
-
learnParameters
public void learnParameters()Description copied from interface:PGM
Learns the parameters of the PGM.- Specified by:
learnParameters
in interfacePGM<NodeType extends Node>
-
learnParameters
Description copied from interface:PGM
Learns the parameters of the PGM using the provided dataset.- Specified by:
learnParameters
in interfacePGM<NodeType extends Node>
- Parameters:
dataset
- dataset used to learn the parameters
-
learnParameters
Description copied from interface:PGM
Learns the parameters of a certain node of the PGM using the provided dataset.- Specified by:
learnParameters
in interfacePGM<NodeType extends Node>
- Parameters:
dataset
- dataset used to learn the parametersidxNode
- node index
-
learnParameters
Description copied from interface:PGM
Learns the parameters of the nodes whose indexes are specified.- Specified by:
learnParameters
in interfacePGM<NodeType extends Node>
- Parameters:
idxNodes
- indexes of the nodes whose parameters should be learnt
-
learnParameters
Description copied from interface:PGM
Learns the parameters of the node whose index is specified.- Specified by:
learnParameters
in interfacePGM<NodeType extends Node>
- Parameters:
idxNode
- index of the node whose parameters should be learnt
-
learnParameters
public void learnParameters(List<Integer> idxNodes, ParameterLearningAlgorithm parameterLearningAlg) Description copied from interface:PGM
Learns the parameters of the nodes whose indexes are specified using a provider parameter learning algorithm.- Specified by:
learnParameters
in interfacePGM<NodeType extends Node>
- Parameters:
idxNodes
- indexes of the nodes whose parameters should be learntparameterLearningAlg
- aParameterLearningAlgorithm
-
removeAllEdges
public void removeAllEdges()Description copied from interface:PGM
Remove all edges between the nodes of the PGM.- Specified by:
removeAllEdges
in interfacePGM<NodeType extends Node>
-
removeAllNodes
public void removeAllNodes()Description copied from interface:PGM
Removes all the nodes from the PGM.- Specified by:
removeAllNodes
in interfacePGM<NodeType extends Node>
-
saveGraph
Description copied from interface:PGM
Saves the PGM graph to a file. -
setStructure
public void setStructure(boolean[][] adjacencyMatrix) Description copied from interface:PGM
Modifies the structure of the PGM by changing the parents of the nodes.- Specified by:
setStructure
in interfacePGM<NodeType extends Node>
- Parameters:
adjacencyMatrix
- adjacency matrix with the new structure of the PGM
-
setStructure
public void setStructure(int idxNode, boolean[][] adjacencyMatrix) Description copied from interface:PGM
Updates the structure of the model only for the specified node.- Specified by:
setStructure
in interfacePGM<NodeType extends Node>
- Parameters:
idxNode
- node indexadjacencyMatrix
- adjacency matrix
-
setStructure
Description copied from interface:PGM
Updates the structure of the model only for the specified node.- Specified by:
setStructure
in interfacePGM<NodeType extends Node>
- Parameters:
idxNodes
- node indexesadjacencyMatrix
- adjacency matrix found
-
setStructureModifiedNodes
public void setStructureModifiedNodes(boolean[][] newAdjacencyMatrix) Description copied from interface:PGM
Modifies the structure of the PGM by changing the parents and CPDs of those nodes which have different parents between the current adjacency matrix and the new one.- Specified by:
setStructureModifiedNodes
in interfacePGM<NodeType extends Node>
- Parameters:
newAdjacencyMatrix
- new adjacency matrix
-
getNodeFactory
Returns aNodeFactory
for the nodes of the PGM.- Returns:
- a
NodeFactory
-
getNodeClass
Returns the type of the nodes.- Returns:
- type of the nodes
-
getDataset
Returns the dataset used to learn the PGM.- Returns:
- dataset
-
setDataset
Set the dataset used to learn the PGM.- Parameters:
dataset
- dataset
-
getHyperparameters
Returns the hyperparameters of the model the user sets.- Returns:
a Map
with the hyperparameters
-
getNameVariables
Returns the names of the variables of the PGM.- Returns:
- names of the variables
-
setNameVariables
Set the name of the variables in the PGM.- Parameters:
nameVariables
- names of the variables
-
getStructureConstraints
Returns the constraints that the PGM needs to meet.- Returns:
- structure constraints
-
setStructureConstraints
Establishes the constraints that the PGM needs to meet.- Parameters:
structureConstraints
- structure constraints to take into account during the learning of the model
-
getStructureLearningAlg
Returns the algorithm used to learn the structure of the PGM.- Returns:
- structure learning algorithm
-
setParameterLearningAlgorithm
Establishes the algorithm that will be used to learn the parameters of the PGM.- Parameters:
parameterLearningAlg
- parameter learning algorithm
-
setStructureLearningAlgorithm
Establishes the algorithm that will be used to learn the structure of the PGM.- Parameters:
structureLearningAlg
- structure learning algorithm
-