Class CptInvariantUpdater

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

public final class CptInvariantUpdater extends Object implements ManipulatingBayesUpdater
Calculates updated probabilities for variables conditional on their parents as well as single-variable updated marginals for a Bayes IM using an algorithm that restricts expensive updating summations only to conditional probabilities of variables with respect to their parents that change from non-updated to updated values.
Version:
$Id: $Id
Author:
josephramsey
See Also:
  • Constructor Details

    • CptInvariantUpdater

      public CptInvariantUpdater(BayesIm bayesIm)

      Constructor for CptInvariantUpdater.

      Parameters:
      bayesIm - a BayesIm object
    • CptInvariantUpdater

      public CptInvariantUpdater(BayesIm bayesIm, Evidence evidence)
      Constructs a new updater for the given Bayes net.
      Parameters:
      bayesIm - a BayesIm object
      evidence - a Evidence object
  • Method Details

    • serializableInstance

      public static CptInvariantUpdater serializableInstance()
      Generates a simple exemplar of this class to test serialization.
      Returns:
      a CptInvariantUpdater object
    • getBayesIm

      public BayesIm getBayesIm()

      Getter for the field bayesIm.

      Specified by:
      getBayesIm in interface BayesUpdater
      Returns:
      a BayesIm object
    • getManipulatedBayesIm

      public BayesIm getManipulatedBayesIm()

      Getter for the field manipulatedBayesIm.

      Specified by:
      getManipulatedBayesIm in interface ManipulatingBayesUpdater
      Returns:
      a BayesIm object
    • getManipulatedGraph

      public Graph getManipulatedGraph()

      getManipulatedGraph.

      Specified by:
      getManipulatedGraph in interface ManipulatingBayesUpdater
      Returns:
      a Graph object
    • getUpdatedBayesIm

      public BayesIm getUpdatedBayesIm()

      Getter for the field updatedBayesIm.

      Specified by:
      getUpdatedBayesIm in interface ManipulatingBayesUpdater
      Returns:
      a BayesIm object
    • getEvidence

      public Evidence getEvidence()

      Getter for the field evidence.

      Specified by:
      getEvidence in interface ManipulatingBayesUpdater
      Returns:
      a Evidence object
    • setEvidence

      public void setEvidence(Evidence evidence)
      Sets new evidence for the updater. Once this is called, old updating results should not longer be available.

      Sets new evidence for the updater. Once this is called, old updating results should not longer be available.

      Specified by:
      setEvidence in interface BayesUpdater
      Specified by:
      setEvidence in interface ManipulatingBayesUpdater
      Parameters:
      evidence - evidence
    • getMarginal

      public double getMarginal(int variable, int value)
      Returns the marginal probability of the given variable taking the given value, given the evidence.

      Returns the updated graph. This is the graph in which all probabilities of variables conditional on their parents have been updated.

      Specified by:
      getMarginal in interface BayesUpdater
      Specified by:
      getMarginal in interface ManipulatingBayesUpdater
      Parameters:
      variable - variable index
      value - category index
      Returns:
      P(variable = value | evidence), where evidence is getEvidence().
    • isJointMarginalSupported

      public boolean isJointMarginalSupported()

      isJointMarginalSupported.

      Specified by:
      isJointMarginalSupported in interface BayesUpdater
      Returns:
      a boolean
    • getJointMarginal

      public double getJointMarginal(int[] variables, int[] values)

      getJointMarginal.

      Specified by:
      getJointMarginal in interface BayesUpdater
      Parameters:
      variables - an array of int objects
      values - an array of int objects
      Returns:
      a double
    • calculatePriorMarginals

      public double[] calculatePriorMarginals(int nodeIndex)
      Calculates the prior marginal probabilities of the given node.
      Specified by:
      calculatePriorMarginals in interface BayesUpdater
      Parameters:
      nodeIndex - node index
      Returns:
      P(node = value), where value is the value of the node in the Bayes net.
    • calculateUpdatedMarginals

      public double[] calculateUpdatedMarginals(int nodeIndex)
      Calculates the updated marginal probabilities of the given node, given the evidence.
      Specified by:
      calculateUpdatedMarginals in interface BayesUpdater
      Parameters:
      nodeIndex - node index
      Returns:
      P(node = value | evidence), where value is the value of the node in the Bayes net.
    • toString

      public String toString()
      Prints out the most recent marginal.
      Overrides:
      toString in class Object
      Returns:
      a String object