A Bayesian formulation of behavioral control