grf-labs / policytree

Policy learning via doubly robust empirical welfare maximization over trees
https://grf-labs.github.io/policytree/
MIT License
74 stars 15 forks source link

Predict same leaf labels as printed labels with hybrid policytree #153

Closed erikcs closed 1 year ago

erikcs commented 1 year ago

When calling print on a hybrid_policy_tree leaf nodes are given node labels according to the order in which the hybrid tree is grown, which will be breadth first for each subtree. However, predict with option type = “node.id” would give node labels according to an “ordinary” breadth first. This PR fixes the predicted node labels to match up with how they are printed.

This should ideally not be a breaking change for anyone that uses predict(hybrid.tree, type = “node.id”), as the group each observation belongs to is correct, it will just be given a different label that matches up with what’s printed. (i.e. code that relies on sample Xi belonging to group g = A_i will not break as long as it doesn’t rely on whether g is called A_i, “banana”, or 42,...)

(just updating the printed leaf labels for hybrid tree is too much of a hassle, this fix is simpler and should be perfectly fine with the above caveat)