cpoerschke commented on a change in pull request #58: URL: https://github.com/apache/solr/pull/58#discussion_r629312321
########## 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: Actually, since both `left` and `right` need validating the `regressionTreeNode = regressionTreeNode.leftOrRight;` pattern to remove recursion seems problematic? If a node had either left or right then it would work but if it has both then we're missing out on validation for part of the tree. -- 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