A magic compute_tree_prob/loss based on https://gist.github.com/ddemidov/10846799