Class JunctionTreeUpdater

java.lang.Object
edu.cmu.tetrad.bayes.JunctionTreeUpdater
All Implemented Interfaces:
BayesUpdater, ManipulatingBayesUpdater, TetradSerializable, Serializable

public final class JunctionTreeUpdater extends Object implements ManipulatingBayesUpdater
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

    Constructors
    Constructor
    Description
    Constructs a new instance of JunctionTreeUpdater using the provided Bayesian network representation.
    JunctionTreeUpdater(BayesIm bayesIm, Evidence evidence)
    Constructs a new instance of JunctionTreeUpdater, 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 Type
    Method
    Description
    double[]
    calculatePriorMarginals(int nodeIndex)
    Calculates the prior marginals for a specified node in the Bayesian network.
    double[]
    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.
    double
    getJointMarginal(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.
    double
    getMarginal(int variable, int value)
    Indicates whether this updater supports computing joint marginals.
    Retrieves the updated Bayesian network representation associated with this updater.
    boolean
    Indicates whether this updater supports computing joint marginals.
    Creates and returns a serializable instance of JunctionTreeUpdater.
    void
    Sets the evidence for the Bayesian network updater.
    Returns a string representation of the JunctionTreeUpdater2 instance, summarizing its inference method and current evidence state.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • JunctionTreeUpdater

      public JunctionTreeUpdater(BayesIm bayesIm)
      Constructs a new instance of JunctionTreeUpdater using the provided Bayesian network representation.
      Parameters:
      bayesIm - the Bayesian network representation in the form of a BayesIm. Must not be null.
      Throws:
      NullPointerException - if bayesIm is null.
    • JunctionTreeUpdater

      public JunctionTreeUpdater(BayesIm bayesIm, Evidence evidence)
      Constructs a new instance of JunctionTreeUpdater, using the provided Bayesian network representation and associated evidence.
      Parameters:
      bayesIm - the Bayesian network representation in the form of a BayesIm. Must not be null.
      evidence - the evidence object containing observed data for the Bayesian network. Can be null if no evidence is provided.
      Throws:
      NullPointerException - if bayesIm is null.
    • 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

      public static JunctionTreeUpdater serializableInstance()
      Creates and returns a serializable instance of JunctionTreeUpdater.
      Returns:
      a new instance of JunctionTreeUpdater, configured with a serializable BayesIm instance, enabling the use of this updater in serialized form.
    • getBayesIm

      public BayesIm getBayesIm()
      Retrieves the Bayesian network representation associated with this updater.
      Specified by:
      getBayesIm in interface BayesUpdater
      Returns:
      the BayesIm instance representing the current Bayesian network.
    • getManipulatedBayesIm

      public BayesIm 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:
      getManipulatedBayesIm in interface ManipulatingBayesUpdater
      Returns:
      the BayesIm instance representing the manipulated Bayesian network.
    • getManipulatedGraph

      public Graph 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:
      getManipulatedGraph in interface ManipulatingBayesUpdater
      Returns:
      the BayesIm instance representing the manipulated Bayesian network.
    • getUpdatedBayesIm

      public BayesIm 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:
      getUpdatedBayesIm in interface ManipulatingBayesUpdater
      Returns:
      the BayesIm instance representing the updated Bayesian network.
    • getEvidence

      public Evidence getEvidence()
      Retrieves the evidence associated with this updater. The evidence encapsulates the current state of observed variables and their values.
      Specified by:
      getEvidence in interface ManipulatingBayesUpdater
      Returns:
      the Evidence instance representing the current evidence.
    • setEvidence

      public void setEvidence(Evidence evidence)
      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:
      setEvidence in interface BayesUpdater
      Specified by:
      setEvidence in interface ManipulatingBayesUpdater
      Parameters:
      evidence - the Evidence object representing the observed data for the Bayesian network. Must not be null.
      Throws:
      NullPointerException - if evidence is null.
      IllegalArgumentException - if the variable list in the provided evidence is incompatible with the variable list in the BayesIm.
    • isJointMarginalSupported

      public boolean isJointMarginalSupported()
      Indicates whether this updater supports computing joint marginals.
      Specified by:
      isJointMarginalSupported in interface BayesUpdater
      Returns:
      true
    • getJointMarginal

      public double getJointMarginal(int[] variables, int[] values)
      Indicates whether this updater supports computing joint marginals.
      Specified by:
      getJointMarginal in interface BayesUpdater
      Parameters:
      variables - variable indices
      values - category indices
      Returns:
      true
    • getMarginal

      public double getMarginal(int variable, int value)
      Indicates whether this updater supports computing joint marginals.
      Specified by:
      getMarginal in interface BayesUpdater
      Specified by:
      getMarginal in interface ManipulatingBayesUpdater
      Parameters:
      variable - variable index
      value - 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:
      calculatePriorMarginals in interface BayesUpdater
      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:
      calculateUpdatedMarginals in interface BayesUpdater
      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

      public String toString()
      Returns a string representation of the JunctionTreeUpdater2 instance, summarizing its inference method and current evidence state.
      Overrides:
      toString in class Object
      Returns:
      a string describing the inference method used (RowSumming plumbing combined with Junction Tree inference) and the current evidence state.