Learning sparse gradients for variable selection and dimension reduction