suryakant261 commented on a change in pull request #58:
URL: https://github.com/apache/solr/pull/58#discussion_r632742341
##########
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:
Good catch @cpoerschke , thanks for highlighting. In Explain and score
method, we want to traverse only one path from root to leaf based on
featurevalue, however in validate method we want to traverse all nodes of the
tree. So, the approach had to be different, have now updated the approach for
validate method, using a stack and doing preorder traversal.
--
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:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]