Search in sources :

Example 6 with VariableNode

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;
}
Also used : PartitionTree(IncrementalAnytimeExactBeliefPropagation.PartitionTree) VariableNode(IncrementalAnytimeExactBeliefPropagation.Model.Node.VariableNode) NoSuchElementException(java.util.NoSuchElementException) FactorNode(IncrementalAnytimeExactBeliefPropagation.Model.Node.FactorNode)

Example 7 with VariableNode

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);
    }
}
Also used : VariableNode(IncrementalAnytimeExactBeliefPropagation.Model.Node.VariableNode) Expression(com.sri.ai.expresso.api.Expression)

Example 8 with VariableNode

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);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) DefaultExtensionalMultiSet(com.sri.ai.expresso.core.DefaultExtensionalMultiSet) Bound(com.sri.ai.grinder.library.bounds.Bound) ArrayList(java.util.ArrayList) DefaultExtensionalMultiSet(com.sri.ai.expresso.core.DefaultExtensionalMultiSet) VariableNode(IncrementalAnytimeExactBeliefPropagation.Model.Node.VariableNode) Expression(com.sri.ai.expresso.api.Expression) HashSet(java.util.HashSet)

Example 9 with VariableNode

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();
}
Also used : VariableNode(IncrementalAnytimeExactBeliefPropagation.Model.Node.VariableNode) FactorNode(IncrementalAnytimeExactBeliefPropagation.Model.Node.FactorNode)

Example 10 with VariableNode

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);
        }
    }
}
Also used : VariableNode(IncrementalAnytimeExactBeliefPropagation.Model.Node.VariableNode) Expression(com.sri.ai.expresso.api.Expression) FactorNode(IncrementalAnytimeExactBeliefPropagation.Model.Node.FactorNode)

Aggregations

VariableNode (IncrementalAnytimeExactBeliefPropagation.Model.Node.VariableNode)11 Expression (com.sri.ai.expresso.api.Expression)6 HashSet (java.util.HashSet)6 FactorNode (IncrementalAnytimeExactBeliefPropagation.Model.Node.FactorNode)5 DefaultExtensionalMultiSet (com.sri.ai.expresso.core.DefaultExtensionalMultiSet)5 Bound (com.sri.ai.grinder.library.bounds.Bound)5 ArrayList (java.util.ArrayList)5 Set (java.util.Set)3 Node (IncrementalAnytimeExactBeliefPropagation.Model.Node.Node)1 PartitionTree (IncrementalAnytimeExactBeliefPropagation.PartitionTree)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 NoSuchElementException (java.util.NoSuchElementException)1