Automatic Derivation of Statistical Algorithms: The EM Family and Beyond