BUG: optimize: fix issues related to line searches

This PR does the following:

- Deal properly with failing line searches.
- Convert fmin_ncg to use wolfe criterion (see [Trac #1778](http://projects.scipy.org/scipy/ticket/1778)).
- Clean up some magic numbers away from the code.
- Make `line_search_wolfe2` to actually signal a failure if it doesn't manage to find a suitable step length. Previously, it would just return some small number in the case of a failure.

The code is unfortunately a bit light on tests, so some careful review is warranted here.