use of com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable in project aic-praise by aic-sri-international.
the class GradientAnytimeExactBP method collapse.
private static AtomicPolytope collapse(Polytope subPolytope) {
Variable freeVariable = getFreeVariable(subPolytope);
AtomicPolytope subAtomicPolytope = Polytopes.getEquivalentAtomicPolytopeOn(freeVariable, subPolytope);
return subAtomicPolytope;
}
use of com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable in project aic-praise by aic-sri-international.
the class GradientAnytimeExactBP method getAbsoluteVolumeVariationFromFactorToVariableWithRespectTo.
private Double getAbsoluteVolumeVariationFromFactorToVariableWithRespectTo(Anytime<Factor> sub, Collection<? extends Variable> subAtomicPolytopeIndices) {
// root is a variable
Approximation<Factor> subApproximation = sub.getCurrentApproximation();
AtomicPolytope subAtomicPolytope = transformApproximationToAtomicPolytopeOrThrowsErrorIfNotPossible(subApproximation);
Approximation<Factor> rootApproximation = getCurrentApproximation();
IntensionalConvexHullOfFactors rootConvexHull = transformApproximationToConvexHullOrThrowsErrorIfNotPossible(rootApproximation);
Collection<? extends Variable> rootIndices = rootConvexHull.getIndices();
Factor rootFactor = rootConvexHull.getFactor();
Factor normalizedMaxFactor = createNormalizedMaxFactor(rootIndices);
Factor normalizedMinFactor = createNormalizedMinFactor(rootIndices);
Factor invertedMaxMinusMinFactor = computeInvertedMaxMinusMinFactor(rootFactor, subAtomicPolytopeIndices);
List<Variable> rootFreeVariables = new ArrayList<>(rootConvexHull.getFreeVariables());
Factor maxFactor = rootFactor.max(rootIndices);
Factor maxNormalizationConstant = maxFactor.sumOut(rootFreeVariables);
Factor invertedMaxNormalizationConstant = maxNormalizationConstant.invert();
Factor maxProduct = invertedMaxMinusMinFactor.multiply(invertedMaxNormalizationConstant);
Factor minFactor = rootFactor.min(rootIndices);
Factor minNormalizationConstant = minFactor.sumOut(rootFreeVariables);
Factor invertedMinNormalizationConstant = minNormalizationConstant.invert();
Factor minProduct = invertedMaxMinusMinFactor.multiply(invertedMinNormalizationConstant);
Polytope summedOutPolytopeWithoutOneSub = sumOutWithoutOneSub(sub);
IntensionalConvexHullOfFactors rootConvexHullWithoutOneSub = (IntensionalConvexHullOfFactors) summedOutPolytopeWithoutOneSub;
Factor rootFactorWithoutOneSub = rootConvexHullWithoutOneSub.getFactor();
Factor summedOutRootFactorWithoutOneSub = rootFactorWithoutOneSub.sumOut(rootFreeVariables);
return null;
// TODO
}
use of com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable in project aic-praise by aic-sri-international.
the class BFS method next.
@Override
public AEBPFactorTreeNode next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
AEBPFactorTreeNode next = queue.remove();
for (Variable variableNeighbour : model.getEntireGraph().getNeighbors(next.getRoot())) {
AEBPVariableTreeNode variableTreeNode;
if (fromNodeToPartition.get(variableNeighbour) == null) {
variableTreeNode = new AEBPVariableTreeNode(variableNeighbour, next, isExhausted);
next.addChild(variableTreeNode);
fromNodeToPartition.put(variableNeighbour, variableTreeNode);
} else {
variableTreeNode = (AEBPVariableTreeNode) fromNodeToPartition.get(variableNeighbour);
}
for (Factor factorNeighbour : model.getEntireGraph().getNeighbors(variableNeighbour)) {
if (!visited.contains(factorNeighbour)) {
AEBPFactorTreeNode factorTreeNode = new AEBPFactorTreeNode(factorNeighbour, variableTreeNode, isExhausted);
// variableTreeNode.addChild(factorTreeNode);
visited.add(factorNeighbour);
queue.add(factorTreeNode);
}
}
}
return next;
}
Aggregations