use of IncrementalAnytimeExactBeliefPropagation.Model.Node.VariableNode in project aic-expresso by aic-sri-international.
the class BFS method next.
@Override
public PartitionTree next() {
if (first) {
first = false;
return this.partitionQuery;
}
if (!hasNext())
throw new NoSuchElementException();
// removes from front of queue
FactorNode nextFactor = queue.remove();
PartitionTree nextFactorPartition = fromNodeToPartition.get(nextFactor);
for (VariableNode neighborVariable : graph.getAsOfB(nextFactor)) {
PartitionTree neighborVariablePartition = fromNodeToPartition.get(neighborVariable);
if (neighborVariablePartition == null) {
neighborVariablePartition = new PartitionTree(neighborVariable, nextFactorPartition);
fromNodeToPartition.put(neighborVariable, neighborVariablePartition);
}
for (FactorNode neighborFactor : graph.getBsOfA(neighborVariable)) {
if (!visited.contains(neighborFactor)) {
PartitionTree neighborFactorPartition = new PartitionTree(neighborFactor, neighborVariablePartition);
fromNodeToPartition.put(neighborFactor, neighborFactorPartition);
queue.add(neighborFactor);
visited.add(neighborFactor);
}
}
}
return nextFactorPartition;
}
use of IncrementalAnytimeExactBeliefPropagation.Model.Node.VariableNode in project aic-expresso by aic-sri-international.
the class Model method ExpandModel.
public void ExpandModel(FactorNode newFactorNode) {
// BFS, DFS,...
for (Expression variable : Expressions.freeVariables(newFactorNode.getValue(), context)) {
VariableNode v = new VariableNode(variable, isExtensional, theory, context);
exploredGraphicalModel.add(v, newFactorNode);
}
}
use of IncrementalAnytimeExactBeliefPropagation.Model.Node.VariableNode in project aic-expresso by aic-sri-international.
the class IncrementalAnytimeBeliefPropagationWithSeparatorConditioning method variableMessage.
private Bound variableMessage(PartitionTree partitionInAVariableNode, Set<VariableNode> SeparatorVariablesOnLevelAbove) {
// or notToSumVariables
if (!partitionInAVariableNode.node.isVariable()) {
println("error in S-BP!!!");
return null;
}
PairOf<Set<VariableNode>> sep = computeSeparatorOnThisLevelAndSeparatorOnLevelsBelow(partitionInAVariableNode, SeparatorVariablesOnLevelAbove);
Set<VariableNode> SeparatorOnThisLevel = sep.first;
Set<VariableNode> SeparatorForNextLevels = sep.second;
// calling children partitions. for each partition, call message passing,
// store bound
Bound[] boundsOfChildrenMessages = new Bound[partitionInAVariableNode.children.size()];
Set<Expression> variablesToSumOut = new HashSet<>();
for (VariableNode v : SeparatorOnThisLevel) {
variablesToSumOut.add(v.getValue());
}
// obs. it can be equivalently thought as attaching a "simplex factor" to non exhausted nodes.
if (!allNodesAreExplored && !model.isExhausted((VariableNode) partitionInAVariableNode.node)) {
Expression var = partitionInAVariableNode.node.getValue();
Bound bound = Bounds.simplex(arrayList(var), model.getTheory(), model.getContext(), model.isExtensional());
// partitionInAVariableNode.node.setBound(bound);
return bound;
}
int i = 0;
for (PartitionTree p : partitionInAVariableNode.children) {
Bound boundInP = factorMessage(p, SeparatorForNextLevels);
// 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;
// partitionInAVariableNode.node.setBound(bound);
}
use of IncrementalAnytimeExactBeliefPropagation.Model.Node.VariableNode in project aic-expresso by aic-sri-international.
the class IncrementalAnytimeBeliefPropagationWithSeparatorConditioning method updatePartitionTree.
private void updatePartitionTree(PartitionTree p) {
FactorNode newFactor = (FactorNode) p.node;
Collection<VariableNode> variablesOfNewFactor = model.getVariablesOfAFactor(newFactor);
updateSetOfFactorsInPartitionTree(p, newFactor);
updateSetOfVariablesInPartitionTree(p, variablesOfNewFactor);
updateCutSet(p, newFactor);
updateBounds();
}
use of IncrementalAnytimeExactBeliefPropagation.Model.Node.VariableNode in project aic-expresso by aic-sri-international.
the class Model method ExpandModel.
/**
* This method receives as input an {@code Iterator<FactorNode>} object and expands the
* {@code exploredGraphicalModel} by adding ONE FACTOR to it.
*
* There are various ways of doing such expansion, and it is then given to the User the
* choice on which way to go.
*
* @param it
*/
public void ExpandModel(Iterator<FactorNode> it) {
// BFS, DFS,...
if (it.hasNext()) {
FactorNode newFactorNode = it.next();
for (Expression variable : Expressions.freeVariables(newFactorNode.getValue(), context)) {
VariableNode v = new VariableNode(variable, isExtensional, theory, context);
exploredGraphicalModel.add(v, newFactorNode);
}
}
}
Aggregations