cpoerschke commented on a change in pull request #58:
URL: https://github.com/apache/solr/pull/58#discussion_r633675080



##########
File path: 
solr/contrib/ltr/src/java/org/apache/solr/ltr/model/MultipleAdditiveTreesModel.java
##########
@@ -345,6 +282,87 @@ 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 {
+    
+    // Create an empty stack and push root to it
+    Stack<RegressionTreeNode> stack = new Stack<RegressionTreeNode>();
+    stack.push(regressionTreeNode);
+
+    while (stack.empty() == false) {
+      RegressionTreeNode topStackNode = stack.pop();
+
+      if (topStackNode.isLeaf()) {
+        if (topStackNode.left != null || topStackNode.right != null) {
+          throw new ModelException("MultipleAdditiveTreesModel tree node is 
leaf with left=" + topStackNode.left + " and right=" + topStackNode.right);
+        }
+        return;
+      }

Review comment:
       ```suggestion
           continue;
         }
   ```
   
   or
   
   ```suggestion
         } else {
           ...
         }
   ```




-- 
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

Reply via email to