Search in sources :

Example 6 with FactorNode

use of IncrementalAnytimeExactBeliefPropagation.Model.Node.FactorNode 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 7 with FactorNode

use of IncrementalAnytimeExactBeliefPropagation.Model.Node.FactorNode 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)

Example 8 with FactorNode

use of IncrementalAnytimeExactBeliefPropagation.Model.Node.FactorNode in project aic-expresso by aic-sri-international.

the class PartitionTree method createPartitionTreeWithBFS.

/*------------------------------------------------------------------------------------------------------------------------*/
/**
 * This class creates a partition based on a BFS process.
 *
 * There are various ways to create the partition tree.
 *
 * In fact any partition tree will provide an exact inference. But some of them will
 * generate so many separator variables (or cutset variables) that the inference time
 * can be close to the Naive computation.
 *
 * The study of the complexity of choosing the optimal tree (or a good heuristic)
 * still needs to be done in the project. (TODO)
 *
 * The choice of a BFS seems intuitively good because it distributes the nodes more or less
 * evenly among the partitions
 *
 * @param model
 */
public void createPartitionTreeWithBFS(Model model) {
    HashMap<Node, PartitionTree> hashTable = new HashMap<>();
    Set<Node> visited = new HashSet<>();
    Queue<Node> queue = new LinkedList<>();
    visited.add(node);
    queue.add(node);
    hashTable.put(this.node, this);
    while (!queue.isEmpty()) {
        Node n = queue.remove();
        PartitionTree parentPartition = hashTable.get(n);
        Set<Node> neighbors = new HashSet<>();
        if (n.isFactor()) {
            Collection<VariableNode> variableNeighbors = model.getExploredGraph().getAsOfB((FactorNode) n);
            neighbors.addAll(variableNeighbors);
        } else {
            Collection<FactorNode> factorNeighbors = model.getExploredGraph().getBsOfA((VariableNode) n);
            neighbors.addAll(factorNeighbors);
        }
        for (Node neighbor : neighbors) {
            if (!visited.contains(neighbor)) {
                queue.add(neighbor);
                visited.add(neighbor);
                PartitionTree pChild = new PartitionTree(neighbor);
                pChild.parent = parentPartition;
                hashTable.put(neighbor, pChild);
                parentPartition.children.add(pChild);
            }
        }
    }
}
Also used : VariableNode(IncrementalAnytimeExactBeliefPropagation.Model.Node.VariableNode) HashMap(java.util.HashMap) Node(IncrementalAnytimeExactBeliefPropagation.Model.Node.Node) FactorNode(IncrementalAnytimeExactBeliefPropagation.Model.Node.FactorNode) VariableNode(IncrementalAnytimeExactBeliefPropagation.Model.Node.VariableNode) LinkedList(java.util.LinkedList) FactorNode(IncrementalAnytimeExactBeliefPropagation.Model.Node.FactorNode) HashSet(java.util.HashSet)

Aggregations

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