The principles of adaptation in organisms and machines I: machine learning, information theory, and thermodynamics