Compiling Bayesian Networks