Search in sources :

Example 11 with Theory

use of com.sri.ai.grinder.api.Theory in project aic-expresso by aic-sri-international.

the class SymbolicShell method main.

public static void main(String[] args) {
    Theory theory = makeTheory();
    Context context = makeContext(theory);
    ConsoleIterator consoleIterator = getConsole(args);
    help(consoleIterator);
    for (String example : EXAMPLES) {
        interpretExample(example, consoleIterator, theory, context);
    }
    while (consoleIterator.hasNext()) {
        context = interpretConsoleInput(consoleIterator, theory, context);
    }
    consoleIterator.getOutputWriter().println("\nGoodbye.");
}
Also used : TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) PropositionalTheory(com.sri.ai.grinder.theory.propositional.PropositionalTheory) BruteForceFallbackTheory(com.sri.ai.grinder.theory.bruteforce.BruteForceFallbackTheory) BruteForceFunctionTheory(com.sri.ai.grinder.theory.function.BruteForceFunctionTheory) EqualityTheory(com.sri.ai.grinder.theory.equality.EqualityTheory) LinearRealArithmeticTheory(com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory) Theory(com.sri.ai.grinder.api.Theory) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) CompoundTheory(com.sri.ai.grinder.theory.compound.CompoundTheory) TupleTheory(com.sri.ai.grinder.theory.tuple.TupleTheory) GUIConsoleIterator(com.sri.ai.util.console.gui.GUIConsoleIterator) ConsoleIterator(com.sri.ai.util.console.ConsoleIterator) DefaultConsoleIterator(com.sri.ai.util.console.DefaultConsoleIterator)

Example 12 with Theory

use of com.sri.ai.grinder.api.Theory in project aic-expresso by aic-sri-international.

the class TheorySolvedSingleQuantifierEliminationProblem method makeStepSolver.

private ExpressionLiteralSplitterStepSolver makeStepSolver(Context context) {
    Theory theory = context.getTheory();
    ExpressionLiteralSplitterStepSolver result = theory.getSingleQuantifierEliminatorStepSolver(this, context);
    return result;
}
Also used : Theory(com.sri.ai.grinder.api.Theory) ExpressionLiteralSplitterStepSolver(com.sri.ai.grinder.api.ExpressionLiteralSplitterStepSolver)

Example 13 with Theory

use of com.sri.ai.grinder.api.Theory in project aic-expresso by aic-sri-international.

the class BPTest method main.

public static void main(String[] args) {
    Theory theory = new CompoundTheory(new EqualityTheory(false, true), new DifferenceArithmeticTheory(false, false), new LinearRealArithmeticTheory(false, false), new TupleTheory(), new PropositionalTheory());
    Context context = new TrueContext(theory);
    Model m = IsingModel(3, 4, theory, context, parse("Boolean"));
    // printModel(model);
    runTest(m);
}
Also used : TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) EqualityTheory(com.sri.ai.grinder.theory.equality.EqualityTheory) PropositionalTheory(com.sri.ai.grinder.theory.propositional.PropositionalTheory) EqualityTheory(com.sri.ai.grinder.theory.equality.EqualityTheory) LinearRealArithmeticTheory(com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory) Theory(com.sri.ai.grinder.api.Theory) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) CompoundTheory(com.sri.ai.grinder.theory.compound.CompoundTheory) TupleTheory(com.sri.ai.grinder.theory.tuple.TupleTheory) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) LinearRealArithmeticTheory(com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory) PropositionalTheory(com.sri.ai.grinder.theory.propositional.PropositionalTheory) CompoundTheory(com.sri.ai.grinder.theory.compound.CompoundTheory) TupleTheory(com.sri.ai.grinder.theory.tuple.TupleTheory) TrueContext(com.sri.ai.grinder.core.TrueContext)

Example 14 with Theory

use of com.sri.ai.grinder.api.Theory in project aic-expresso by aic-sri-international.

the class FactorComponent method calculate.

public Expression calculate() {
    Theory theory = this.model.theory;
    Context context = this.model.context;
    Expression childrenMessage = parse("{ 1 }");
    for (VariableComponent children : this.children) {
        childrenMessage = apply(TIMES, childrenMessage, children.calculate());
    }
    childrenMessage = apply(TIMES, childrenMessage, this.phi);
    for (Expression cutset : this.cutsetInsideSubModel) {
        // String str = "sum({{ (on " + cutset + " in Boolean ) " + childrenMessage + " }})";
        // childrenMessage = parse(str);
        // childrenMessage = theory.evaluate(childrenMessage, context);
        Expression valuesTakenByVariableToSum = this.model.getValues(cutset);
        IndexExpressionsSet indices = new ExtensionalIndexExpressionsSet(apply(IN, cutset, valuesTakenByVariableToSum));
        Expression intensionalMultiSet = IntensionalSet.makeMultiSet(indices, childrenMessage, parse("true"));
        Expression summation = apply(SUM, intensionalMultiSet);
        childrenMessage = summation;
    // String str = "sum({{ (on " + variableToSum + " in " + this.model.getValues(variableToSum) +" ) " + childrenMessage + " }})";
    // childrenMessage = parse(str);
    }
    Set<Expression> toSum = model.getNeighbors(phi);
    for (Expression e : this.parent) {
        toSum.remove(e);
    }
    toSum.removeAll(this.cutsetOutsideSubModel);
    toSum.removeAll(this.cutsetInsideSubModel);
    for (Expression variableToSum : toSum) {
        Expression expressionToSum = theory.evaluate(childrenMessage, context);
        Expression valuesTakenByVariableToSum = this.model.getValues(variableToSum);
        IndexExpressionsSet indices = new ExtensionalIndexExpressionsSet(apply(IN, variableToSum, valuesTakenByVariableToSum));
        Expression intensionalMultiSet = IntensionalSet.makeMultiSet(indices, expressionToSum, parse("true"));
        Expression summation = apply(SUM, intensionalMultiSet);
        // String str = "sum({{ (on " + variableToSum + " in " + this.model.getValues(variableToSum) +" ) " + childrenMessage + " }})";
        // childrenMessage = parse(str);
        childrenMessage = summation;
    }
    return theory.evaluate(childrenMessage, context);
}
Also used : Context(com.sri.ai.grinder.api.Context) ExtensionalIndexExpressionsSet(com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet) Theory(com.sri.ai.grinder.api.Theory) Expression(com.sri.ai.expresso.api.Expression) ExtensionalIndexExpressionsSet(com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet) IndexExpressionsSet(com.sri.ai.expresso.api.IndexExpressionsSet)

Example 15 with Theory

use of com.sri.ai.grinder.api.Theory in project aic-expresso by aic-sri-international.

the class VariableComponent method calculateBound.

public void calculateBound() {
    Theory theory = this.model.theory;
    Context context = this.model.context;
    // Expression childrenBound = parse("{ 1 }");
    // for (FactorComponent children : this.children) {
    // childrenBound = Bounds.boundProduct(theory, context, childrenBound, children.bound);
    // }
    Bound[] childrenArray = new Bound[children.size()];
    int i = 0;
    for (FactorComponent children : this.children) {
        childrenArray[i] = children.bound;
        i++;
    }
    Bound childrenBound;
    if (childrenArray.length != 0) {
        childrenBound = Bounds.boundProduct(this.model.theory, this.model.context, isExtensionalBound, childrenArray);
    } else {
        childrenBound = Bounds.makeSingleElementBound(makeSymbol(1), isExtensionalBound);
    }
    Iterator<Expression> iteratorToVariables = this.cutsetInsideSubModel.iterator();
    ArrayList<Expression> variablesToBeSummedOut = new ArrayList<>(this.cutsetInsideSubModel.size());
    for (Expression var : Util.in(iteratorToVariables)) {
        variablesToBeSummedOut.add(var);
    }
    // We want sum other toSum of Phi*childrenBound
    DefaultExtensionalUniSet varToSum = new DefaultExtensionalUniSet(variablesToBeSummedOut);
    bound = childrenBound.summingBound(varToSum, context, theory);
}
Also used : Context(com.sri.ai.grinder.api.Context) Theory(com.sri.ai.grinder.api.Theory) Expression(com.sri.ai.expresso.api.Expression) Bound(com.sri.ai.grinder.library.bounds.Bound) ArrayList(java.util.ArrayList) DefaultExtensionalUniSet(com.sri.ai.expresso.core.DefaultExtensionalUniSet)

Aggregations

Theory (com.sri.ai.grinder.api.Theory)46 Expression (com.sri.ai.expresso.api.Expression)32 Context (com.sri.ai.grinder.api.Context)23 Type (com.sri.ai.expresso.api.Type)14 DifferenceArithmeticTheory (com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory)9 Expressions.makeSymbol (com.sri.ai.expresso.helper.Expressions.makeSymbol)7 SingleQuantifierEliminationProblem (com.sri.ai.grinder.api.SingleQuantifierEliminationProblem)7 SingleVariableConstraint (com.sri.ai.grinder.api.SingleVariableConstraint)7 TrueContext (com.sri.ai.grinder.core.TrueContext)7 DefaultSingleQuantifierEliminationProblem (com.sri.ai.grinder.core.solver.DefaultSingleQuantifierEliminationProblem)7 AssociativeCommutativeGroup (com.sri.ai.grinder.group.AssociativeCommutativeGroup)7 BruteForceCommonInterpreter (com.sri.ai.grinder.interpreter.BruteForceCommonInterpreter)7 IndexExpressions (com.sri.ai.grinder.library.indexexpression.IndexExpressions)7 CompoundTheory (com.sri.ai.grinder.theory.compound.CompoundTheory)7 EqualityTheory (com.sri.ai.grinder.theory.equality.EqualityTheory)7 Beta (com.google.common.annotations.Beta)6 IndexExpressionsSet (com.sri.ai.expresso.api.IndexExpressionsSet)6 QuantifiedExpression (com.sri.ai.expresso.api.QuantifiedExpression)6 TRUE (com.sri.ai.expresso.helper.Expressions.TRUE)6 ZERO (com.sri.ai.expresso.helper.Expressions.ZERO)6