Skip to content

Commit

Permalink
Fixed the encoding of empty nests
Browse files Browse the repository at this point in the history
  • Loading branch information
vruusmann committed Jun 13, 2024
1 parent 11e8ce9 commit 57b946c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pmml-rexp/src/main/java/org/jpmml/rexp/MaxLikConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,14 @@ public Model encodeModel(Schema schema){
Feature nextFeature = toExpFeature(utilityFunctionFeatures.get(nextChoice), encoder);

DerivedField derivedField = encoder.ensureDerivedField(FieldNameUtil.create("term", currentChoice, nextChoice), OpType.CONTINUOUS, DataType.DOUBLE, () -> {
Apply choiceApply = ExpressionUtil.createApply(PMMLFunctions.DIVIDE, currentFeature.ref(), nextFeature.ref());
// Can't divide by zero.
// A division by integer zero raises an invalid result error.
// However, a division by floating-point zero succeeds - the result is a (positive-) infinity.
Apply choiceApply = ExpressionUtil.createApply(PMMLFunctions.IF,
ExpressionUtil.createApply(PMMLFunctions.EQUAL, nextFeature.ref(), ExpressionUtil.createConstant(0d)),
ExpressionUtil.createConstant(0d),
ExpressionUtil.createApply(PMMLFunctions.DIVIDE, currentFeature.ref(), nextFeature.ref())
);

if(lambda.doubleValue() != 1d){
choiceApply = ExpressionUtil.createApply(PMMLFunctions.POW, choiceApply, ExpressionUtil.createConstant(1d / lambda.doubleValue()));
Expand Down

0 comments on commit 57b946c

Please sign in to comment.