Gradient methods for minimizing composite functions