added gradients to the optimization problem in example.R; still working on empirical.R