use of com.yahoo.searchlib.rankingexpression.RankingExpression in project vespa by vespa-engine.
the class GbdtModelTestCase method requireThatFactoryMethodWorks.
@Test
public void requireThatFactoryMethodWorks() throws Exception {
GbdtModel model = GbdtModel.fromXmlFile("src/test/files/gbdt.xml");
assertEquals(10, model.trees().size());
String exp = model.toRankingExpression();
assertEquals(readFile("src/test/files/gbdt.expression").trim(), exp.trim());
assertNotNull(new RankingExpression(exp));
}
use of com.yahoo.searchlib.rankingexpression.RankingExpression in project vespa by vespa-engine.
the class EvaluationBenchmark method runGBDT.
private void runGBDT(int iterations, String gbdtString) throws ParseException {
// Unoptimized...............
double total = benchmark(new RankingExpression(gbdtString), new MapContext(), iterations, "Unoptimized");
System.out.println("-----------------------------------------------------------------------------------------------------");
// Tree optimized...................
RankingExpression treeOptimized = new RankingExpression(gbdtString);
ArrayContext treeContext = new ArrayContext(treeOptimized, true);
ExpressionOptimizer optimizer = new ExpressionOptimizer();
optimizer.getOptimizer(GBDTForestOptimizer.class).setEnabled(false);
System.out.print("Tree optimizing ... ");
OptimizationReport treeOptimizationReport = optimizer.optimize(treeOptimized, treeContext);
System.out.println("done");
System.out.println(treeOptimizationReport);
double treeTotal = benchmark(treeOptimized, treeContext, iterations, "Tree optimized");
assertEqualish(total, treeTotal);
System.out.println("-----------------------------------------------------------------------------------------------------");
// Forest optimized...................
RankingExpression forestOptimized = new RankingExpression(gbdtString);
DoubleOnlyArrayContext forestContext = new DoubleOnlyArrayContext(forestOptimized, true);
System.out.print("Forest optimizing ... ");
OptimizationReport forestOptimizationReport = new ExpressionOptimizer().optimize(forestOptimized, forestContext);
System.out.println("done");
System.out.println(forestOptimizationReport);
double forestTotal = benchmark(forestOptimized, forestContext, iterations, "Forest optimized");
assertEqualish(total, forestTotal);
System.out.println("-----------------------------------------------------------------------------------------------------");
}
use of com.yahoo.searchlib.rankingexpression.RankingExpression in project vespa by vespa-engine.
the class EvaluationBenchmark method runNativeComparison.
public void runNativeComparison(int iterations) {
oul("Running native expression...");
MapContext arguments = new MapContext();
arguments.put("one", 1d);
out(" warming up...");
double nativeTotal = 0;
for (int i = 0; i < iterations / 5; i++) {
arguments.put("i", (double) i);
nativeTotal += nativeExpression(arguments);
}
oul("done");
out(" running " + iterations + " iterations...");
long startTime = System.currentTimeMillis();
for (int i = 0; i < iterations; i++) {
arguments.put("i", (double) i);
nativeTotal += nativeExpression(arguments);
}
long nativeTotalTime = System.currentTimeMillis() - startTime;
oul("done");
oul(" Total time running native: " + nativeTotalTime + " ms (" + iterations / nativeTotalTime + " expressions/ms)");
oul("Running ranking expression...");
RankingExpression expression;
try {
expression = new RankingExpression(comparisonExpression);
} catch (ParseException e) {
throw new RuntimeException(e);
}
out(" warming up...");
double rankingTotal = 0;
for (int i = 0; i < iterations / 5; i++) {
arguments.put("i", (double) i);
rankingTotal += expression.evaluate(arguments).asDouble();
}
oul("done");
out(" running " + iterations + " iterations...");
startTime = System.currentTimeMillis();
for (int i = 0; i < iterations; i++) {
arguments.put("i", (double) i);
rankingTotal += expression.evaluate(arguments).asDouble();
}
long rankingTotalTime = System.currentTimeMillis() - startTime;
if (rankingTotal != nativeTotal)
throw new IllegalStateException("Expressions are not the same, native: " + nativeTotal + " rankingExpression: " + rankingTotal);
oul("done");
oul(" Total time running expression: " + rankingTotalTime + " ms (" + iterations / rankingTotalTime + " expressions/ms)");
oul("Expression % of max possible speed: " + ((int) ((100 * nativeTotalTime) / rankingTotalTime)) + " %");
}
use of com.yahoo.searchlib.rankingexpression.RankingExpression in project vespa by vespa-engine.
the class EvaluationTester method assertEvaluates.
public RankingExpression assertEvaluates(Value value, String expressionString, Context context, String explanation) {
try {
RankingExpression expression = new RankingExpression(expressionString);
if (!explanation.isEmpty())
explanation = explanation + ": ";
assertEquals(explanation + expression.toString(), value, expression.evaluate(context));
return expression;
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
use of com.yahoo.searchlib.rankingexpression.RankingExpression in project vespa by vespa-engine.
the class ContextReuseTestCase method testIt.
public void testIt() throws ParseException, IOException {
// Prepare
RankingExpression expression = new RankingExpression(IOUtils.readFile(new File("src/test/files/s-expression.vre")));
ArrayContext contextPrototype = new ArrayContext(expression);
new ExpressionOptimizer().optimize(expression, contextPrototype);
// Execute
ArrayContext context = contextPrototype.clone();
for (String contextValueString : contextString.split("\n")) {
String[] contextValueParts = contextValueString.split("=");
context.put(contextValueParts[0].trim(), Double.valueOf(contextValueParts[1].trim()));
}
assertEquals(-2.3450294999999994, expression.evaluate(context).asDouble());
}
Aggregations