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