Search in sources :

Example 26 with RankingExpression

use of com.yahoo.searchlib.rankingexpression.RankingExpression in project vespa by vespa-engine.

the class GBDTOptimizerTestCase method testSimpleNodeOptimization.

public void testSimpleNodeOptimization() throws ParseException {
    RankingExpression gbdt = new RankingExpression("if (a < 2, if (b < 2, 5, 6), 4) + if (a < 3, 7, 8)");
    // Optimized evaluation
    ArrayContext arguments = new ArrayContext(gbdt);
    ExpressionOptimizer optimizer = new ExpressionOptimizer();
    optimizer.getOptimizer(GBDTForestOptimizer.class).setEnabled(false);
    OptimizationReport report = optimizer.optimize(gbdt, arguments);
    assertEquals(2, report.getMetric("Optimized GDBT trees"));
    arguments.put("a", 1d);
    arguments.put("b", 2d);
    assertEquals(13.0, gbdt.evaluate(arguments).asDouble());
}
Also used : RankingExpression(com.yahoo.searchlib.rankingexpression.RankingExpression) ArrayContext(com.yahoo.searchlib.rankingexpression.evaluation.ArrayContext) OptimizationReport(com.yahoo.searchlib.rankingexpression.evaluation.OptimizationReport) ExpressionOptimizer(com.yahoo.searchlib.rankingexpression.evaluation.ExpressionOptimizer)

Example 27 with RankingExpression

use of com.yahoo.searchlib.rankingexpression.RankingExpression in project vespa by vespa-engine.

the class GBDTOptimizerTestCase method testBug4009433.

public void testBug4009433() throws ParseException {
    RankingExpression exp = new RankingExpression("10*if(two>35,if(two>one,if(two>=670,4,8),if(two>8000,5,3)),if(two==478,90,91))");
    new GBDTOptimizer().optimize(exp, new ArrayContext(exp), new OptimizationReport());
}
Also used : RankingExpression(com.yahoo.searchlib.rankingexpression.RankingExpression) ArrayContext(com.yahoo.searchlib.rankingexpression.evaluation.ArrayContext) OptimizationReport(com.yahoo.searchlib.rankingexpression.evaluation.OptimizationReport)

Example 28 with RankingExpression

use of com.yahoo.searchlib.rankingexpression.RankingExpression in project vespa by vespa-engine.

the class Benchmark method evaluateForestOptimized.

private static Result evaluateForestOptimized(String str, int numRuns) throws ParseException {
    Result ret = new Result();
    ret.name = "Optimized forest";
    RankingExpression exp = new RankingExpression(str);
    List<String> vars = new LinkedList<String>();
    getFeatures(exp.getRoot(), vars);
    ArrayContext ctx = new ArrayContext(exp);
    ExpressionOptimizer optimizer = new ExpressionOptimizer();
    optimizer.optimize(exp, ctx);
    benchmark(exp, vars, ctx, numRuns, ret);
    return ret;
}
Also used : RankingExpression(com.yahoo.searchlib.rankingexpression.RankingExpression) LinkedList(java.util.LinkedList)

Example 29 with RankingExpression

use of com.yahoo.searchlib.rankingexpression.RankingExpression in project vespa by vespa-engine.

the class Benchmark method evaluateTree.

private static Result evaluateTree(String str, int numRuns) throws ParseException {
    Result ret = new Result();
    ret.name = "Unoptimized";
    RankingExpression exp = new RankingExpression(str);
    List<String> vars = new LinkedList<String>();
    getFeatures(exp.getRoot(), vars);
    benchmark(exp, vars, new MapContext(), numRuns, ret);
    return ret;
}
Also used : RankingExpression(com.yahoo.searchlib.rankingexpression.RankingExpression) LinkedList(java.util.LinkedList)

Example 30 with RankingExpression

use of com.yahoo.searchlib.rankingexpression.RankingExpression in project vespa by vespa-engine.

the class Benchmark method evaluateTreeOptimized.

private static Result evaluateTreeOptimized(String str, int numRuns) throws ParseException {
    Result ret = new Result();
    ret.name = "Optimized tree";
    RankingExpression exp = new RankingExpression(str);
    List<String> vars = new LinkedList<String>();
    getFeatures(exp.getRoot(), vars);
    ArrayContext ctx = new ArrayContext(exp);
    ExpressionOptimizer optimizer = new ExpressionOptimizer();
    optimizer.getOptimizer(GBDTForestOptimizer.class).setEnabled(false);
    optimizer.optimize(exp, ctx);
    benchmark(exp, vars, ctx, numRuns, ret);
    return ret;
}
Also used : RankingExpression(com.yahoo.searchlib.rankingexpression.RankingExpression) GBDTForestOptimizer(com.yahoo.searchlib.rankingexpression.evaluation.gbdtoptimization.GBDTForestOptimizer) LinkedList(java.util.LinkedList)

Aggregations

RankingExpression (com.yahoo.searchlib.rankingexpression.RankingExpression)34 Test (org.junit.Test)10 ParseException (com.yahoo.searchlib.rankingexpression.parser.ParseException)6 ArrayContext (com.yahoo.searchlib.rankingexpression.evaluation.ArrayContext)5 OptimizationReport (com.yahoo.searchlib.rankingexpression.evaluation.OptimizationReport)4 ExpressionOptimizer (com.yahoo.searchlib.rankingexpression.evaluation.ExpressionOptimizer)3 MapContext (com.yahoo.searchlib.rankingexpression.evaluation.MapContext)3 TensorType (com.yahoo.tensor.TensorType)3 LinkedList (java.util.LinkedList)3 GBDTForestOptimizer (com.yahoo.searchlib.rankingexpression.evaluation.gbdtoptimization.GBDTForestOptimizer)2 ExpressionNode (com.yahoo.searchlib.rankingexpression.rule.ExpressionNode)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 RankProfile (com.yahoo.searchdefinition.RankProfile)1 ExpressionFunction (com.yahoo.searchlib.rankingexpression.ExpressionFunction)1 Reference (com.yahoo.searchlib.rankingexpression.Reference)1 Context (com.yahoo.searchlib.rankingexpression.evaluation.Context)1 TensorValue (com.yahoo.searchlib.rankingexpression.evaluation.TensorValue)1 Value (com.yahoo.searchlib.rankingexpression.evaluation.Value)1 TensorFlowModel (com.yahoo.searchlib.rankingexpression.integration.tensorflow.TensorFlowModel)1