Optimize bayes training algorithm