Search in sources :

Example 76 with Expression

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

the class SingleVariableConstraint method satisfiability.

/**
	 * Returns the satisfiability of this single-variable constraint under a context and context,
	 * or null if there is no appropriate solver.
	 * @param context
	 * @return
	 */
default default Expression satisfiability(Context context) {
    ExpressionLiteralSplitterStepSolver satisfiabilityStepSolver = getTheory().getSingleVariableConstraintSatisfiabilityStepSolver(this, context);
    Expression satisfiability;
    if (satisfiabilityStepSolver != null) {
        satisfiability = satisfiabilityStepSolver.solve(context);
    } else {
        satisfiability = null;
    }
    return satisfiability;
}
Also used : Expression(com.sri.ai.expresso.api.Expression)

Example 77 with Expression

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

the class Examples method RealCancerModel.

public static VariableComponent RealCancerModel(Set<Expression> condition) {
    // https://qph.ec.quoracdn.net/main-qimg-17c53810d49f6e917af93e576a9ec8da
    Expression visitToAsia = DefaultSymbol.createSymbol("VisitToAsia");
    Expression tuberculosis = DefaultSymbol.createSymbol("Tuberculosis");
    Expression lungCancer = DefaultSymbol.createSymbol("LungCancer");
    Expression lungCancerOrTuberculosis = DefaultSymbol.createSymbol("LungCancerOrTuberculosis");
    Expression positiveXRay = DefaultSymbol.createSymbol("PositiveXRay");
    Expression dispnea = DefaultSymbol.createSymbol("Dispnea");
    Expression bronchitis = DefaultSymbol.createSymbol("Bronchitis");
    Expression smoker = DefaultSymbol.createSymbol("Smoker");
    Expression probabilityVisitToAsia = IfThenElse.make(visitToAsia, parse("0.01"), parse("0.99"));
    Expression probabilitySmoker = IfThenElse.make(smoker, parse("0.5"), parse("0.5"));
    Expression f1 = IfThenElse.make(visitToAsia, IfThenElse.make(tuberculosis, parse("0.05"), parse("0.95")), IfThenElse.make(tuberculosis, parse("0.01"), parse("0.99")));
    Expression f2 = IfThenElse.make(smoker, IfThenElse.make(lungCancer, parse("0.1"), parse("0.9")), IfThenElse.make(lungCancer, parse("0.01"), parse("0.99")));
    Expression f3 = IfThenElse.make(smoker, IfThenElse.make(bronchitis, parse("0.6"), parse("0.4")), IfThenElse.make(bronchitis, parse("0.3"), parse("0.7")));
    Expression f4 = IfThenElse.make(lungCancerOrTuberculosis, IfThenElse.make(positiveXRay, parse("0.98"), parse("0.02")), IfThenElse.make(positiveXRay, parse("0.05"), parse("0.95")));
    Expression f5 = IfThenElse.make(lungCancerOrTuberculosis, IfThenElse.make(lungCancer, parse("1"), IfThenElse.make(tuberculosis, parse("1"), parse("0"))), IfThenElse.make(lungCancer, parse("0"), IfThenElse.make(tuberculosis, parse("0"), parse("1"))));
    Expression f6 = IfThenElse.make(lungCancerOrTuberculosis, IfThenElse.make(bronchitis, IfThenElse.make(dispnea, parse("0.9"), parse("0.1")), IfThenElse.make(dispnea, parse("0.7"), parse("0.3"))), IfThenElse.make(bronchitis, IfThenElse.make(dispnea, parse("0.8"), parse("0.2")), IfThenElse.make(dispnea, parse("0.1"), parse("0.9"))));
    Set<Expression> Factor = new HashSet<Expression>();
    Factor.add(f1);
    Factor.add(f2);
    Factor.add(f3);
    Factor.add(f4);
    Factor.add(f5);
    Factor.add(f6);
    Factor.add(probabilityVisitToAsia);
    Factor.add(probabilitySmoker);
    Model m = new Model(Factor);
    m.addConditions(condition);
    VariableComponent ComponentResultat = new VariableComponent(lungCancer, DefaultSymbol.createSymbol(""), m, new HashSet<Expression>());
    return ComponentResultat;
}
Also used : Expression(com.sri.ai.expresso.api.Expression) HashSet(java.util.HashSet)

Example 78 with Expression

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

the class Examples method TriangleModel.

public static VariableComponent TriangleModel() {
    Expression func = DefaultSymbol.createSymbol("f");
    Expression a = DefaultSymbol.createSymbol("A");
    Expression b = DefaultSymbol.createSymbol("B");
    Expression q = DefaultSymbol.createSymbol("Q");
    Expression f1 = apply(IF_THEN_ELSE, a, q, 5);
    Expression f2 = apply(IF_THEN_ELSE, b, q, 5);
    Expression f3 = apply(IF_THEN_ELSE, a, b, 5);
    Expression res = apply(func, q);
    Set<Expression> Factor = new HashSet<Expression>();
    Factor.add(f1);
    Factor.add(f2);
    Factor.add(f3);
    Factor.add(res);
    Model m = new Model(Factor);
    VariableComponent ComponentResultat = new VariableComponent(q, res, m, new HashSet<Expression>());
    return ComponentResultat;
}
Also used : Expression(com.sri.ai.expresso.api.Expression) HashSet(java.util.HashSet)

Example 79 with Expression

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

the class TrueContext method add.

@Override
public TrueContext add(Type type) {
    TrueContext result = clone();
    String name = type.getName();
    Expression typeExpression = parse(name);
    LinkedHashMap<Expression, Type> additionalTypeMap = map(typeExpression, type);
    result.fromTypeExpressionToType = new StackedHashMap<>(additionalTypeMap, fromTypeExpressionToType);
    return result;
}
Also used : Type(com.sri.ai.expresso.api.Type) Expression(com.sri.ai.expresso.api.Expression)

Example 80 with Expression

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

the class AbstractSingleVariableConstraint method computeInnerExpressionIfNotContradiction.

@Override
protected Expression computeInnerExpressionIfNotContradiction() {
    List<Expression> conjuncts = list();
    conjuncts.addAll(positiveNormalizedAtoms);
    Util.mapIntoList(negativeNormalizedAtoms, n -> fromNormalizedAtomToItsNegationAsLiteral(n), conjuncts);
    conjuncts.addAll(externalLiterals);
    Expression result = And.make(conjuncts);
    return result;
}
Also used : Expression(com.sri.ai.expresso.api.Expression)

Aggregations

Expression (com.sri.ai.expresso.api.Expression)1392 Test (org.junit.Test)259 ArrayList (java.util.ArrayList)196 Context (com.sri.ai.grinder.api.Context)187 Type (com.sri.ai.expresso.api.Type)124 TrueContext (com.sri.ai.grinder.core.TrueContext)113 IndexExpressionsSet (com.sri.ai.expresso.api.IndexExpressionsSet)100 ExtensionalIndexExpressionsSet (com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet)91 QuantifiedExpression (com.sri.ai.expresso.api.QuantifiedExpression)90 Context (com.sri.ai.grinder.sgdpllt.api.Context)87 Theory (com.sri.ai.grinder.api.Theory)78 Map (java.util.Map)78 LambdaExpression (com.sri.ai.expresso.api.LambdaExpression)71 IntensionalSet (com.sri.ai.expresso.api.IntensionalSet)68 List (java.util.List)68 DefaultLambdaExpression (com.sri.ai.expresso.core.DefaultLambdaExpression)63 CommonTheory (com.sri.ai.grinder.application.CommonTheory)55 LinkedHashMap (java.util.LinkedHashMap)55 LinkedHashSet (java.util.LinkedHashSet)54 Pair (com.sri.ai.util.base.Pair)52