public CategoricalDistribution eliminationAsk(RandomVariable[] X,
AssignmentProposition[] e, BayesianNetwork bn)
{
Set<RandomVariable> hidden = new Set<RandomVariable>();
List<RandomVariable> VARS = new List<RandomVariable>();
calculateVariables(X, e, bn, hidden, VARS);
// factors <- []
List<Factor> factors = new List<Factor>();
// for each var in ORDER(bn.VARS) do
foreach (RandomVariable var in order(bn, VARS))
{
// factors <- [MAKE-FACTOR(var, e) | factors]
factors.Add(0, makeFactor(var, e, bn));
// if var is hidden variable then factors <- SUM-OUT(var, factors)
if (hidden.Contains(var))
{
factors = sumOut(var, factors, bn);
}
}
// return NORMALIZE(POINTWISE-PRODUCT(factors))
Factor product = pointwiseProduct(factors);
// Note: Want to ensure the order of the product matches the
// query variables
return ((ProbabilityTable) product.pointwiseProductPOS(_identity, X))
.normalize();
}