Fix scipy.optimise code
working but slow version to due repeated theano compilation