Generative Flow Networks: Theory and Applications to Structure Learning