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
ConstructorsConstructorDescriptionDefault constructor.AbstractPGM(List<NodeType> nodes) Common initialisation for PGMs.AbstractPGM(List<NodeType> nodes, Dataset dataset) Common initialisation for PGMs. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the provided nodes to the PGM.booleanReturns true if all the parameters were estimated.voidcomputeSufficientStatistics(List<Integer> idxNodes) Computes the sufficient statistics for the nodes whose indexes are specified.voiddisplay()Displays the probabilistic graphical model.voidDisplays the probabilistic graphical model.voidDisplays 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.intgetIndexOfNode(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 aNodeFactoryfor the nodes of the PGM.Returns the node indexer of the model.getNodes()Returns all the nodes in the model.intReturns 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.voidinitialiseModel(Dataset dataset) Sets the dataset that will be used to estimate the structure and parameters of the model and creates its nodes.booleanisStructureLegal(boolean[][] adjacencyMatrix) Determines if the structure is legal.voidlearn()Learns the structure and parameters of the model.longLearns the structure and parameters of the model from a given dataset.voidLearns the parameters and parent set of a model's node from a given dataset.voidLearns the parameters and parent set of some nodes of the model from a given dataset.voidLearns the parameters of the PGM.voidlearnParameters(Dataset dataset) Learns the parameters of the PGM using the provided dataset.voidlearnParameters(Dataset dataset, int idxNode) Learns the parameters of a certain node of the PGM using the provided dataset.voidlearnParameters(Integer idxNode) Learns the parameters of the node whose index is specified.voidlearnParameters(List<Integer> idxNodes) Learns the parameters of the nodes whose indexes are specified.voidlearnParameters(List<Integer> idxNodes, ParameterLearningAlgorithm parameterLearningAlg) Learns the parameters of the nodes whose indexes are specified using a provider parameter learning algorithm.voidRemove all edges between the nodes of the PGM.voidRemoves all the nodes from the PGM.voidSaves the PGM graph to a file.voidsetDataset(Dataset dataset) Set the dataset used to learn the PGM.voidsetNameVariables(List<String> nameVariables) Set the name of the variables in the PGM.voidsetParameterLearningAlgorithm(ParameterLearningAlgorithm parameterLearningAlg) Establishes the algorithm that will be used to learn the parameters of the PGM.voidsetStructure(boolean[][] adjacencyMatrix) Modifies the structure of the PGM by changing the parents of the nodes.voidsetStructure(int idxNode, boolean[][] adjacencyMatrix) Updates the structure of the model only for the specified node.voidsetStructure(List<Integer> idxNodes, boolean[][] adjacencyMatrix) Updates the structure of the model only for the specified node.voidsetStructureConstraints(StructureConstraints structureConstraints) Establishes the constraints that the PGM needs to meet.voidsetStructureLearningAlgorithm(StructureLearningAlgorithm structureLearningAlg) Establishes the algorithm that will be used to learn the structure of the PGM.voidsetStructureModifiedNodes(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, waitMethods 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:PGMAdds the provided nodes to the PGM. -
areParametersEstimated
public boolean areParametersEstimated()Description copied from interface:PGMReturns true if all the parameters were estimated.- Specified by:
areParametersEstimatedin interfacePGM<NodeType extends Node>- Returns:
- true if all the parameters were estimated
-
computeSufficientStatistics
Description copied from interface:PGMComputes the sufficient statistics for the nodes whose indexes are specified.- Specified by:
computeSufficientStatisticsin interfacePGM<NodeType extends Node>- Parameters:
idxNodes- node indexes
-
display
public void display()Description copied from interface:PGMDisplays the probabilistic graphical model. -
display
Description copied from interface:PGMDisplays the probabilistic graphical model. -
display
Description copied from interface:PGMDisplays the probabilistic graphical model. -
getAdjacencyMatrix
public boolean[][] getAdjacencyMatrix()Returns the adjacency matrix of the PGM by analysing the parents of each node.- Specified by:
getAdjacencyMatrixin interfacePGM<NodeType extends Node>- Returns:
- two-dimensional
booleanarray representing the adjacency matrix
-
getIndexNodes
Description copied from interface:PGMReturns the indexes of the nodes.- Specified by:
getIndexNodesin interfacePGM<NodeType extends Node>- Returns:
- node indexes
-
getNamesNodesByIndex
Description copied from interface:PGMReturn the names of the nodes whose indexes are given.- Specified by:
getNamesNodesByIndexin interfacePGM<NodeType extends Node>- Parameters:
indexes- node indexes- Returns:
- node names
-
getNodeByIndex
Description copied from interface:PGMObtains the node (feature or class variable) with a certain index.- Specified by:
getNodeByIndexin interfacePGM<NodeType extends Node>- Parameters:
index- node index- Returns:
- node with the specified index
-
getIndexOfNode
Description copied from interface:PGMReturns the index of the provided node.- Specified by:
getIndexOfNodein interfacePGM<NodeType extends Node>- Parameters:
node- node for which the index is needed- Returns:
- index of the node
-
getNodeByName
Description copied from interface:PGMReturns the node whose variable name is given.- Specified by:
getNodeByNamein interfacePGM<NodeType extends Node>- Parameters:
nameVariable- name of the variable- Returns:
- requested node
-
getNodeIndexer
Returns the node indexer of the model.- Specified by:
getNodeIndexerin interfacePGM<NodeType extends Node>- Returns:
- node indexer
-
getNodes
Description copied from interface:PGMReturns all the nodes in the model. -
getNumNodes
public int getNumNodes()Description copied from interface:PGMReturns the number of nodes.- Specified by:
getNumNodesin interfacePGM<NodeType extends Node>- Returns:
- number of nodes
-
getParameterLearningAlg
Description copied from interface:PGMReturns the algorithm that is used to learn the parameters of the PGM.- Specified by:
getParameterLearningAlgin interfacePGM<NodeType extends Node>- Returns:
- parameter learning algorithm
-
initialiseModel
Description copied from interface:PGMSets the dataset that will be used to estimate the structure and parameters of the model and creates its nodes.- Specified by:
initialiseModelin 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:
isStructureLegalin interfacePGM<NodeType extends Node>- Parameters:
adjacencyMatrix- adjacency matrix- Returns:
- true if the structure is valid, false otherwise
-
learn
Description copied from interface:PGMLearns the structure and parameters of the model.- Specified by:
learnin interfacePGM<NodeType extends Node>- Throws:
ErroneousValueException- if a provided parameter is erroneous for the requested task
-
learn
Description copied from interface:PGMLearns the structure and parameters of the model from a given dataset.- Specified by:
learnin 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:PGMLearns the parameters and parent set of a model's node from a given dataset.- Specified by:
learnin 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:PGMLearns the parameters and parent set of some nodes of the model from a given dataset.- Specified by:
learnin 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:PGMLearns the parameters of the PGM.- Specified by:
learnParametersin interfacePGM<NodeType extends Node>
-
learnParameters
Description copied from interface:PGMLearns the parameters of the PGM using the provided dataset.- Specified by:
learnParametersin interfacePGM<NodeType extends Node>- Parameters:
dataset- dataset used to learn the parameters
-
learnParameters
Description copied from interface:PGMLearns the parameters of a certain node of the PGM using the provided dataset.- Specified by:
learnParametersin interfacePGM<NodeType extends Node>- Parameters:
dataset- dataset used to learn the parametersidxNode- node index
-
learnParameters
Description copied from interface:PGMLearns the parameters of the nodes whose indexes are specified.- Specified by:
learnParametersin interfacePGM<NodeType extends Node>- Parameters:
idxNodes- indexes of the nodes whose parameters should be learnt
-
learnParameters
Description copied from interface:PGMLearns the parameters of the node whose index is specified.- Specified by:
learnParametersin 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:PGMLearns the parameters of the nodes whose indexes are specified using a provider parameter learning algorithm.- Specified by:
learnParametersin interfacePGM<NodeType extends Node>- Parameters:
idxNodes- indexes of the nodes whose parameters should be learntparameterLearningAlg- aParameterLearningAlgorithm
-
removeAllEdges
public void removeAllEdges()Description copied from interface:PGMRemove all edges between the nodes of the PGM.- Specified by:
removeAllEdgesin interfacePGM<NodeType extends Node>
-
removeAllNodes
public void removeAllNodes()Description copied from interface:PGMRemoves all the nodes from the PGM.- Specified by:
removeAllNodesin interfacePGM<NodeType extends Node>
-
saveGraph
Description copied from interface:PGMSaves the PGM graph to a file. -
setStructure
public void setStructure(boolean[][] adjacencyMatrix) Description copied from interface:PGMModifies the structure of the PGM by changing the parents of the nodes.- Specified by:
setStructurein 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:PGMUpdates the structure of the model only for the specified node.- Specified by:
setStructurein interfacePGM<NodeType extends Node>- Parameters:
idxNode- node indexadjacencyMatrix- adjacency matrix
-
setStructure
Description copied from interface:PGMUpdates the structure of the model only for the specified node.- Specified by:
setStructurein interfacePGM<NodeType extends Node>- Parameters:
idxNodes- node indexesadjacencyMatrix- adjacency matrix found
-
setStructureModifiedNodes
public void setStructureModifiedNodes(boolean[][] newAdjacencyMatrix) Description copied from interface:PGMModifies 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:
setStructureModifiedNodesin interfacePGM<NodeType extends Node>- Parameters:
newAdjacencyMatrix- new adjacency matrix
-
getNodeFactory
Returns aNodeFactoryfor 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 Mapwith 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
-