The principles of adaptation in organisms and machines II: Thermodynamics of the Bayesian brain