use of com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue in project vespa by vespa-engine.
the class TensorFlowFeatureConverter method expandBatchDimensionsAtOutput.
/**
* If batch dimensions have been reduced away above, bring them back here
* for any following computation of the tensor.
* Todo: determine when this is not necessary!
*/
private ExpressionNode expandBatchDimensionsAtOutput(ExpressionNode node, TensorType before, TensorType after) {
if (after.equals(before)) {
return node;
}
TensorType.Builder typeBuilder = new TensorType.Builder();
for (TensorType.Dimension dimension : before.dimensions()) {
if (dimension.size().orElse(-1L) == 1 && !after.dimensionNames().contains(dimension.name())) {
typeBuilder.indexed(dimension.name(), 1);
}
}
TensorType expandDimensionsType = typeBuilder.build();
if (expandDimensionsType.dimensions().size() > 0) {
ExpressionNode generatedExpression = new ConstantNode(new DoubleValue(1.0));
Generate generatedFunction = new Generate(expandDimensionsType, new GeneratorLambdaFunctionNode(expandDimensionsType, generatedExpression).asLongListToDoubleOperator());
Join expand = new Join(TensorFunctionNode.wrapArgument(node), generatedFunction, ScalarFunctions.multiply());
return new TensorFunctionNode(expand);
}
return node;
}
use of com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue in project vespa by vespa-engine.
the class ReferenceNodeTestCase method requireThatAccessorsWork.
@Test
public void requireThatAccessorsWork() {
TreeNode lhs = new ResponseNode(6.0, null);
TreeNode rhs = new ResponseNode(9.0, null);
NumericFeatureNode node = new NumericFeatureNode("foo", new DoubleValue(6.9), null, lhs, rhs);
assertEquals("foo", node.feature());
assertEquals(6.9, node.value().asDouble(), 1E-6);
assertSame(lhs, node.left());
assertSame(rhs, node.right());
}
use of com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue in project vespa by vespa-engine.
the class Simplifier method transformArithmetic.
private ExpressionNode transformArithmetic(ArithmeticNode node) {
if (node.children().size() > 1) {
List<ExpressionNode> children = new ArrayList<>(node.children());
List<ArithmeticOperator> operators = new ArrayList<>(node.operators());
for (ArithmeticOperator operator : ArithmeticOperator.operatorsByPrecedence) transform(operator, children, operators);
node = new ArithmeticNode(children, operators);
}
if (isConstant(node))
return new ConstantNode(node.evaluate(null));
else if (// disregarding the /0 case
allMultiplicationOrDivision(node) && hasZero(node))
return new ConstantNode(new DoubleValue(0));
else
return node;
}
use of com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue in project vespa by vespa-engine.
the class Mean method lazyGetFunction.
// todo: optimization: if keepDims and one reduce dimension that has size 1: same as identity.
@Override
protected TensorFunction lazyGetFunction() {
if (!allInputTypesPresent(2)) {
return null;
}
TensorFunction inputFunction = inputs.get(0).function().get();
TensorFunction output = new Reduce(inputFunction, Reduce.Aggregator.avg, reduceDimensions);
if (shouldKeepDimensions()) {
// multiply with a generated tensor created from the reduced dimensions
TensorType.Builder typeBuilder = new TensorType.Builder();
for (String name : reduceDimensions) {
typeBuilder.indexed(name, 1);
}
TensorType generatedType = typeBuilder.build();
ExpressionNode generatedExpression = new ConstantNode(new DoubleValue(1));
Generate generatedFunction = new Generate(generatedType, new GeneratorLambdaFunctionNode(generatedType, generatedExpression).asLongListToDoubleOperator());
output = new com.yahoo.tensor.functions.Join(output, generatedFunction, ScalarFunctions.multiply());
}
return output;
}
use of com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue in project vespa by vespa-engine.
the class FieldTermMatch method compute.
/**
* Computes the fieldTermMatch features:
* <ul>
* <li><code>firstPosition</code> - the position of the first occurrence of this query term in this index field</li>
* <li><code>occurrences</code> - the position of the first occurrence of this query term in this index field</li>
* </ul>
* @param queryTerm the term to return these features for
* @param field the field value to compute over, assumed to be a space-separated string of tokens
* @return a features object containing the two values described above
*/
public static Features compute(String queryTerm, String field) {
Map<String, Value> features = new HashMap<>();
String[] tokens = field.split(" ");
int occurrences = 0;
int firstPosition = 1000000;
for (int i = 0; i < tokens.length; i++) {
if (tokens[i].equals(queryTerm)) {
if (occurrences == 0)
firstPosition = i;
occurrences++;
}
}
features.put("firstPosition", new DoubleValue(firstPosition));
features.put("occurrences", new DoubleValue(occurrences));
return new Features(features);
}
Aggregations