{"action":"created","issue":{"url":"https://api.github.com/repos/scipy/scipy/issues/4555","labels_url":"https://api.github.com/repos/scipy/scipy/issues/4555/labels{/name}","comments_url":"https://api.github.com/repos/scipy/scipy/issues/4555/comments","events_url":"https://api.github.com/repos/scipy/scipy/issues/4555/events","html_url":"https://github.com/scipy/scipy/issues/4555","id":58792230,"number":4555,"title":"leastsq should use cholesky not inv for hessian inversion","user":{"login":"pv","id":35046,"avatar_url":"https://avatars.githubusercontent.com/u/35046?v=3","gravatar_id":"","url":"https://api.github.com/users/pv","html_url":"https://github.com/pv","followers_url":"https://api.github.com/users/pv/followers","following_url":"https://api.github.com/users/pv/following{/other_user}","gists_url":"https://api.github.com/users/pv/gists{/gist_id}","starred_url":"https://api.github.com/users/pv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pv/subscriptions","organizations_url":"https://api.github.com/users/pv/orgs","repos_url":"https://api.github.com/users/pv/repos","events_url":"https://api.github.com/users/pv/events{/privacy}","received_events_url":"https://api.github.com/users/pv/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-02-24T19:36:55Z","updated_at":"2015-02-24T19:52:41Z","closed_at":null,"body":"The covariance estimate in `leastsq` in is computed using `inv`: https://github.com/scipy/scipy/blob/master/scipy/optimize/minpack.py#L437\r\n```\r\ncov_x = inv(dot(transpose(R), R))\r\n```\r\nHowever, if the condition number is bad, this can lose positive definitiness. This should use cholesky instead, AFAICS. The result will probably garbage in and out, but PD garbage is probably better than negative variances...\r\n\r\nApparently it is this issue that causes confusion here:\r\nhttps://stackoverflow.com/questions/28702631/scipy-curve-fit-returns-negative-variance/28704611"},"comment":{"url":"https://api.github.com/repos/scipy/scipy/issues/comments/75832175","html_url":"https://github.com/scipy/scipy/issues/4555#issuecomment-75832175","issue_url":"https://api.github.com/repos/scipy/scipy/issues/4555","id":75832175,"user":{"login":"charris","id":77272,"avatar_url":"https://avatars.githubusercontent.com/u/77272?v=3","gravatar_id":"","url":"https://api.github.com/users/charris","html_url":"https://github.com/charris","followers_url":"https://api.github.com/users/charris/followers","following_url":"https://api.github.com/users/charris/following{/other_user}","gists_url":"https://api.github.com/users/charris/gists{/gist_id}","starred_url":"https://api.github.com/users/charris/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/charris/subscriptions","organizations_url":"https://api.github.com/users/charris/orgs","repos_url":"https://api.github.com/users/charris/repos","events_url":"https://api.github.com/users/charris/events{/privacy}","received_events_url":"https://api.github.com/users/charris/received_events","type":"User","site_admin":false},"created_at":"2015-02-24T19:52:41Z","updated_at":"2015-02-24T19:52:41Z","body":"Maybe invert `r` (it's upper triangular), then apply `perm`. This gives a factorization of `cov_x`. It may not be positive definite unless regularized, I think, as `leastsq` still sort of works when the result does not depend on one of the variables due to symmetry. "}}