use of com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue in project vespa by vespa-engine.
the class Reshape method unrollTensorExpression.
private static ExpressionNode unrollTensorExpression(TensorType type) {
if (type.rank() == 0) {
return new ConstantNode(DoubleValue.zero);
}
List<ExpressionNode> children = new ArrayList<>();
List<ArithmeticOperator> operators = new ArrayList<>();
int size = 1;
for (int i = type.dimensions().size() - 1; i >= 0; --i) {
TensorType.Dimension dimension = type.dimensions().get(i);
children.add(0, new ReferenceNode(dimension.name()));
if (size > 1) {
operators.add(0, ArithmeticOperator.MULTIPLY);
children.add(0, new ConstantNode(new DoubleValue(size)));
}
size *= TensorConverter.dimensionSize(dimension);
if (i > 0) {
operators.add(0, ArithmeticOperator.PLUS);
}
}
return new ArithmeticNode(children, operators);
}
use of com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue in project vespa by vespa-engine.
the class ExpandDims method lazyGetFunction.
@Override
protected TensorFunction lazyGetFunction() {
if (!allInputFunctionsPresent(2)) {
return null;
}
// multiply with a generated tensor created from the reduced dimensions
TensorType.Builder typeBuilder = new TensorType.Builder();
for (String name : expandDimensions) {
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());
return new com.yahoo.tensor.functions.Join(inputs().get(0).function().get(), generatedFunction, ScalarFunctions.multiply());
}
use of com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue in project vespa by vespa-engine.
the class ElementCompleteness method compute.
/**
* Computes the following elementCompleteness features:
* <ul>
* <li><code>completeness</code>
* <li><code>fieldCompleteness</code>
* <li><code>queryCompleteness</code>
* <li><code>elementWeight</code>
* </ul>
*
* @param queryTerms the query terms with associated weights to compute over
* @param field a set of weighted field values, where each is taken to be a space-separated string of tokens
* @return a features object containing the values listed above
*/
public static Features compute(Map<String, Integer> queryTerms, Item[] field) {
double completeness = 0;
double fieldCompleteness = 0;
double queryCompleteness = 0;
double elementWeight = 0;
double queryTermWeightSum = sum(queryTerms.values());
for (Item item : field) {
String[] itemTokens = item.value().split(" ");
int matchCount = 0;
int matchWeightSum = 0;
for (String token : itemTokens) {
Integer weight = queryTerms.get(token);
if (weight == null)
continue;
matchCount++;
matchWeightSum += weight;
}
double itemFieldCompleteness = (double) matchCount / itemTokens.length;
double itemQueryCompleteness = matchWeightSum / queryTermWeightSum;
double itemCompleteness = fieldCompletenessImportance * itemFieldCompleteness + (1 - fieldCompletenessImportance) * itemQueryCompleteness;
if (itemCompleteness > completeness) {
completeness = itemCompleteness;
fieldCompleteness = itemFieldCompleteness;
queryCompleteness = itemQueryCompleteness;
elementWeight = item.weight();
}
}
Map<String, Value> features = new HashMap<>();
features.put("completeness", new DoubleValue(completeness));
features.put("fieldCompleteness", new DoubleValue(fieldCompleteness));
features.put("queryCompleteness", new DoubleValue(queryCompleteness));
features.put("elementWeight", new DoubleValue(elementWeight));
return new Features(features);
}
Aggregations