Derived gradient for sparsity.