use of IncrementalAnytimeExactBeliefPropagation.Model.Node.VariableNode in project aic-expresso by aic-sri-international.
the class IncrementalAnytimeBeliefPropagationWithSeparatorConditioning method factorMessage.
private Bound factorMessage(PartitionTree partitionInAFactorNode, Set<VariableNode> SeparatorVariablesOnLevelAbove) {
if (!partitionInAFactorNode.node.isFactor()) {
println("error in S-BP!!!");
return null;
}
PairOf<Set<VariableNode>> sep = computeSeparatorOnThisLevelAndSeparatorOnLevelsBelow(partitionInAFactorNode, SeparatorVariablesOnLevelAbove);
Set<VariableNode> SeparatorOnThisLevel = sep.first;
Set<VariableNode> SeparatorForNextLevels = sep.second;
// calling children partitions. for each partition, call message passing,
// store VariableNode (we are going to sum them all out) and
// store bound
Bound[] boundsOfChildrenMessages = new Bound[partitionInAFactorNode.children.size()];
Set<Expression> variablesToSumOut = new HashSet<>();
for (VariableNode v : SeparatorOnThisLevel) {
variablesToSumOut.add(v.getValue());
}
int i = 0;
for (PartitionTree p : partitionInAFactorNode.children) {
Bound boundInP = variableMessage(p, SeparatorForNextLevels);
// Bound boundInP = p.node.getBound();
boundsOfChildrenMessages[i] = boundInP;
variablesToSumOut.add(p.node.getValue());
i++;
}
for (VariableNode v : SeparatorVariablesOnLevelAbove) {
variablesToSumOut.remove(v.getValue());
}
Bound bound = Bounds.boundProduct(model.getTheory(), model.getContext(), model.isExtensional(), boundsOfChildrenMessages);
ArrayList<Expression> varToSumOutList = new ArrayList<>();
varToSumOutList.addAll(variablesToSumOut);
Expression varToSumOut = new DefaultExtensionalMultiSet(varToSumOutList);
bound = bound.summingPhiTimesBound(varToSumOut, partitionInAFactorNode.node.getValue(), model.getContext(), model.getTheory());
return bound;
// partitionInAFactorNode.node.setBound(bound);
}
use of IncrementalAnytimeExactBeliefPropagation.Model.Node.VariableNode in project aic-expresso by aic-sri-international.
the class IncrementalAnytimeBeliefPropagationWithSeparatorConditioning method inference.
public Bound inference() {
VariableNode query = model.getQuery();
this.partitionTree = new PartitionTree(query, model);
allNodesAreExplored = model.allNodesAreExplored();
Bound result = variableMessage(partitionTree, new HashSet<VariableNode>());
return result;
}
use of IncrementalAnytimeExactBeliefPropagation.Model.Node.VariableNode in project aic-expresso by aic-sri-international.
the class IncrementalAnytimeBeliefPropagationWithSeparatorConditioning method computeSeparator.
/**
* Given the partition, compute the separator. TODO more efficient implementation
* @param p
* @return
*/
private Set<VariableNode> computeSeparator(PartitionTree pTree) {
// Create sets with the variables in each partition
List<Set<VariableNode>> VariablePartition = new ArrayList<Set<VariableNode>>();
for (PartitionTree p : pTree.children) {
Set<VariableNode> variablesOfP = new HashSet<>();
for (FactorNode phi : p.setOfFactors) {
Collection<VariableNode> VarsOfPhi = model.getExploredGraph().getAsOfB(phi);
variablesOfP.addAll(VarsOfPhi);
}
VariablePartition.add(variablesOfP);
}
// take the variables that compose the intersection of those sets
Set<VariableNode> separatorVariables = new HashSet<>();
for (int i = 0; i < VariablePartition.size(); i++) {
for (int j = i + 1; j < VariablePartition.size(); j++) {
Set<VariableNode> intersectionAti = new HashSet<>();
intersectionAti.addAll(VariablePartition.get(i));
intersectionAti.retainAll(VariablePartition.get(j));
separatorVariables.addAll(intersectionAti);
}
}
return separatorVariables;
}
use of IncrementalAnytimeExactBeliefPropagation.Model.Node.VariableNode in project aic-expresso by aic-sri-international.
the class IncrementalAnytimeBeliefPropagationWithSeparatorConditioning method variableMessage.
private Bound variableMessage(PartitionTree currentNode) {
Set<Expression> variablesToSumOut = new HashSet<>();
for (VariableNode v : currentNode.separator) {
variablesToSumOut.add(v.getValue());
}
Bound[] boundsOfChildrenMessages = new Bound[currentNode.children.size()];
int i = 0;
for (PartitionTree p : currentNode.children) {
Bound boundInP = p.node.getBound();
boundsOfChildrenMessages[i] = boundInP;
i++;
}
Bound bound = Bounds.boundProduct(model.getTheory(), model.getContext(), model.isExtensional(), boundsOfChildrenMessages);
ArrayList<Expression> varToSumOutList = new ArrayList<>();
varToSumOutList.addAll(variablesToSumOut);
Expression varToSumOut = new DefaultExtensionalMultiSet(varToSumOutList);
bound = bound.summingBound(varToSumOut, model.getContext(), model.getTheory());
return bound;
}
use of IncrementalAnytimeExactBeliefPropagation.Model.Node.VariableNode in project aic-expresso by aic-sri-international.
the class IncrementalAnytimeBeliefPropagationWithSeparatorConditioning method factorMessage.
private Bound factorMessage(PartitionTree currentNode) {
Set<Expression> variablesToSumOut = new HashSet<>();
for (VariableNode v : currentNode.separator) {
variablesToSumOut.add(v.getValue());
}
Bound[] boundsOfChildrenMessages = new Bound[currentNode.children.size()];
int i = 0;
for (PartitionTree p : currentNode.children) {
Bound boundInP = p.node.getBound();
boundsOfChildrenMessages[i] = boundInP;
variablesToSumOut.add(p.node.getValue());
i++;
}
for (VariableNode v : currentNode.cutsetOfAllLevelsAbove) {
variablesToSumOut.remove(v.getValue());
}
Bound bound = Bounds.boundProduct(model.getTheory(), model.getContext(), model.isExtensional(), boundsOfChildrenMessages);
ArrayList<Expression> varToSumOutList = new ArrayList<>();
varToSumOutList.addAll(variablesToSumOut);
Expression varToSumOut = new DefaultExtensionalMultiSet(varToSumOutList);
bound = bound.summingPhiTimesBound(varToSumOut, currentNode.node.getValue(), model.getContext(), model.getTheory());
return bound;
}
Aggregations