public ProbabilityTable pointwiseProductPOS(
ProbabilityTable multiplier, params RandomVariable[] prodVarOrder)
{
ProbabilityTable product = new ProbabilityTable(prodVarOrder);
if (!product.randomVarInfo.keySet().Equals(
SetOps.union(new List <RandomVariable>(randomVarInfo.keySet()),
new List <RandomVariable>(multiplier.randomVarInfo
.keySet()))))
{
if (1 == product.getValues().Length)
{
product.getValues()[0] = getValues()[0] * multiplier.getValues()[0];
}
else
{
// Otherwise need to iterate through the product
// to calculate its values based on the terms.
Object[] term1Values = new Object[randomVarInfo.size()];
Object[] term2Values = new Object[multiplier.randomVarInfo
.size()];
//ProbabilityTable.Iterator di = new ProbabilityTable.Iterator() {
// private int idx = 0;
// public void iterate(Map<RandomVariable, Object> possibleWorld,
// double probability) {
// int term1Idx = termIdx(term1Values, ProbabilityTable.this,
// possibleWorld);
// int term2Idx = termIdx(term2Values, multiplier,
// possibleWorld);
// product.getValues()[idx] = getValues()[term1Idx]
// * multiplier.getValues()[term2Idx];
// idx++;
// }
// private int termIdx(Object[] termValues, ProbabilityTable d,
// Map<RandomVariable, Object> possibleWorld) {
// if (0 == termValues.Length) {
// // The term has no variables so always position 0.
// return 0;
// }
// int i = 0;
// for (RandomVariable rv : d.randomVarInfo.keySet()) {
// termValues[i] = possibleWorld.get(rv);
// i++;
// }
// return d.getIndex(termValues);
// }
//};
//product.iterateOverTable(di);
// TODO
}
}
return(product);
}