Search in sources :

Example 1 with ConstantFactor

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

the class ExpressionFactorTest method testMultiply4.

@Test
public void testMultiply4() {
    Theory theory = new CommonTheory();
    Context context = new TrueContext(theory);
    Expression a = DefaultSymbol.createSymbol("a");
    ExpressionFactor aFactor = new DefaultExpressionFactor(a, context);
    ConstantFactor tenFactor = new ConstantFactor(10.);
    Factor result = aFactor.multiply(tenFactor);
    assertEquals("10 * a", result.toString());
}
Also used : CommonTheory(com.sri.ai.grinder.application.CommonTheory) TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) ExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor) DefaultExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor) DefaultExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor) PropositionalTheory(com.sri.ai.grinder.theory.propositional.PropositionalTheory) EqualityTheory(com.sri.ai.grinder.theory.equality.EqualityTheory) CommonTheory(com.sri.ai.grinder.application.CommonTheory) 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) Expression(com.sri.ai.expresso.api.Expression) ConstantFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.ConstantFactor) ExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor) Factor(com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor) DefaultExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor) ConstantFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.ConstantFactor) TrueContext(com.sri.ai.grinder.core.TrueContext) Test(org.junit.Test)

Example 2 with ConstantFactor

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

the class TableFactorTest method testf2SumOutV2V4.

@Test
public void testf2SumOutV2V4() {
    println();
    println("SUM OUT V2 and V4 from F2");
    println("-------------------------------");
    ArrayList<TableVariable> variablesToSumOut = Util.arrayList(V2, V4);
    ConstantFactor f2SumOutV2V4 = (ConstantFactor) f2.sumOut(variablesToSumOut);
    // f1SumOutV1V2V3.setName("f1SumOutV1V2V3");  cannot set name of a [now] ConstantFactor
    print("f2SumOutV2V4: ");
    println(f2SumOutV2V4);
    assertEquals("129.0", f2SumOutV2V4.toString());
    println();
}
Also used : ConstantFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.ConstantFactor) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable) Test(org.junit.Test)

Example 3 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 computeInvertedMaxMinusMinFactor.

private static Factor computeInvertedMaxMinusMinFactor(Factor factor, Collection<? extends Variable> variablesToMaximizeAndMinimizeOver) {
    Factor maxFactor = factor.max(variablesToMaximizeAndMinimizeOver);
    Factor minFactor = factor.min(variablesToMaximizeAndMinimizeOver);
    Factor normalizedMaxFactor = maxFactor.normalize();
    Factor normalizedMinFactor = minFactor.normalize();
    Factor minusMinFactor = normalizedMinFactor.multiply(new ConstantFactor(-1.));
    Factor maxMinusMinFactor = normalizedMaxFactor.add(minusMinFactor);
    Factor invertMaxMinusMinFactor = maxMinusMinFactor.invert();
    return invertMaxMinusMinFactor;
}
Also used : 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 4 with ConstantFactor

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

the class ExpressionFactorTest method testAdd4.

@Test
public void testAdd4() {
    Theory theory = new CommonTheory();
    Context context = new TrueContext(theory);
    Expression a = DefaultSymbol.createSymbol("a");
    ExpressionFactor aFactor = new DefaultExpressionFactor(a, context);
    ConstantFactor tenFactor = new ConstantFactor(10.);
    Factor result = aFactor.add(tenFactor);
    assertEquals("10 + a", result.toString());
}
Also used : CommonTheory(com.sri.ai.grinder.application.CommonTheory) TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) ExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor) DefaultExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor) DefaultExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor) PropositionalTheory(com.sri.ai.grinder.theory.propositional.PropositionalTheory) EqualityTheory(com.sri.ai.grinder.theory.equality.EqualityTheory) CommonTheory(com.sri.ai.grinder.application.CommonTheory) 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) Expression(com.sri.ai.expresso.api.Expression) ConstantFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.ConstantFactor) ExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor) Factor(com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor) DefaultExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor) ConstantFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.ConstantFactor) TrueContext(com.sri.ai.grinder.core.TrueContext) Test(org.junit.Test)

Example 5 with ConstantFactor

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

the class TableFactorTest method testf1SumOutV1V2V3.

@Test
public void testf1SumOutV1V2V3() {
    println();
    println("SUM OUT V1, V2, and V3 from F1");
    println("-------------------------------");
    ArrayList<TableVariable> variablesToSumOut = Util.arrayList(V1, V2, V3);
    ConstantFactor f1SumOutV1V2V3 = (ConstantFactor) f1.sumOut(variablesToSumOut);
    // f1SumOutV1V2V3.setName("f1SumOutV1V2V3");  cannot set name of a [now] ConstantFactor
    print("f1SumOutV1V2V3: ");
    println(f1SumOutV1V2V3);
    assertEquals("24.0", f1SumOutV1V2V3.toString());
    println();
}
Also used : ConstantFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.ConstantFactor) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable) Test(org.junit.Test)

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