Derivation of Generalized Master Equations