added parameterized loss functions for reconstruction error loss, refactored some bookeeping at the end of the constructor (and __setstate__) to call a helper function, in the spirit of DRY.