Class ApproximateUpdater

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

public final class ApproximateUpdater extends Object implements ManipulatingBayesUpdater
Calculates updated marginals for a Bayes net by simulating data and calculating likelihood ratios. The method is as follows. For P(A | B), enough sample points are simulated from the underlying BayesIm so that 1000 satisfy the condition B. Then the maximum likelihood estimate of condition A is calculated.
Version:
$Id: $Id
Author:
josephramsey
See Also:
  • Constructor Details

    • ApproximateUpdater

      public ApproximateUpdater(BayesIm bayesIm)
      Constructs a new updater for the given Bayes net.
      Parameters:
      bayesIm - the Bayes net to be updated.
    • ApproximateUpdater

      public ApproximateUpdater(BayesIm bayesIm, Evidence evidence)
      Constructs a new updater for the given Bayes net.
      Parameters:
      bayesIm - the Bayes net to be updated.
      evidence - the evidence for the update.
  • Method Details

    • serializableInstance

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

      public BayesIm getBayesIm()

      Getter for the field bayesIm.

      Specified by:
      getBayesIm in interface BayesUpdater
      Returns:
      the Bayes instantiated model that is being updated.
    • getManipulatedBayesIm

      public BayesIm getManipulatedBayesIm()

      Getter for the field manipulatedBayesIm.

      Specified by:
      getManipulatedBayesIm in interface ManipulatingBayesUpdater
      Returns:
      the Bayes instantiated model after manipulations have been applied.
    • getManipulatedGraph

      public Graph getManipulatedGraph()

      getManipulatedGraph.

      Specified by:
      getManipulatedGraph in interface ManipulatingBayesUpdater
      Returns:
      the graph for getManipulatedBayesIm().
    • getUpdatedBayesIm

      public BayesIm getUpdatedBayesIm()

      getUpdatedBayesIm.

      Specified by:
      getUpdatedBayesIm in interface ManipulatingBayesUpdater
      Returns:
      the updated Bayes IM, or null if there is no updated Bayes IM.
    • getEvidence

      public Evidence getEvidence()

      Getter for the field evidence.

      Specified by:
      getEvidence in interface ManipulatingBayesUpdater
      Returns:
      a copy of the getModel evidence.
    • 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.

      Sets new evidence for the next update operation.

      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:
      the joint marginal.
    • 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