Generalized Invariant Risk Minimization: relating adaptation and invariant representation learning