Separate optimization from statistic redux

This is a rebased version of #1914.  I decided to go ahead and make a new PR so that it can easily be run through Travis and the like.  Otherwise no major differences.  Once the CI gives us a green checkmark this should be merged instead of #1914.
Oh yeah, in my refactor of this the custom statistic functions are just as straightforward to implement as in Sherpa.