Package edu.cmu.tetrad.bayes
Class ApproximateUpdater
java.lang.Object
edu.cmu.tetrad.bayes.ApproximateUpdater
- All Implemented Interfaces:
BayesUpdater
,ManipulatingBayesUpdater
,TetradSerializable
,Serializable
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.
- Author:
- josephramsey
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionApproximateUpdater
(BayesIm bayesIm) Constructs a new updater for the given Bayes net.ApproximateUpdater
(BayesIm bayesIm, Evidence evidence) Constructs a new updater for the given Bayes net. -
Method Summary
Modifier and TypeMethodDescriptiondouble[]
calculatePriorMarginals
(int nodeIndex) Calculates the prior marginal probabilities of the given node.double[]
calculateUpdatedMarginals
(int nodeIndex) Calculates the updated marginal probabilities of the given node, given the evidence.Returns the evidence for the updater.Returns the manipulation that was used to manipulate the Bayes IM.double
getJointMarginal
(int[] variables, int[] values) Returns the joint marginal probability of the given variables taking the given values, given the evidence.Returns the manipulated Bayes IM.Returns the manipulated graph.double
getMarginal
(int variable, int value) Returns the updated graph.Returns the updated Bayes IM.boolean
Returns the joint marginal probability of the given variables taking the given values, given the evidence.static ApproximateUpdater
Returns a simple exemplar of this class to test serialization.void
setEvidence
(Evidence evidence) Sets new evidence for the next update operation.toString()
Prints out the most recent marginal.
-
Constructor Details
-
ApproximateUpdater
Constructs a new updater for the given Bayes net.- Parameters:
bayesIm
- the Bayes net to be updated.
-
ApproximateUpdater
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
Returns a simple exemplar of this class to test serialization.- Returns:
- a simple exemplar of this class to test serialization.
-
getBayesIm
Description copied from interface:BayesUpdater
Returns the evidence for the updater.- Specified by:
getBayesIm
in interfaceBayesUpdater
- Returns:
- the Bayes instantiated model that is being updated.
-
getManipulatedBayesIm
Description copied from interface:ManipulatingBayesUpdater
Returns the manipulated Bayes IM. This is the Bayes IM in which the variables in the manipulation have been removed from the graph.- Specified by:
getManipulatedBayesIm
in interfaceManipulatingBayesUpdater
- Returns:
- the Bayes instantiated model after manipulations have been applied.
-
getManipulatedGraph
Description copied from interface:ManipulatingBayesUpdater
Returns the manipulated graph. This is the graph in which the variables in the manipulation have been removed from the graph.- Specified by:
getManipulatedGraph
in interfaceManipulatingBayesUpdater
- Returns:
- the graph for getManipulatedBayesIm().
-
getUpdatedBayesIm
Description copied from interface:ManipulatingBayesUpdater
Returns the updated Bayes IM. This is the Bayes IM in which all probabilities of variables conditional on their parents have been updated.- Specified by:
getUpdatedBayesIm
in interfaceManipulatingBayesUpdater
- Returns:
- the updated Bayes IM, or null if there is no updated Bayes IM.
-
getEvidence
Description copied from interface:ManipulatingBayesUpdater
Returns the manipulation that was used to manipulate the Bayes IM.- Specified by:
getEvidence
in interfaceManipulatingBayesUpdater
- Returns:
- a copy of the getModel evidence.
-
setEvidence
Sets new evidence for the next update operation.- Specified by:
setEvidence
in interfaceBayesUpdater
- Specified by:
setEvidence
in interfaceManipulatingBayesUpdater
- Parameters:
evidence
- the new evidence.
-
getMarginal
public double getMarginal(int variable, int value) Description copied from interface:ManipulatingBayesUpdater
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 interfaceBayesUpdater
- Specified by:
getMarginal
in interfaceManipulatingBayesUpdater
- Parameters:
variable
- variable indexvalue
- category index- Returns:
- P(variable = category | evidence) where evidence is getEvidence().
-
isJointMarginalSupported
public boolean isJointMarginalSupported()Description copied from interface:BayesUpdater
Returns the joint marginal probability of the given variables taking the given values, given the evidence.- Specified by:
isJointMarginalSupported
in interfaceBayesUpdater
- Returns:
- true if the getJointMarginal() method is supported.
-
getJointMarginal
public double getJointMarginal(int[] variables, int[] values) Description copied from interface:BayesUpdater
Returns the joint marginal probability of the given variables taking the given values, given the evidence.- Specified by:
getJointMarginal
in interfaceBayesUpdater
- Parameters:
variables
- variable indicesvalues
- category indices- Returns:
- the joint marginal.
-
calculatePriorMarginals
public double[] calculatePriorMarginals(int nodeIndex) Description copied from interface:BayesUpdater
Calculates the prior marginal probabilities of the given node.- Specified by:
calculatePriorMarginals
in interfaceBayesUpdater
- 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) Description copied from interface:BayesUpdater
Calculates the updated marginal probabilities of the given node, given the evidence.- Specified by:
calculateUpdatedMarginals
in interfaceBayesUpdater
- Parameters:
nodeIndex
- node index- Returns:
- P(node = value | evidence), where value is the value of the node in the Bayes net.
-
toString
Prints out the most recent marginal.
-