Class JunctionTreeUpdater
java.lang.Object
edu.cmu.tetrad.bayes.JunctionTreeUpdater
- All Implemented Interfaces:
BayesUpdater, ManipulatingBayesUpdater, TetradSerializable, Serializable
RowSummingExactUpdater-style updater plumbing, but uses JunctionTreeInference
for marginals/joints/conditionals. All evidence and BayesIm alignment behavior
is inherited from the RowSummingExactUpdater design.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionJunctionTreeUpdater(BayesIm bayesIm) Constructs a new instance ofJunctionTreeUpdaterusing the provided Bayesian network representation.JunctionTreeUpdater(BayesIm bayesIm, Evidence evidence) Constructs a new instance ofJunctionTreeUpdater, using the provided Bayesian network representation and associated evidence.JunctionTreeUpdater(BayesIm bayesIm, Evidence evidence, BayesIm manipulatedBayesIm, BayesIm updatedBayesIm, JunctionTreeInference jti) Creates an instance of the JunctionTreeUpdater class which performs updates on a junction tree structure based on Bayesian networks and evidence. -
Method Summary
Modifier and TypeMethodDescriptiondouble[]calculatePriorMarginals(int nodeIndex) Calculates the prior marginals for a specified node in the Bayesian network.double[]calculateUpdatedMarginals(int nodeIndex) Computes the updated marginal probabilities for a given node in a Bayesian network.Retrieves the Bayesian network representation associated with this updater.Retrieves the evidence associated with this updater.doublegetJointMarginal(int[] variables, int[] values) Indicates whether this updater supports computing joint marginals.Retrieves the manipulated Bayesian network representation associated with this updater.Retrieves the manipulated Bayesian network representation associated with this updater.doublegetMarginal(int variable, int value) Indicates whether this updater supports computing joint marginals.Retrieves the updated Bayesian network representation associated with this updater.booleanIndicates whether this updater supports computing joint marginals.static JunctionTreeUpdaterCreates and returns a serializable instance ofJunctionTreeUpdater.voidsetEvidence(Evidence evidence) Sets the evidence for the Bayesian network updater.toString()Returns a string representation of the JunctionTreeUpdater2 instance, summarizing its inference method and current evidence state.
-
Constructor Details
-
JunctionTreeUpdater
Constructs a new instance ofJunctionTreeUpdaterusing the provided Bayesian network representation.- Parameters:
bayesIm- the Bayesian network representation in the form of aBayesIm. Must not benull.- Throws:
NullPointerException- ifbayesImisnull.
-
JunctionTreeUpdater
Constructs a new instance ofJunctionTreeUpdater, using the provided Bayesian network representation and associated evidence.- Parameters:
bayesIm- the Bayesian network representation in the form of aBayesIm. Must not benull.evidence- the evidence object containing observed data for the Bayesian network. Can benullif no evidence is provided.- Throws:
NullPointerException- ifbayesImisnull.
-
JunctionTreeUpdater
public JunctionTreeUpdater(BayesIm bayesIm, Evidence evidence, BayesIm manipulatedBayesIm, BayesIm updatedBayesIm, JunctionTreeInference jti) Creates an instance of the JunctionTreeUpdater class which performs updates on a junction tree structure based on Bayesian networks and evidence.- Parameters:
bayesIm- The Bayesian network representation (BayesIm) used for the initial setup.evidence- The evidence object containing observations and values to be applied to the network.manipulatedBayesIm- The manipulated BayesIm reflecting changes to the original network.updatedBayesIm- The updated BayesIm reflecting the state of the network after processing evidence.jti- The JunctionTreeInference object used for performing inference on the junction tree.
-
-
Method Details
-
serializableInstance
Creates and returns a serializable instance ofJunctionTreeUpdater.- Returns:
- a new instance of
JunctionTreeUpdater, configured with a serializableBayesIminstance, enabling the use of this updater in serialized form.
-
getBayesIm
Retrieves the Bayesian network representation associated with this updater.- Specified by:
getBayesImin interfaceBayesUpdater- Returns:
- the
BayesIminstance representing the current Bayesian network.
-
getManipulatedBayesIm
Retrieves the manipulated Bayesian network representation associated with this updater. The manipulated Bayesian network incorporates changes based on applied interventions or adjustments, distinguishing it from the original or updated Bayesian network.- Specified by:
getManipulatedBayesImin interfaceManipulatingBayesUpdater- Returns:
- the
BayesIminstance representing the manipulated Bayesian network.
-
getManipulatedGraph
Retrieves the manipulated Bayesian network representation associated with this updater. The manipulated Bayesian network incorporates changes based on applied interventions or adjustments, distinguishing it from the original or updated Bayesian network.- Specified by:
getManipulatedGraphin interfaceManipulatingBayesUpdater- Returns:
- the
BayesIminstance representing the manipulated Bayesian network.
-
getUpdatedBayesIm
Retrieves the updated Bayesian network representation associated with this updater. The updated Bayesian network reflects the current state after applying interventions or adjustments, contrasting with the original or manipulated Bayesian network.- Specified by:
getUpdatedBayesImin interfaceManipulatingBayesUpdater- Returns:
- the
BayesIminstance representing the updated Bayesian network.
-
getEvidence
Retrieves the evidence associated with this updater. The evidence encapsulates the current state of observed variables and their values.- Specified by:
getEvidencein interfaceManipulatingBayesUpdater- Returns:
- the
Evidenceinstance representing the current evidence.
-
setEvidence
Sets the evidence for the Bayesian network updater. The provided evidence specifies observed data or conditions that will influence the Bayesian inference process. This method validates the compatibility of the evidence with the existing Bayesian network structure and updates internal states accordingly.- Specified by:
setEvidencein interfaceBayesUpdater- Specified by:
setEvidencein interfaceManipulatingBayesUpdater- Parameters:
evidence- theEvidenceobject representing the observed data for the Bayesian network. Must not benull.- Throws:
NullPointerException- ifevidenceisnull.IllegalArgumentException- if the variable list in the providedevidenceis incompatible with the variable list in theBayesIm.
-
isJointMarginalSupported
public boolean isJointMarginalSupported()Indicates whether this updater supports computing joint marginals.- Specified by:
isJointMarginalSupportedin interfaceBayesUpdater- Returns:
- true
-
getJointMarginal
public double getJointMarginal(int[] variables, int[] values) Indicates whether this updater supports computing joint marginals.- Specified by:
getJointMarginalin interfaceBayesUpdater- Parameters:
variables- variable indicesvalues- category indices- Returns:
- true
-
getMarginal
public double getMarginal(int variable, int value) Indicates whether this updater supports computing joint marginals.- Specified by:
getMarginalin interfaceBayesUpdater- Specified by:
getMarginalin interfaceManipulatingBayesUpdater- Parameters:
variable- variable indexvalue- category index- Returns:
- true
-
calculatePriorMarginals
public double[] calculatePriorMarginals(int nodeIndex) Calculates the prior marginals for a specified node in the Bayesian network. The method temporarily resets the evidence to a tautology, calculates the prior marginals for the specified node, and then restores the previous evidence.- Specified by:
calculatePriorMarginalsin interfaceBayesUpdater- Parameters:
nodeIndex- the index of the node in the Bayesian network for which the prior marginals are to be calculated. Must be a valid index within the range of nodes in the network.- Returns:
- an array of doubles representing the prior marginal probabilities of the different categories (states) for the specified node. The size of the array corresponds to the number of categories associated with the node.
-
calculateUpdatedMarginals
public double[] calculateUpdatedMarginals(int nodeIndex) Computes the updated marginal probabilities for a given node in a Bayesian network. The method calculates marginal probabilities for each category based on the current state of the Bayesian network. It ensures that the marginals are normalized unless the computed values are non-finite or the sum is not greater than zero, in which case the resulting marginals are set to NaN.- Specified by:
calculateUpdatedMarginalsin interfaceBayesUpdater- Parameters:
nodeIndex- the index of the node in the Bayesian network for which the updated marginal probabilities are to be calculated- Returns:
- an array containing the updated marginal probabilities for each category of the specified node. If the normalization conditions fail, the array contains NaN values
-
toString
Returns a string representation of the JunctionTreeUpdater2 instance, summarizing its inference method and current evidence state.
-