use of com.yahoo.searchlib.rankingexpression.evaluation.Context in project vespa by vespa-engine.
the class SimplifierTestCase method testSimplifyComplexExpression.
// A black box test verifying we are not screwing up real expressions
@Test
public void testSimplifyComplexExpression() throws ParseException {
RankingExpression initial = new RankingExpression("sqrt(if (if (INFERRED * 0.9 < INFERRED, GMP, (1 + 1.1) * INFERRED) < INFERRED * INFERRED - INFERRED, if (GMP < 85.80799542793133 * GMP, INFERRED, if (GMP < GMP, tanh(INFERRED), log(76.89956221113943))), tanh(tanh(INFERRED))) * sqrt(sqrt(GMP + INFERRED)) * GMP ) + 13.5 * (1 - GMP) * pow(GMP * 0.1, 2 + 1.1 * 0)");
TransformContext c = new TransformContext(Collections.emptyMap());
RankingExpression simplified = new Simplifier().transform(initial, c);
Context context = new MapContext();
context.put("INFERRED", 0.5);
context.put("GMP", 80.0);
context.put("value", 50.0);
assertEquals(initial.evaluate(context), simplified.evaluate(context));
context.put("INFERRED", 38.0);
context.put("GMP", 80.0);
context.put("value", 50.0);
assertEquals(initial.evaluate(context), simplified.evaluate(context));
context.put("INFERRED", 38.0);
context.put("GMP", 90.0);
context.put("value", 100.0);
assertEquals(initial.evaluate(context), simplified.evaluate(context));
context.put("INFERRED", 500.0);
context.put("GMP", 90.0);
context.put("value", 100.0);
assertEquals(initial.evaluate(context), simplified.evaluate(context));
}
use of com.yahoo.searchlib.rankingexpression.evaluation.Context in project vespa by vespa-engine.
the class TestableTensorFlowModel method assertEqualResult.
public void assertEqualResult(String inputName, String operationName) {
Tensor tfResult = tensorFlowExecute(tensorFlowModel, inputName, operationName);
Context context = contextFrom(model);
Tensor placeholder = placeholderArgument();
context.put(inputName, new TensorValue(placeholder));
model.macros().forEach((k, v) -> evaluateMacro(context, model, k));
Tensor vespaResult = model.expressions().get(operationName).evaluate(context).asTensor();
assertEquals("Operation '" + operationName + "' produces equal results", tfResult, vespaResult);
}
Aggregations