[SciPy-User] Optimiation does nothing

Philipp A. flying-sheep at web.de
Mon Dec 9 06:30:36 EST 2013


Hi Alex,

thank you very much for helping me here! could you please tell me why you
chose pinvh here, and whats the difference between it, numpy.linalg.inv and
scipy.linmalg.inv?

Best regards, Philipp


2013/12/8 alex <argriffi at ncsu.edu>

> > Hi,
> >
> > i’m trying to use scipy’s optimization using a negative loglikelihood
> > function, but it immediately “converges” with a gradient of 1e+23.
> >
> > here’s the notebook if you could have a look:
> > http://nbviewer.ipython.org/gist/flying-sheep/7806554 (just ignore the
> > data, code is after that)
> >
> > as you can see, matlab’s fmincon found a much better solution,
> > and there’s no bug in my loglikelihood function
> > (i use scipy 1.14’s multivariate normal log-probability density function,
> > and it indeed rates matlabs optimum better)
> >
> > what should i modify to make the optimizer do its job?
> >
> > best regards, philipp
>
> Hi Philipp,
>
> I'm glad to see that this new scipy function is being used!  Here's a
> code snippet that will reproduce your matlab answer
>
> -----
>
> import numpy as np
>
> from scipy.stats import multivariate_normal
> from scipy import optimize
> import scipy
>
> from mydata import data1, data2
>
> def neg_ll(X):
>     lam, x2, y2, x1, y1 = X
>     ll_total = 0
>     for x, y, data in ((x1, y1, data1), (x2, y2, data2)):
>         prec = np.array([
>             [x*x, x*y*np.cos(lam)],
>             [x*y*np.cos(lam), y*y]])
>         cov = scipy.linalg.pinvh(prec)
>         ll = multivariate_normal.logpdf(data, np.mean(data, 0), cov).sum()
>         ll_total += ll
>     return -ll_total
>
> guess = np.ones(5)
> optx, opty, info = optimize.fmin_l_bfgs_b(neg_ll, guess, approx_grad=True)
>
> print 'scipy optimize info:'
> print optx
> print opty
> print info
>
> -----
>
> Best,
> Alex
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20131209/64ce8d42/attachment.html>


More information about the SciPy-User mailing list