Optimizing bayesian model