public class LikelihoodWeighting extends java.lang.Object implements BayesSampleInference
function LIKELIHOOD-WEIGHTING(X, e, bn, N) returns an estimate of P(X|e)
inputs: X, the query variable
e, observed values for variables E
bn, a Bayesian network specifying joint distribution P(X1,...,Xn)
N, the total number of samples to be generated
local variables: W, a vector of weighted counts for each value of X, initially zero
for j = 1 to N do
x,w <- WEIGHTED-SAMPLE(bn,e)
W[x] <- W[x] + w where x is the value of X in x
return NORMALIZE(W)
--------------------------------------------------------------------------------------
function WEIGHTED-SAMPLE(bn, e) returns an event and a weight
w <- 1; x <- an event with n elements initialized from e
foreach variable Xi in X1,...,Xn do
if Xi is an evidence variable with value xi in e
then w <- w * P(Xi = xi | parents(Xi))
else x[i] <- a random sample from P(Xi | parents(Xi))
return x, w
Figure 14.15 The likelihood-weighting algorithm for inference in Bayesian
networks. In WEIGHTED-SAMPLE, each nonevidence variable is sampled according
to the conditional distribution given the values already sampled for the
variable's parents, while a weight is accumulated based on the likelihood for
each evidence variable.| Constructor and Description |
|---|
LikelihoodWeighting() |
LikelihoodWeighting(Randomizer r) |
| Modifier and Type | Method and Description |
|---|---|
CategoricalDistribution |
ask(RandomVariable[] X,
AssignmentProposition[] observedEvidence,
BayesianNetwork bn,
int N) |
CategoricalDistribution |
likelihoodWeighting(RandomVariable[] X,
AssignmentProposition[] e,
BayesianNetwork bn,
int N)
The LIKELIHOOD-WEIGHTING algorithm in Figure 14.15.
|
Pair<java.util.Map<RandomVariable,java.lang.Object>,java.lang.Double> |
weightedSample(BayesianNetwork bn,
AssignmentProposition[] e)
The WEIGHTED-SAMPLE function in Figure 14.15.
|
public LikelihoodWeighting()
public LikelihoodWeighting(Randomizer r)
public CategoricalDistribution likelihoodWeighting(RandomVariable[] X, AssignmentProposition[] e, BayesianNetwork bn, int N)
X - the query variablese - observed values for variables Ebn - a Bayesian network specifying joint distribution
P(X1,...,Xn)N - the total number of samples to be generatedpublic Pair<java.util.Map<RandomVariable,java.lang.Object>,java.lang.Double> weightedSample(BayesianNetwork bn, AssignmentProposition[] e)
e - observed values for variables Ebn - a Bayesian network specifying joint distribution
P(X1,...,Xn)public CategoricalDistribution ask(RandomVariable[] X, AssignmentProposition[] observedEvidence, BayesianNetwork bn, int N)
ask in interface BayesSampleInferenceX - the query variables.observedEvidence - observed values for variables E.bn - a Bayes net with variables {X} ∪ E ∪ Y /* Y = hidden
variablesN - the total number of samples to be generated