Modified SDAE to work with optimizer