use of com.sri.ai.expresso.core.DefaultExtensionalMultiSet in project aic-expresso by aic-sri-international.
the class IncrementalBeliefPropagationWithConditioning method variableMessage.
public 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 (!AllExplored && !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 com.sri.ai.expresso.core.DefaultExtensionalMultiSet in project aic-expresso by aic-sri-international.
the class IncrementalBeliefPropagationWithConditioning method factorMessage.
public 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 com.sri.ai.expresso.core.DefaultExtensionalMultiSet in project aic-expresso by aic-sri-international.
the class ModelGenerator method LVECalculation.
public static Expression LVECalculation(Collection<FactorNode> factorNodes, Expression query, Context context, Theory theory) {
Set<Expression> factorExpressions = new HashSet<>();
for (FactorNode f : factorNodes) {
factorExpressions.add(f.getValue());
}
Expression product = apply(TIMES, factorExpressions);
Set<Expression> freevariables = Expressions.freeVariables(product, context);
freevariables.remove(query);
ArrayList<Expression> varToSumOut = new ArrayList<>();
varToSumOut.addAll(freevariables);
Expression variablesToBeSummedOut = new DefaultExtensionalMultiSet(varToSumOut);
IndexExpressionsSet indices = getIndexExpressionsOfFreeVariablesIn(variablesToBeSummedOut, context);
Expression setOfFactorInstantiations = IntensionalSet.makeMultiSet(indices, // head
product, // No Condition
makeSymbol(true));
Expression sumOnPhi = apply(SUM, setOfFactorInstantiations);
Expression evaluation = theory.evaluate(sumOnPhi, context);
Expression result = Bounds.normalizeSingleExpression(evaluation, theory, context);
return result;
}
use of com.sri.ai.expresso.core.DefaultExtensionalMultiSet 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 com.sri.ai.expresso.core.DefaultExtensionalMultiSet 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;
}
Aggregations