Action and Perception as Divergence Minimization