Search in sources :

Example 1 with Context

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));
}
Also used : Context(com.yahoo.searchlib.rankingexpression.evaluation.Context) MapContext(com.yahoo.searchlib.rankingexpression.evaluation.MapContext) RankingExpression(com.yahoo.searchlib.rankingexpression.RankingExpression) MapContext(com.yahoo.searchlib.rankingexpression.evaluation.MapContext) Test(org.junit.Test)

Example 2 with 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);
}
Also used : Context(com.yahoo.searchlib.rankingexpression.evaluation.Context) MapContext(com.yahoo.searchlib.rankingexpression.evaluation.MapContext) TensorValue(com.yahoo.searchlib.rankingexpression.evaluation.TensorValue) Tensor(com.yahoo.tensor.Tensor)

Aggregations

Context (com.yahoo.searchlib.rankingexpression.evaluation.Context)2 MapContext (com.yahoo.searchlib.rankingexpression.evaluation.MapContext)2 RankingExpression (com.yahoo.searchlib.rankingexpression.RankingExpression)1 TensorValue (com.yahoo.searchlib.rankingexpression.evaluation.TensorValue)1 Tensor (com.yahoo.tensor.Tensor)1 Test (org.junit.Test)1