A general framework for defining and optimizing robustness