An optimization approach to model reduction