public CategoricalDistribution likelihoodWeighting(RandomVariable[] X,
AssignmentProposition[] e, BayesianNetwork bn, int N)
{
// local variables: W, a vector of weighted counts for each value of X,
// initially zero
double[] W = new double[ProbUtil
.expectedSizeOfCategoricalDistribution(X)];
// for j = 1 to N do
for (int j = 0; j < N; j++)
{
// <b>x</b>,w <- WEIGHTED-SAMPLE(bn,e)
Pair<Map<RandomVariable, Object>, Double> x_w = weightedSample(bn,
e);
// W[x] <- W[x] + w where x is the value of X in <b>x</b>
W[ProbUtil.indexOf(X, x_w.getFirst())] += x_w.getSecond();
}
// return NORMALIZE(W)
return new ProbabilityTable(W, X).normalize();
}