@Override public FieldValue evaluate(List<FieldValue> values) { if (values.size() != 2) { throw new EvaluationException(); } FieldValue left = values.get(0); FieldValue right = values.get(1); // "If one of the input fields of a simple arithmetic function is a missing value, the result // evaluates to missing value" if (left == null || right == null) { return null; } DataType dataType = TypeUtil.getResultDataType(left.getDataType(), right.getDataType()); Number result; try { result = evaluate(left.asNumber(), right.asNumber()); } catch (ArithmeticException ae) { throw new InvalidResultException(null); } return FieldValueUtil.create(cast(dataType, result)); }
@Override public FieldValue evaluate(List<FieldValue> values) { StorelessUnivariateStatistic statistic = createStatistic(); DataType dataType = null; for (FieldValue value : values) { // "Missing values in the input to an aggregate function are simply ignored" if (value == null) { continue; } statistic.increment((value.asNumber()).doubleValue()); if (dataType != null) { dataType = TypeUtil.getResultDataType(dataType, value.getDataType()); } else { dataType = value.getDataType(); } } if (statistic.getN() == 0) { throw new MissingResultException(null); } Object result = cast(getResultType(dataType), statistic.getResult()); return FieldValueUtil.create(result); }
@Override public FieldValue evaluate(List<FieldValue> values) { checkArguments(values, 1); FieldValue value = values.get(0); Number result = cast(getResultType(value.getDataType()), evaluate(value.asNumber())); return FieldValueUtil.create(result); }
private double[] createInput(EvaluationContext context) { SupportVectorMachineModel supportVectorMachineModel = getModel(); VectorDictionary vectorDictionary = supportVectorMachineModel.getVectorDictionary(); VectorFields vectorFields = vectorDictionary.getVectorFields(); List<FieldRef> fieldRefs = vectorFields.getFieldRefs(); double[] result = new double[fieldRefs.size()]; for (int i = 0; i < fieldRefs.size(); i++) { FieldRef fieldRef = fieldRefs.get(i); FieldValue value = ExpressionUtil.evaluate(fieldRef, context); if (value == null) { throw new MissingValueException(fieldRef.getField(), vectorFields); } result[i] = (value.asNumber()).doubleValue(); } return result; }