cpoerschke commented on a change in pull request #58: URL: https://github.com/apache/solr/pull/58#discussion_r629292545
########## 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; + } + } + } + + private static String explainNode(float[] featureVector, RegressionTreeNode regressionTreeNode) { + StringBuilder returnValueBuilder = new StringBuilder(); + while(true) { Review comment: minor: ```suggestion final StringBuilder returnValueBuilder = new StringBuilder(); while (true) { ``` -- 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