Search in sources :

Example 11 with VariableNode

use of anytimeExactBeliefPropagation.Model.Node.VariableNode in project aic-expresso by aic-sri-international.

the class PartitionTree method updateSetsOfVariables.

public void updateSetsOfVariables() {
    VariableNode newVariable = (VariableNode) this.node;
    this.setOfVariablesInsidePartition.add(newVariable);
    if (this.parent != null) {
        this.parent.updateSetsOfVariables();
    }
}
Also used : VariableNode(anytimeExactBeliefPropagation.Model.Node.VariableNode)

Example 12 with VariableNode

use of anytimeExactBeliefPropagation.Model.Node.VariableNode 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(anytimeExactBeliefPropagation.Model.Node.VariableNode) HashMap(java.util.HashMap) VariableNode(anytimeExactBeliefPropagation.Model.Node.VariableNode) Node(anytimeExactBeliefPropagation.Model.Node.Node) FactorNode(anytimeExactBeliefPropagation.Model.Node.FactorNode) LinkedList(java.util.LinkedList) FactorNode(anytimeExactBeliefPropagation.Model.Node.FactorNode) HashSet(java.util.HashSet)

Example 13 with VariableNode

use of anytimeExactBeliefPropagation.Model.Node.VariableNode in project aic-expresso by aic-sri-international.

the class PartitionTree method updateCutSet2.

/*------------------------------------------------------------------------------------------------------------------------*/
// Alternative iplementation of updating cutset:
@SuppressWarnings("unused")
private void updateCutSet2(Model m) {
    FactorNode factor = (FactorNode) this.node;
    // we take all variables of this factor, and remove those that haven't appeared in other parts of the graph
    Collection<VariableNode> newSeparatorVariables = m.getVariablesOfAFactor(factor);
    newSeparatorVariables.removeAll(this.children);
    newSeparatorVariables.remove(this.parent);
    // Update cutset of "Virgin Variables"
    // TODO
    // Update this cutset, and all above together
    addingToCutSet(newSeparatorVariables, null);
}
Also used : VariableNode(anytimeExactBeliefPropagation.Model.Node.VariableNode) FactorNode(anytimeExactBeliefPropagation.Model.Node.FactorNode)

Aggregations

VariableNode (anytimeExactBeliefPropagation.Model.Node.VariableNode)13 FactorNode (anytimeExactBeliefPropagation.Model.Node.FactorNode)7 Expression (com.sri.ai.expresso.api.Expression)5 HashSet (java.util.HashSet)5 DefaultExtensionalMultiSet (com.sri.ai.expresso.core.DefaultExtensionalMultiSet)3 Bound (com.sri.ai.grinder.library.bounds.Bound)3 ArrayList (java.util.ArrayList)3 Set (java.util.Set)3 Node (anytimeExactBeliefPropagation.Model.Node.Node)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1