cpoerschke commented on a change in pull request #58: URL: https://github.com/apache/solr/pull/58#discussion_r629289913
########## File path: solr/contrib/ltr/src/java/org/apache/solr/ltr/model/MultipleAdditiveTreesModel.java ########## @@ -345,6 +281,80 @@ public float score(float[] modelFeatureValuesNormalized) { return score; } + private static float scoreNode(float[] featureVector, RegressionTreeNode regressionTreeNode) { + while (true) { + if (regressionTreeNode.isLeaf()) { + return regressionTreeNode.value; + } + // unsupported feature (tree is looking for a feature that does not exist) + if ((regressionTreeNode.featureIndex < 0) || (regressionTreeNode.featureIndex >= featureVector.length)) { + return 0f; + } + + if (featureVector[regressionTreeNode.featureIndex] <= regressionTreeNode.threshold) { + regressionTreeNode = regressionTreeNode.left; + } else { + regressionTreeNode = regressionTreeNode.right; + } + } + } + + private static void validateNode(RegressionTreeNode regressionTreeNode) throws ModelException { + while (true) { + if (regressionTreeNode.isLeaf()) { + if (regressionTreeNode.left != null || regressionTreeNode.right != null) { + throw new ModelException("MultipleAdditiveTreesModel tree node is leaf with left=" + regressionTreeNode.left + " and right=" + regressionTreeNode.right); + } + return; + } + if (null == regressionTreeNode.threshold) { + throw new ModelException("MultipleAdditiveTreesModel tree node is missing threshold"); + } + if (null == regressionTreeNode.left) { + throw new ModelException("MultipleAdditiveTreesModel tree node is missing left"); + } else { + regressionTreeNode = regressionTreeNode.left; + } + if (null == regressionTreeNode.right) { + throw new ModelException("MultipleAdditiveTreesModel tree node is missing right"); + } else { + regressionTreeNode = regressionTreeNode.right; + } Review comment: ```suggestion if (null == regressionTreeNode.left) { throw new ModelException("MultipleAdditiveTreesModel tree node is missing left"); } else { regressionTreeNode = regressionTreeNode.left; continue; } if (null == regressionTreeNode.right) { throw new ModelException("MultipleAdditiveTreesModel tree node is missing right"); } else { regressionTreeNode = regressionTreeNode.right; continue; } ``` I think a `continue` is needed after the `regressionTreeNode = regressionTreeNode.left` and whilst it's not necessary currently after the `regressionTreeNode = regressionTreeNode.right` it might be nicely symmetrical to have it there too e.g. in case additional validation is added in future after the `regressionTreeNode = regressionTreeNode.right` assignment. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org