Esempio n. 1
0
 protected void compute(int[] varsToSumOver, int i, int[] nodeDomainIndices, MutableDouble sum) {
   if (i == varsToSumOver.length) {
     double result = 1.0;
     for (BeliefNode node : cpts) result *= getCPTProbability(node, nodeDomainIndices);
     for (MessageFunction h : childFunctions) result *= h.compute(nodeDomainIndices);
     sum.value += result;
     return;
   }
   int idxVar = varsToSumOver[i];
   for (int v = 0; v < nodes[idxVar].getDomain().getOrder(); v++) {
     nodeDomainIndices[idxVar] = v;
     compute(varsToSumOver, i + 1, nodeDomainIndices, sum);
   }
 }
Esempio n. 2
0
 protected void computeSum(
     int i,
     BeliefNode[] varsToSumOver,
     BeliefNode excludedNode,
     Cluster u,
     int[] nodeDomainIndices,
     MutableDouble result) {
   if (i == varsToSumOver.length) {
     result.value += u.product(nodeDomainIndices);
     return;
   }
   if (varsToSumOver[i] == excludedNode)
     computeSum(i + 1, varsToSumOver, excludedNode, u, nodeDomainIndices, result);
   else {
     for (int j = 0; j < varsToSumOver[i].getDomain().getOrder(); j++) {
       nodeDomainIndices[this.getNodeIndex(varsToSumOver[i])] = j;
       computeSum(i + 1, varsToSumOver, excludedNode, u, nodeDomainIndices, result);
     }
   }
 }