// if EMPTY?(vars) then return 1.0
if (0 == vars.size()) {
return 1;
}
// Y <- FIRST(vars)
RandomVariable Y = Util.first(vars);
// if Y has value y in e
if (e.containsValue(Y)) {
// then return P(y | parents(Y)) * ENUMERATE-ALL(REST(vars), e)
return e.posteriorForParents(Y) * enumerateAll(Util.rest(vars), e);
}
/**
* <pre>
* else return ∑<sub>y</sub> P(y | parents(Y)) * ENUMERATE-ALL(REST(vars), e<sub>y</sub>)
* where e<sub>y</sub> is e extended with Y = y
* </pre>
*/
double sum = 0;
for (Object y : ((FiniteDomain) Y.getDomain()).getPossibleValues()) {
e.setExtendedValue(Y, y);
sum += e.posteriorForParents(Y) * enumerateAll(Util.rest(vars), e);
}
return sum;