@Override public Object getResult(){ if(this.result == null){ throw new EvaluationException("Classification result has not been computed"); } return this.result; }
@Override public Object getResult(){ if(this.result == null){ throw new EvaluationException("Vote result has not been computed"); } return this.result; }
public Node getLastPrediction(){ if(this.lastPrediction == null){ throw new EvaluationException("Empty trail"); } return this.lastPrediction; }
@Override public Object getResult(){ if(this.result == null){ throw new EvaluationException("Regression result has not been computed"); } return this.result; }
@Override public int compareToString(String string){ throw new EvaluationException("Categorical value cannot be used in comparison operations"); }
@Override public int compareToValue(FieldValue value){ throw new EvaluationException("Categorical value cannot be used in comparison operations"); }
static public Pattern compile(String regex, int flags, PMMLObject context){ try { return Pattern.compile(regex, flags); } catch(PatternSyntaxException pse){ String message = "Regex pattern could not be compiled"; throw (context != null ? new EvaluationException(message, context) : new EvaluationException(message)) .initCause(pse); } } }
static private int compare(List<?> ordering, Object left, Object right){ int leftIndex = ordering.indexOf(left); int rightIndex = ordering.indexOf(right); if((leftIndex | rightIndex) < 0){ throw new EvaluationException("Values " + PMMLException.formatValue(left) + " and " + PMMLException.formatValue(right) + " cannot be ordered"); } return (leftIndex - rightIndex); }
protected void computeResult(DataType dataType){ Map.Entry<String, Value<V>> entry = getWinner(); if(entry == null){ throw new EvaluationException("Empty classification"); } String key = entry.getKey(); Value<V> value = entry.getValue(); Object result = TypeUtil.parse(dataType, key); setResult(result); }
protected EvaluationException createMiningSchemaException(String message){ M model = getModel(); MiningSchema miningSchema = model.getMiningSchema(); return new EvaluationException(message, miningSchema); }
static public BitSet toBitSet(List<FieldValue> values){ BitSet result = new BitSet(values.size()); for(int i = 0; i < values.size(); i++){ FieldValue value = values.get(i); if((FieldValues.CONTINUOUS_DOUBLE_ZERO).equalsValue(value)){ result.set(i, false); } else if((FieldValues.CONTINUOUS_DOUBLE_ONE).equalsValue(value)){ result.set(i, true); } else { throw new EvaluationException("Expected " + PMMLException.formatValue(FieldValues.CONTINUOUS_DOUBLE_ZERO) + " or " + PMMLException.formatValue(FieldValues.CONTINUOUS_DOUBLE_ONE) + ", got " + PMMLException.formatValue(value)); } } return result; }
static private Map<FieldName, ?> selectAll(List<SegmentResult> segmentResults){ ListMultimap<FieldName, Object> result = ArrayListMultimap.create(); Set<FieldName> keys = null; for(SegmentResult segmentResult : segmentResults){ if(keys == null){ keys = new LinkedHashSet<>(segmentResult.keySet()); } // End if // Ensure that all List values in the ListMultimap contain the same number of elements if(!(keys).equals(segmentResult.keySet())){ Function<Object, String> function = new Function<Object, String>(){ @Override public String apply(Object object){ return PMMLException.formatKey(object); } }; throw new EvaluationException("Field sets " + Iterables.transform(keys, function) + " and " + Iterables.transform(segmentResult.keySet(), function) + " do not match"); } for(FieldName key : keys){ result.put(key, segmentResult.get(key)); } } return result.asMap(); }
static private DataType getDaysDataType(LocalDate epoch){ if((Epochs.YEAR_1960).equals(epoch)){ return DataType.DATE_DAYS_SINCE_1960; } else if((Epochs.YEAR_1970).equals(epoch)){ return DataType.DATE_DAYS_SINCE_1970; } else if((Epochs.YEAR_1980).equals(epoch)){ return DataType.DATE_DAYS_SINCE_1980; } throw new EvaluationException("Non-standard epoch " + epoch); }
static private DataType getSecondsDataType(LocalDate epoch){ if((Epochs.YEAR_1960).equals(epoch)){ return DataType.DATE_TIME_SECONDS_SINCE_1960; } else if((Epochs.YEAR_1970).equals(epoch)){ return DataType.DATE_TIME_SECONDS_SINCE_1970; } else if((Epochs.YEAR_1980).equals(epoch)){ return DataType.DATE_TIME_SECONDS_SINCE_1980; } throw new EvaluationException("Non-standard epoch " + epoch); } }
public void put(String key, Value<V> value){ ValueMap<String, V> values = getValues(); if(values.containsKey(key)){ throw new EvaluationException("Value for key " + PMMLException.formatKey(key) + " has already been defined"); } values.put(key, value); }
static public FieldValue evaluate(DefineFunction defineFunction, List<FieldValue> values, EvaluationContext context){ List<ParameterField> parameterFields = defineFunction.getParameterFields(); if(parameterFields.size() != values.size()){ throw new EvaluationException("Function " + PMMLException.formatKey(defineFunction.getName()) + " expects " + parameterFields.size() + " arguments, got " + values.size() + " arguments"); } DefineFunctionEvaluationContext functionContext = new DefineFunctionEvaluationContext(defineFunction, context); for(int i = 0; i < parameterFields.size(); i++){ ParameterField parameterField = parameterFields.get(i); FieldValue value = values.get(i); FieldName name = parameterField.getName(); if(name == null){ throw new MissingAttributeException(parameterField, PMMLAttributes.PARAMETERFIELD_NAME); } value = value.cast(parameterField.getDataType(), parameterField.getOpType()); functionContext.declare(name, value); } return ExpressionUtil.evaluateTypedExpressionContainer(defineFunction, functionContext); }
private void verify(Object expected, Object actual, double precision, double zeroThreshold){ if(expected == null){ return; } // End if if(!(actual instanceof Collection)){ DataType dataType = TypeUtil.getDataType(actual); expected = TypeUtil.parseOrCast(dataType, expected); } boolean acceptable = VerificationUtil.acceptable(expected, actual, precision, zeroThreshold); if(!acceptable){ throw new EvaluationException("Values " + PMMLException.formatValue(expected) + " and " + PMMLException.formatValue(actual) + " do not match"); } }
private Value<V> computeProbability(String category){ ValueMap<String, V> values = getValues(); if(this.sum == null){ throw new EvaluationException("Vote distribution result has not been computed"); } Value<V> probability = values.get(category); if(probability != null){ probability = probability.copy(); if(this.sum.equals(0d)){ throw new UndefinedResultException(); } probability.divide(this.sum); } return probability; } }
static public FieldValue evaluate(Apply apply, List<FieldValue> values, EvaluationContext context){ String function = apply.getFunction(); if(function == null){ throw new MissingAttributeException(apply, PMMLAttributes.APPLY_FUNCTION); } Function builtInFunction = getFunction(function); if(builtInFunction != null){ return builtInFunction.evaluate(values); } Function userDefinedFunction = FunctionRegistry.getFunction(function); if(userDefinedFunction != null){ return userDefinedFunction.evaluate(values); } DefineFunction defineFunction = context.getDefineFunction(function); if(defineFunction != null){ return evaluate(defineFunction, values, context); } throw new EvaluationException("Function " + PMMLException.formatKey(function) + " is not defined", apply); }
throw new EvaluationException("No PMML data type for the intersection of PMML data types " + left.value() + " and " + right.value());