Improve compute_tree_prob and compute_tree_loss based on Denis's comments.