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;
}
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;
}
Aggregations