{"action":"created","comment":{"url":"https://api.github.com/repos/scipy/scipy/pulls/comments/76047199","id":76047199,"diff_hunk":"@@ -517,6 +517,82 @@ def test_maxfev_and_bounds(self):\n         assert_allclose(popt1, 2, atol=1e-14)\n         assert_allclose(popt2, 2, atol=1e-14)\n \n+    def test_curvefit_simplecovariance(self):\n+\n+        def func(x, a, b):\n+            return a * np.exp(-b*x)\n+\n+        def jac(x, a, b):\n+            e = np.exp(-b*x)\n+            return np.vstack((e, -a * x * e)).T\n+\n+        np.random.seed(0)\n+        xdata = np.linspace(0, 4, 50)\n+        y = func(xdata, 2.5, 1.3)\n+        ydata = y + 0.2 * np.random.normal(size=len(xdata))\n+\n+        sigma = np.zeros(len(xdata)) + 0.2\n+        covar = np.diag(sigma**2)\n+\n+        for usejacobian in [True, False]:\n+            if not usejacobian:\n+                jac = None\n+\n+            popt1, pcov1 = curve_fit(func, xdata, ydata, sigma=sigma,\n+                    jac=jac, absolute_sigma=True)\n+            popt2, pcov2 = curve_fit(func, xdata, ydata, sigma=covar,\n+                    jac=jac, absolute_sigma=True)\n+\n+            assert_allclose(popt1, popt2, atol=1e-14)\n+            assert_allclose(pcov1, pcov2, atol=1e-14)\n+\n+    def test_curvefit_covariance(self):\n+\n+        def funcp(x, a, b):\n+            rotn = np.array([[1./np.sqrt(2), -1./np.sqrt(2), 0], [1./np.sqrt(2), 1./np.sqrt(2), 0], [0, 0, 1.0]])\n+            return rotn.dot(a * np.exp(-b*x))\n+\n+        def jacp(x, a, b):\n+            rotn = np.array([[1./np.sqrt(2), -1./np.sqrt(2), 0], [1./np.sqrt(2), 1./np.sqrt(2), 0], [0, 0, 1.0]])\n+            e = np.exp(-b*x)\n+            return rotn.dot(np.vstack((e, -a * x * e)).T)\n+\n+        def func(x, a, b):\n+            return a * np.exp(-b*x)\n+\n+        def jac(x, a, b):\n+            e = np.exp(-b*x)\n+            return np.vstack((e, -a * x * e)).T\n+\n+        np.random.seed(0)\n+        xdata = np.arange(1, 4)\n+        y = func(xdata, 2.5, 1.0)\n+        ydata = y + 0.2 * np.random.normal(size=len(xdata))\n+        sigma = np.zeros(len(xdata)) + 0.2\n+        covar = np.diag(sigma**2)\n+        # Get a rotation matrix, and obtain ydatap = R ydata\n+        # Chisq = ydata^T C^{-1} ydata\n+        #       = ydata^T R^T R C^{-1} R^T R ydata\n+        #       = ydatap^T Cp^{-1} ydatap\n+        # Cp^{-1} = R C^{-1} R^T\n+        # Cp      = R C R^T, since R^-1 = R^T\n+        rotn = np.array([[1./np.sqrt(2), -1./np.sqrt(2), 0], [1./np.sqrt(2), 1./np.sqrt(2), 0], [0, 0, 1.0]])\n+        ydatap = rotn.dot(ydata)\n+        covarp = rotn.dot(covar).dot(rotn.T)\n+\n+        for usejacobian in [True, False]:","path":"scipy/optimize/tests/test_minpack.py","position":67,"original_position":67,"commit_id":"5f147ff6dfd803980485cd991beceaec73cd7616","original_commit_id":"5f147ff6dfd803980485cd991beceaec73cd7616","user":{"login":"nmayorov","id":7074023,"avatar_url":"https://avatars.githubusercontent.com/u/7074023?v=3","gravatar_id":"","url":"https://api.github.com/users/nmayorov","html_url":"https://github.com/nmayorov","followers_url":"https://api.github.com/users/nmayorov/followers","following_url":"https://api.github.com/users/nmayorov/following{/other_user}","gists_url":"https://api.github.com/users/nmayorov/gists{/gist_id}","starred_url":"https://api.github.com/users/nmayorov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nmayorov/subscriptions","organizations_url":"https://api.github.com/users/nmayorov/orgs","repos_url":"https://api.github.com/users/nmayorov/repos","events_url":"https://api.github.com/users/nmayorov/events{/privacy}","received_events_url":"https://api.github.com/users/nmayorov/received_events","type":"User","site_admin":false},"body":"What I suggest:\r\n\r\n```\r\nfor jac1, jac2 in [(jac, jacp), (None, None)]:\r\n  for absolute_sigma in [False, True]:\r\n    # The existing code goes here.\r\n```\r\n\r\nAnd similar for the function above.","created_at":"2016-08-24T12:33:14Z","updated_at":"2016-08-24T12:33:14Z","html_url":"https://github.com/scipy/scipy/pull/6493#discussion_r76047199","pull_request_url":"https://api.github.com/repos/scipy/scipy/pulls/6493","_links":{"self":{"href":"https://api.github.com/repos/scipy/scipy/pulls/comments/76047199"},"html":{"href":"https://github.com/scipy/scipy/pull/6493#discussion_r76047199"},"pull_request":{"href":"https://api.github.com/repos/scipy/scipy/pulls/6493"}}},"pull_request":{"url":"https://api.github.com/repos/scipy/scipy/pulls/6493","id":81611652,"html_url":"https://github.com/scipy/scipy/pull/6493","diff_url":"https://github.com/scipy/scipy/pull/6493.diff","patch_url":"https://github.com/scipy/scipy/pull/6493.patch","issue_url":"https://api.github.com/repos/scipy/scipy/issues/6493","number":6493,"state":"open","locked":false,"title":"Adds covariance argument to scipy.optimize.curve_fit","user":{"login":"surhudm","id":4392633,"avatar_url":"https://avatars.githubusercontent.com/u/4392633?v=3","gravatar_id":"","url":"https://api.github.com/users/surhudm","html_url":"https://github.com/surhudm","followers_url":"https://api.github.com/users/surhudm/followers","following_url":"https://api.github.com/users/surhudm/following{/other_user}","gists_url":"https://api.github.com/users/surhudm/gists{/gist_id}","starred_url":"https://api.github.com/users/surhudm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/surhudm/subscriptions","organizations_url":"https://api.github.com/users/surhudm/orgs","repos_url":"https://api.github.com/users/surhudm/repos","events_url":"https://api.github.com/users/surhudm/events{/privacy}","received_events_url":"https://api.github.com/users/surhudm/received_events","type":"User","site_admin":false},"body":"The current version of curve_fit does not support data with covariant errors. This pull request modifies curve_fit to account for covariant errors.","created_at":"2016-08-17T09:35:52Z","updated_at":"2016-08-24T12:33:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3518691dcf0c559442205d6967b74c61f10ae59d","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/scipy/scipy/pulls/6493/commits","review_comments_url":"https://api.github.com/repos/scipy/scipy/pulls/6493/comments","review_comment_url":"https://api.github.com/repos/scipy/scipy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/scipy/scipy/issues/6493/comments","statuses_url":"https://api.github.com/repos/scipy/scipy/statuses/5f147ff6dfd803980485cd991beceaec73cd7616","head":{"label":"surhudm:master","ref":"master","sha":"5f147ff6dfd803980485cd991beceaec73cd7616","user":{"login":"surhudm","id":4392633,"avatar_url":"https://avatars.githubusercontent.com/u/4392633?v=3","gravatar_id":"","url":"https://api.github.com/users/surhudm","html_url":"https://github.com/surhudm","followers_url":"https://api.github.com/users/surhudm/followers","following_url":"https://api.github.com/users/surhudm/following{/other_user}","gists_url":"https://api.github.com/users/surhudm/gists{/gist_id}","starred_url":"https://api.github.com/users/surhudm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/surhudm/subscriptions","organizations_url":"https://api.github.com/users/surhudm/orgs","repos_url":"https://api.github.com/users/surhudm/repos","events_url":"https://api.github.com/users/surhudm/events{/privacy}","received_events_url":"https://api.github.com/users/surhudm/received_events","type":"User","site_admin":false},"repo":{"id":65878995,"name":"scipy","full_name":"surhudm/scipy","owner":{"login":"surhudm","id":4392633,"avatar_url":"https://avatars.githubusercontent.com/u/4392633?v=3","gravatar_id":"","url":"https://api.github.com/users/surhudm","html_url":"https://github.com/surhudm","followers_url":"https://api.github.com/users/surhudm/followers","following_url":"https://api.github.com/users/surhudm/following{/other_user}","gists_url":"https://api.github.com/users/surhudm/gists{/gist_id}","starred_url":"https://api.github.com/users/surhudm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/surhudm/subscriptions","organizations_url":"https://api.github.com/users/surhudm/orgs","repos_url":"https://api.github.com/users/surhudm/repos","events_url":"https://api.github.com/users/surhudm/events{/privacy}","received_events_url":"https://api.github.com/users/surhudm/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/surhudm/scipy","description":"Scipy library main repository","fork":true,"url":"https://api.github.com/repos/surhudm/scipy","forks_url":"https://api.github.com/repos/surhudm/scipy/forks","keys_url":"https://api.github.com/repos/surhudm/scipy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/surhudm/scipy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/surhudm/scipy/teams","hooks_url":"https://api.github.com/repos/surhudm/scipy/hooks","issue_events_url":"https://api.github.com/repos/surhudm/scipy/issues/events{/number}","events_url":"https://api.github.com/repos/surhudm/scipy/events","assignees_url":"https://api.github.com/repos/surhudm/scipy/assignees{/user}","branches_url":"https://api.github.com/repos/surhudm/scipy/branches{/branch}","tags_url":"https://api.github.com/repos/surhudm/scipy/tags","blobs_url":"https://api.github.com/repos/surhudm/scipy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/surhudm/scipy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/surhudm/scipy/git/refs{/sha}","trees_url":"https://api.github.com/repos/surhudm/scipy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/surhudm/scipy/statuses/{sha}","languages_url":"https://api.github.com/repos/surhudm/scipy/languages","stargazers_url":"https://api.github.com/repos/surhudm/scipy/stargazers","contributors_url":"https://api.github.com/repos/surhudm/scipy/contributors","subscribers_url":"https://api.github.com/repos/surhudm/scipy/subscribers","subscription_url":"https://api.github.com/repos/surhudm/scipy/subscription","commits_url":"https://api.github.com/repos/surhudm/scipy/commits{/sha}","git_commits_url":"https://api.github.com/repos/surhudm/scipy/git/commits{/sha}","comments_url":"https://api.github.com/repos/surhudm/scipy/comments{/number}","issue_comment_url":"https://api.github.com/repos/surhudm/scipy/issues/comments{/number}","contents_url":"https://api.github.com/repos/surhudm/scipy/contents/{+path}","compare_url":"https://api.github.com/repos/surhudm/scipy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/surhudm/scipy/merges","archive_url":"https://api.github.com/repos/surhudm/scipy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/surhudm/scipy/downloads","issues_url":"https://api.github.com/repos/surhudm/scipy/issues{/number}","pulls_url":"https://api.github.com/repos/surhudm/scipy/pulls{/number}","milestones_url":"https://api.github.com/repos/surhudm/scipy/milestones{/number}","notifications_url":"https://api.github.com/repos/surhudm/scipy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/surhudm/scipy/labels{/name}","releases_url":"https://api.github.com/repos/surhudm/scipy/releases{/id}","deployments_url":"https://api.github.com/repos/surhudm/scipy/deployments","created_at":"2016-08-17T05:39:40Z","updated_at":"2016-08-17T05:39:51Z","pushed_at":"2016-08-24T12:04:09Z","git_url":"git://github.com/surhudm/scipy.git","ssh_url":"git@github.com:surhudm/scipy.git","clone_url":"https://github.com/surhudm/scipy.git","svn_url":"https://github.com/surhudm/scipy","homepage":"http://scipy.org/scipylib/","size":59714,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"scipy:master","ref":"master","sha":"1674c3a27ec4319972ce480f2cf0494adcc52097","user":{"login":"scipy","id":288277,"avatar_url":"https://avatars.githubusercontent.com/u/288277?v=3","gravatar_id":"","url":"https://api.github.com/users/scipy","html_url":"https://github.com/scipy","followers_url":"https://api.github.com/users/scipy/followers","following_url":"https://api.github.com/users/scipy/following{/other_user}","gists_url":"https://api.github.com/users/scipy/gists{/gist_id}","starred_url":"https://api.github.com/users/scipy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scipy/subscriptions","organizations_url":"https://api.github.com/users/scipy/orgs","repos_url":"https://api.github.com/users/scipy/repos","events_url":"https://api.github.com/users/scipy/events{/privacy}","received_events_url":"https://api.github.com/users/scipy/received_events","type":"Organization","site_admin":false},"repo":{"id":1460385,"name":"scipy","full_name":"scipy/scipy","owner":{"login":"scipy","id":288277,"avatar_url":"https://avatars.githubusercontent.com/u/288277?v=3","gravatar_id":"","url":"https://api.github.com/users/scipy","html_url":"https://github.com/scipy","followers_url":"https://api.github.com/users/scipy/followers","following_url":"https://api.github.com/users/scipy/following{/other_user}","gists_url":"https://api.github.com/users/scipy/gists{/gist_id}","starred_url":"https://api.github.com/users/scipy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scipy/subscriptions","organizations_url":"https://api.github.com/users/scipy/orgs","repos_url":"https://api.github.com/users/scipy/repos","events_url":"https://api.github.com/users/scipy/events{/privacy}","received_events_url":"https://api.github.com/users/scipy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/scipy/scipy","description":"Scipy library main repository","fork":false,"url":"https://api.github.com/repos/scipy/scipy","forks_url":"https://api.github.com/repos/scipy/scipy/forks","keys_url":"https://api.github.com/repos/scipy/scipy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/scipy/scipy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/scipy/scipy/teams","hooks_url":"https://api.github.com/repos/scipy/scipy/hooks","issue_events_url":"https://api.github.com/repos/scipy/scipy/issues/events{/number}","events_url":"https://api.github.com/repos/scipy/scipy/events","assignees_url":"https://api.github.com/repos/scipy/scipy/assignees{/user}","branches_url":"https://api.github.com/repos/scipy/scipy/branches{/branch}","tags_url":"https://api.github.com/repos/scipy/scipy/tags","blobs_url":"https://api.github.com/repos/scipy/scipy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/scipy/scipy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/scipy/scipy/git/refs{/sha}","trees_url":"https://api.github.com/repos/scipy/scipy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/scipy/scipy/statuses/{sha}","languages_url":"https://api.github.com/repos/scipy/scipy/languages","stargazers_url":"https://api.github.com/repos/scipy/scipy/stargazers","contributors_url":"https://api.github.com/repos/scipy/scipy/contributors","subscribers_url":"https://api.github.com/repos/scipy/scipy/subscribers","subscription_url":"https://api.github.com/repos/scipy/scipy/subscription","commits_url":"https://api.github.com/repos/scipy/scipy/commits{/sha}","git_commits_url":"https://api.github.com/repos/scipy/scipy/git/commits{/sha}","comments_url":"https://api.github.com/repos/scipy/scipy/comments{/number}","issue_comment_url":"https://api.github.com/repos/scipy/scipy/issues/comments{/number}","contents_url":"https://api.github.com/repos/scipy/scipy/contents/{+path}","compare_url":"https://api.github.com/repos/scipy/scipy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/scipy/scipy/merges","archive_url":"https://api.github.com/repos/scipy/scipy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/scipy/scipy/downloads","issues_url":"https://api.github.com/repos/scipy/scipy/issues{/number}","pulls_url":"https://api.github.com/repos/scipy/scipy/pulls{/number}","milestones_url":"https://api.github.com/repos/scipy/scipy/milestones{/number}","notifications_url":"https://api.github.com/repos/scipy/scipy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/scipy/scipy/labels{/name}","releases_url":"https://api.github.com/repos/scipy/scipy/releases{/id}","deployments_url":"https://api.github.com/repos/scipy/scipy/deployments","created_at":"2011-03-09T18:52:03Z","updated_at":"2016-08-24T11:37:35Z","pushed_at":"2016-08-24T12:04:12Z","git_url":"git://github.com/scipy/scipy.git","ssh_url":"git@github.com:scipy/scipy.git","clone_url":"https://github.com/scipy/scipy.git","svn_url":"https://github.com/scipy/scipy","homepage":"http://scipy.org/scipylib/","size":76439,"stargazers_count":2537,"watchers_count":2537,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1466,"mirror_url":null,"open_issues_count":949,"forks":1466,"open_issues":949,"watchers":2537,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scipy/scipy/pulls/6493"},"html":{"href":"https://github.com/scipy/scipy/pull/6493"},"issue":{"href":"https://api.github.com/repos/scipy/scipy/issues/6493"},"comments":{"href":"https://api.github.com/repos/scipy/scipy/issues/6493/comments"},"review_comments":{"href":"https://api.github.com/repos/scipy/scipy/pulls/6493/comments"},"review_comment":{"href":"https://api.github.com/repos/scipy/scipy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/scipy/scipy/pulls/6493/commits"},"statuses":{"href":"https://api.github.com/repos/scipy/scipy/statuses/5f147ff6dfd803980485cd991beceaec73cd7616"}}}}
{"actor":{"display_login":"nmayorov"}}