Closed OnlyFor closed 5 years ago
Exception in thread "main" java.lang.ArithmeticException: integer overflow
The JPMML-Evaluator library uses Java's 32-bit int
/java.lang.Integer
to represent PMML integer data type values. This is fine for the majority of cases, but there seem to be a number edge cases where Java's 64-bit long
/java.lang.Long
would be required instead.
In your case, one of the inputs is a PMML double value, does not fit into Java's java.lang.Integer
after rounding.
but everything just fine in 1.4.7?
The most likely explanation is that the 1.4.7 version simply didn't perform integer bounds checking (which lead to incorrect prediction).
Closing this issue as a duplicate of https://github.com/jpmml/jpmml-evaluator/issues/141
@OnlyFor In your code there's an expression x_int = round(x_double) / 1000
; the integer overflow exception happens during the round(x_double)
part.
Wouldn't it be possible (ie. functionally identical given the true nature of the x_double
variable) to do the division by 1000 before rounding (x_int = round(x_double / 1000d)
)?
But I am pretty sure the results of 1.4.7 is correct, and the reason of * & / 1000 is to keep 3 decimal after rounding, as same as round(x, 3) in other languages
But I am pretty sure the results of 1.4.7 is correct
Perhaps the integer overflow happened with reason codes that did not emerge as the "winner" in the end.
You could tweak the current 1.4-SNAPSHOT
codebase, and simply do return result
(instead of return Math.toIntExact(result)
) here:
https://github.com/jpmml/jpmml-evaluator/blob/master/pmml-evaluator/src/main/java/org/jpmml/evaluator/Functions.java#L309
Are you still seeing successful/correct predictions then?
the reason of * & / 1000 is to keep 3 decimal after rounding, as same as round(x, 3) in other languages
The PMML standard only provides "fixed precision" round function. To emulate arbitrary precision rounding, then you could try using the formatNumber
function instead: http://dmg.org/pmml/v4-3/BuiltinFunctions.html#formatnumber
Something like this:
<DerivedField name="round(x, 3)" dataType="double">
<Apply function="formatNumber">
<FieldRef field="x"/>
<Constant dataType="string">0.000</Constant> <!-- check this pattern! -->
</Apply>
</DerivedField>
thx !
i fix this problem by using something like:
when i use 1.4.13 example,
java -cp pmml-evaluator-example-executable-1.4.13.jar org.jpmml.evaluator.EvaluationExample --model Model_test8-train-test2_score.xml --input input.csv --output output.csv --missing-values "" --separator ","
but everything just fine in 1.4.7 ? files.zip
i use round in scorecard model