Search in sources :

Example 21 with Variable

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;
}
Also used : Variable(com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable) AtomicPolytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope)

Example 22 with Variable

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
}
Also used : Polytopes.identityPolytope(com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.convexhull.Polytopes.identityPolytope) AtomicPolytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope) Polytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.Polytope) Variable(com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable) IntensionalConvexHullOfFactors(com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.convexhull.IntensionalConvexHullOfFactors) ConstantFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.ConstantFactor) Factor(com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor) ArrayList(java.util.ArrayList) AtomicPolytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope)

Example 23 with Variable

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;
}
Also used : Variable(com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable) AEBPFactorTreeNode(com.sri.ai.praise.core.inference.byinputrepresentation.interfacebased.core.exactbp.anytime.gabriel.aebptree.AEBPFactorTreeNode) AEBPVariableTreeNode(com.sri.ai.praise.core.inference.byinputrepresentation.interfacebased.core.exactbp.anytime.gabriel.aebptree.AEBPVariableTreeNode) Factor(com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

Variable (com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable)23 Factor (com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor)11 ArrayList (java.util.ArrayList)10 TableFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor)9 TableVariable (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable)9 ExpressionFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor)4 AtomicPolytope (com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope)4 Polytope (com.sri.ai.praise.core.representation.interfacebased.polytope.api.Polytope)4 Util.mapIntoArrayList (com.sri.ai.util.Util.mapIntoArrayList)4 List (java.util.List)4 Expression (com.sri.ai.expresso.api.Expression)3 TableFactorNetwork (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactorNetwork)3 TableBoxVariable (com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.box.TableBoxVariable)3 IntensionalConvexHullOfFactors (com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.convexhull.IntensionalConvexHullOfFactors)3 Predicate (com.google.common.base.Predicate)2 AnytimeExactBP (com.sri.ai.praise.core.inference.byinputrepresentation.interfacebased.core.exactbp.anytime.rodrigo.AnytimeExactBP)2 ExactBP (com.sri.ai.praise.core.inference.byinputrepresentation.interfacebased.core.exactbp.fulltime.core.ExactBP)2 ExpressionVariable (com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionVariable)2 ExpressionExactBP (com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.ExpressionExactBP)2 RandomTableFactorMaker.makeRandomTableFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.helper.RandomTableFactorMaker.makeRandomTableFactor)2