use of com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable in project aic-praise by aic-sri-international.
the class PerformanceTest method sumOutLastVariable.
private static Factor sumOutLastVariable(Factor factor) {
List<? extends Variable> factorVariables = factor.getVariables();
int indexOfLastVariable = factorVariables.size() - 1;
List<Variable> variablesToSumOut = new ArrayList<>();
if (factorVariables.size() > 0) {
variablesToSumOut.add(factorVariables.get(indexOfLastVariable));
}
Factor result = factor.sumOut(variablesToSumOut);
return result;
}
use of com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable in project aic-praise by aic-sri-international.
the class PerformanceTest method sumOutFirstVariable.
private static Factor sumOutFirstVariable(Factor factor) {
List<? extends Variable> factorVariables = factor.getVariables();
int indexOfFirstVariable = 0;
List<Variable> variablesToSumOut = new ArrayList<>();
if (factorVariables.size() > 0) {
variablesToSumOut.add(factorVariables.get(indexOfFirstVariable));
}
Factor result = factor.sumOut(variablesToSumOut);
return result;
}
use of com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable in project aic-praise by aic-sri-international.
the class BenchmarkingIsingModel method testEBPP.
private static void testEBPP(AEBPTestingDataFrame df, int nRepetitions, List<TableFactor> network, TableVariable query, String netName) {
TableFactorNetwork factorNetwork = new TableFactorNetwork(network);
ExactBPNode<Variable, Factor> exactBP = new ExactBP(query, factorNetwork);
for (int i = 0; i < nRepetitions; i++) {
println("solveWithExactBP : " + netName);
Pair<Double, Factor> p = solveAndPrint(exactBP);
df.addRow(// run number
i, // iteration
-1, // minPTrue
((TableFactor) p.second).getEntries().get(0), // MaxPTrue
((TableFactor) p.second).getEntries().get(0), // iteration time
p.first, // total time
p.first, // InferenceMethodUsed
"ExactBP", // GraphicalModelName
netName + "; query: " + query.toString());
}
}
use of com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable in project aic-praise by aic-sri-international.
the class TableFactorBoxBuilder method makeTableBox.
public static Box makeTableBox(IntensionalConvexHullOfFactors bound) {
ArrayList<TableVariable> notFreeVariables = new ArrayList<>(bound.getIndices().size());
for (Variable v : bound.getIndices()) {
notFreeVariables.add((TableVariable) v);
}
TableFactor factor = buildBoxFactor((TableFactor) bound.getFactor(), notFreeVariables);
Box result = new Box(TABLE_BOX_VARIABLE, factor);
return result;
}
use of com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable in project aic-praise by aic-sri-international.
the class Polytopes method getEquivalentAtomicPolytopeOn.
/**
* Takes a polytope in which the only free variable is a given query variable,
* and returns a single equivalent {@link AtomicPolytope}.
*
* @return
*/
public static AtomicPolytope getEquivalentAtomicPolytopeOn(Variable query, Polytope polytope) {
myAssert(polytope.getFreeVariables().size() == 1 && polytope.getFreeVariables().contains(query), () -> "getEquivalentIntensionalConvexHullOfFactorsOn must receive polytope whose only free variable is " + query + ", but instead got <" + polytope + "> with free variables " + polytope.getFreeVariables());
AtomicPolytope result;
final List<? extends AtomicPolytope> nonIdentityAtomicPolytopes = getNonIdentityAtomicPolytopes(list(polytope));
Simplex simplexOnVariableIfAny = (Simplex) getFirstSatisfyingPredicateOrNull(nonIdentityAtomicPolytopes, p -> isSimplexOn(p, query));
boolean thereIsSimplexOnQuerySoItDominates = simplexOnVariableIfAny != null;
if (thereIsSimplexOnQuerySoItDominates) {
result = simplexOnVariableIfAny;
} else {
// all nonIdentityAtomicPolytopes are intensional convex hulls, or otherwise we would have simplexes on non-query variables and the query would not be the only free variable
result = mergeIntensionalConvexHulls(nonIdentityAtomicPolytopes);
}
return result;
}
Aggregations