Class JunctionTreeInference

java.lang.Object
edu.cmu.tetrad.bayes.JunctionTreeInference
All Implemented Interfaces:
Serializable

public final class JunctionTreeInference extends Object implements Serializable
Exact junction-tree inference over a BayesIm supporting:
  • Soft evidence via allowed categories mask (Proposition)
  • Hard evidence via node=category
  • Marginals, conditionals, and joint marginals (all conditional on evidence)
This class is designed specifically to satisfy the methods required by JunctionTreeUpdater.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a JunctionTreeInference object for performing inference on a Bayesian network represented by the given BayesIm (Bayesian network model interface).
  • Method Summary

    Modifier and Type
    Method
    Description
    double[]
    getConditional(int node, int[] parents, int[] parentValues)
    Computes the conditional probability distribution of a given node (variable) conditioned on its parent variables and their specified values within a Bayesian network.
    double
    getJointProbability(int[] vars, int[] values)
    Computes the joint probability of a set of variables being in specified states according to the current Bayesian network model and evidence.
    double
    getMarginal(int node, int category)
    Computes the marginal probability of a specific variable (node) being in a given category within the current Bayesian network model after accounting for evidence.
    void
    setAllowedCategories(Proposition allowedCategories)
    Sets the allowed categories for variables in the Bayesian network by applying the given Proposition.

    Methods inherited from class Object

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

    • JunctionTreeInference

      public JunctionTreeInference(BayesIm bayesIm)
      Constructs a JunctionTreeInference object for performing inference on a Bayesian network represented by the given BayesIm (Bayesian network model interface). This constructor initializes the necessary data structures, builds the junction tree, and assigns conditional probability table (CPT) factors to the cliques.
      Parameters:
      bayesIm - The Bayesian network model interface (BayesIm) containing the structure, variables, and conditional probability tables of the Bayesian network. Must not be null.
      Throws:
      NullPointerException - If the provided bayesIm parameter is null.
  • Method Details

    • setAllowedCategories

      public void setAllowedCategories(Proposition allowedCategories)
      Sets the allowed categories for variables in the Bayesian network by applying the given Proposition. This method updates the internal mask that specifies which categories are considered valid for each variable and reinitializes the calibration process as needed.
      Parameters:
      allowedCategories - The Proposition object defining the allowed categories for the variables. Must not be null. If null, a NullPointerException will be thrown.
    • getMarginal

      public double getMarginal(int node, int category)
      Computes the marginal probability of a specific variable (node) being in a given category within the current Bayesian network model after accounting for evidence. This method requires the network to be calibrated and ensures appropriate evidence processing.
      Parameters:
      node - The variable index for which the marginal probability is being computed. Must be in the range [0, n), where n is the total number of variables.
      category - The specific category index of the variable. Must be in the range [0, card[node]), where card[node] represents the number of categories available for the given variable.
      Returns:
      The marginal probability of the specified variable being in the given category as a double value. If the calculation cannot be performed due to invalid evidence or other issues, returns Double.NaN.
      Throws:
      IllegalArgumentException - If the node or category index is out of the allowable range.
    • getConditional

      public double[] getConditional(int node, int[] parents, int[] parentValues)
      Computes the conditional probability distribution of a given node (variable) conditioned on its parent variables and their specified values within a Bayesian network. This method ensures the network is calibrated before performing the computation.
      Parameters:
      node - The index of the node (variable) whose conditional probability distribution is being computed. Must be in the range [0, n), where n is the total number of variables.
      parents - An array of indices representing the parent variables of the node. Each index must be in the range [0, n).
      parentValues - An array of values corresponding to the parents, specifying the state of each parent. Each value at index i must be in the range [0, card[parent[i]]), where card[parent[i]] is the cardinality of the parent variable.
      Returns:
      A double array representing the conditional probability distribution of the node, normalized to sum to 1. If there is no valid probability distribution (e.g., due to invalid inputs or evidence), the returned array will contain NaN values.
      Throws:
      NullPointerException - If the parents or parentValues parameter is null.
      IllegalArgumentException - If the lengths of parents and parentValues do not match, if node or any parent index is out of range, or if any parent value is out of the allowable range for the respective parent variable.
    • getJointProbability

      public double getJointProbability(int[] vars, int[] values)
      Computes the joint probability of a set of variables being in specified states according to the current Bayesian network model and evidence. This method ensures the network is calibrated and performs the necessary factor marginalization or retrieval based on the given variables and their values.
      Parameters:
      vars - An array of variable indices whose joint probability is to be computed. Each index must be in the range [0, n), where n is the total number of variables in the Bayesian network.
      values - An array of values corresponding to the specified variables. Each value at index i must be in the range [0, card[vars[i]]), where card[vars[i]] is the cardinality of the variable at index vars[i].
      Returns:
      The joint probability of the specified variables being in the given states as a double value. Returns Double.NaN if the calculation cannot be performed, such as when evidence conflicts with the specified states or due to invalid inputs.
      Throws:
      NullPointerException - If the vars or values parameter is null.
      IllegalArgumentException - If the lengths of vars and values do not match.