Search in sources :

Example 6 with ConstantFactor

use of com.sri.ai.praise.core.representation.interfacebased.factor.core.ConstantFactor in project aic-praise by aic-sri-international.

the class TableFactor method sumOut.

/**
 * Sums out given variables from factor.
 *
 * @param variablesToSumOut (variables to sum out)
 * @return new factor with given variables summed out
 */
@Override
public Factor sumOut(List<? extends Variable> variablesToSumOutList) {
    // TODO: Error check for if variablesToSumOut is of type List<? extends TableVarable>
    // TODO: Error check for if a variable listed to SumOut exists in the factor
    LinkedHashSet<TableVariable> variablesToSumOut = new LinkedHashSet<>((List<TableVariable>) variablesToSumOutList);
    LinkedHashSet<TableVariable> variablesNotToSumOut = new LinkedHashSet<>();
    variablesNotToSumOut = (LinkedHashSet<TableVariable>) setDifference(this.variableSet, variablesToSumOut, variablesNotToSumOut);
    Factor result;
    // if every variable is summed out, return the sum of all the parameters in a constant factor
    if (variablesNotToSumOut.isEmpty()) {
        result = new ConstantFactor(sumOfParameters());
    } else {
        result = sumOutEverythingExcept(variablesNotToSumOut);
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ConstantFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.ConstantFactor) Factor(com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor) ConstantFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.ConstantFactor)

Example 7 with ConstantFactor

use of com.sri.ai.praise.core.representation.interfacebased.factor.core.ConstantFactor in project aic-praise by aic-sri-international.

the class GradientAnytimeExactBP method getAbsoluteVolumeVariationFromVariableToFactorWithRespectTo.

// implementation based on logVolume
private Double getAbsoluteVolumeVariationFromVariableToFactorWithRespectTo(Anytime<Factor> sub, Collection<? extends Variable> subAtomicPolytopeIndices) {
    // root is a factor
    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);
    Factor normalizedMaxFactorWithoutOneSub = createNormalizedMaxFactorWithoutOneSub(sub, rootIndices);
    Factor normalizedMinFactorWithoutOneSub = createNormalizedMinFactorWithoutOneSub(sub, rootIndices);
    Factor minusNormalizedMinFactorWithoutOneSub = normalizedMinFactorWithoutOneSub.multiply(new ConstantFactor(1.));
    Factor MaxMinusMinFactorWithoutOneSub = normalizedMaxFactorWithoutOneSub.add(minusNormalizedMinFactorWithoutOneSub);
    Factor firstTermProduct = invertedMaxMinusMinFactor.multiply(MaxMinusMinFactorWithoutOneSub);
    Factor firstTerm = firstTermProduct.sumOut(new ArrayList<>(rootConvexHull.getFreeVariables()));
    return null;
}
Also used : 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) ConstantFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.ConstantFactor) AtomicPolytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope)

Aggregations

ConstantFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.ConstantFactor)7 Factor (com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor)5 Test (org.junit.Test)4 Expression (com.sri.ai.expresso.api.Expression)2 Context (com.sri.ai.grinder.api.Context)2 Theory (com.sri.ai.grinder.api.Theory)2 CommonTheory (com.sri.ai.grinder.application.CommonTheory)2 TrueContext (com.sri.ai.grinder.core.TrueContext)2 CompoundTheory (com.sri.ai.grinder.theory.compound.CompoundTheory)2 DifferenceArithmeticTheory (com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory)2 EqualityTheory (com.sri.ai.grinder.theory.equality.EqualityTheory)2 LinearRealArithmeticTheory (com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory)2 PropositionalTheory (com.sri.ai.grinder.theory.propositional.PropositionalTheory)2 TupleTheory (com.sri.ai.grinder.theory.tuple.TupleTheory)2 ExpressionFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor)2 DefaultExpressionFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor)2 TableVariable (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable)2 AtomicPolytope (com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope)1 IntensionalConvexHullOfFactors (com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.convexhull.IntensionalConvexHullOfFactors)1 LinkedHashSet (java.util.LinkedHashSet)1