{"action":"created","comment":{"url":"https://api.github.com/repos/gonum/stat/pulls/comments/56427502","id":56427502,"diff_hunk":"@@ -0,0 +1,53 @@\n+// Copyright ©2016 The gonum Authors. All rights reserved.\n+// Use of this source code is governed by a BSD-style\n+// license that can be found in the LICENSE file.\n+\n+package stat\n+\n+import \"sort\"\n+\n+type ByX struct {\n+\tx []float64\n+\tc []bool\n+}\n+\n+func (a ByX) Len() int { return len(a.x) }\n+func (a ByX) Swap(i, j int) {\n+\ta.x[i], a.x[j] = a.x[j], a.x[i]\n+\ta.c[i], a.c[j] = a.c[j], a.c[i]\n+}\n+func (a ByX) Less(i, j int) bool { return a.x[i] < a.x[j] }\n+\n+\n+// ROC returns paired FPR and TPR values which describe the \n+// ROC curve treating y as a binary classifier for pos.\n+func ROC(y []float64, pos []bool) ([]float64, []float64) {\n+\n+\tif len(y) != len(pos) {\n+\t\tpanic(\"inputs differ in length\")\n+\t}\n+\n+\tsort.Sort(ByX{y, pos})\n+\n+\tvar np float64\n+\ttpr := make([]float64, len(y)+1)\n+\tfpr := make([]float64, len(y)+1)\n+\tfor i, u := range pos {\n+\t\tif u {\n+\t\t\tnp += 1.0\n+\t\t\ttpr[i+1] = tpr[i] + 1.0\n+\t\t\tfpr[i+1] = fpr[i]\n+\t\t} else {\n+\t\t\ttpr[i+1] = tpr[i]\n+\t\t\tfpr[i+1] = fpr[i] + 1.0\n+\t\t}\n+\t}\n+\tnn := float64(len(y)) - np\n+\tfor i, _ := range tpr {","path":"roc.go","position":46,"original_position":46,"commit_id":"e8912267aea639da06959fff704032f010fa85e4","original_commit_id":"e8912267aea639da06959fff704032f010fa85e4","user":{"login":"kortschak","id":275221,"avatar_url":"https://avatars.githubusercontent.com/u/275221?v=3","gravatar_id":"","url":"https://api.github.com/users/kortschak","html_url":"https://github.com/kortschak","followers_url":"https://api.github.com/users/kortschak/followers","following_url":"https://api.github.com/users/kortschak/following{/other_user}","gists_url":"https://api.github.com/users/kortschak/gists{/gist_id}","starred_url":"https://api.github.com/users/kortschak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kortschak/subscriptions","organizations_url":"https://api.github.com/users/kortschak/orgs","repos_url":"https://api.github.com/users/kortschak/repos","events_url":"https://api.github.com/users/kortschak/events{/privacy}","received_events_url":"https://api.github.com/users/kortschak/received_events","type":"User","site_admin":false},"body":"for i := range tpr","created_at":"2016-03-16T22:31:21Z","updated_at":"2016-03-16T22:31:21Z","html_url":"https://github.com/gonum/stat/pull/96#discussion_r56427502","pull_request_url":"https://api.github.com/repos/gonum/stat/pulls/96","_links":{"self":{"href":"https://api.github.com/repos/gonum/stat/pulls/comments/56427502"},"html":{"href":"https://github.com/gonum/stat/pull/96#discussion_r56427502"},"pull_request":{"href":"https://api.github.com/repos/gonum/stat/pulls/96"}}},"pull_request":{"url":"https://api.github.com/repos/gonum/stat/pulls/96","id":63021169,"html_url":"https://github.com/gonum/stat/pull/96","diff_url":"https://github.com/gonum/stat/pull/96.diff","patch_url":"https://github.com/gonum/stat/pull/96.patch","issue_url":"https://api.github.com/repos/gonum/stat/issues/96","number":96,"state":"open","locked":false,"title":"ROC function","user":{"login":"Armadilloa16","id":11642131,"avatar_url":"https://avatars.githubusercontent.com/u/11642131?v=3","gravatar_id":"","url":"https://api.github.com/users/Armadilloa16","html_url":"https://github.com/Armadilloa16","followers_url":"https://api.github.com/users/Armadilloa16/followers","following_url":"https://api.github.com/users/Armadilloa16/following{/other_user}","gists_url":"https://api.github.com/users/Armadilloa16/gists{/gist_id}","starred_url":"https://api.github.com/users/Armadilloa16/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Armadilloa16/subscriptions","organizations_url":"https://api.github.com/users/Armadilloa16/orgs","repos_url":"https://api.github.com/users/Armadilloa16/repos","events_url":"https://api.github.com/users/Armadilloa16/events{/privacy}","received_events_url":"https://api.github.com/users/Armadilloa16/received_events","type":"User","site_admin":false},"body":"Produces a ROC curve.\r\n\r\nI'm pretty new to go, and to software development in general\r\nso I'm in the middle of a pretty steep learning curve -- I thought\r\nI should start with some small, simple contributions as I learn.\r\nAny feedback would be very helpful.\r\n\r\n@kortschak  @btracey please take a look?","created_at":"2016-03-16T06:52:48Z","updated_at":"2016-03-16T22:31:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5476f451534bea38906fd37f90ad5c0d0611d365","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/gonum/stat/pulls/96/commits","review_comments_url":"https://api.github.com/repos/gonum/stat/pulls/96/comments","review_comment_url":"https://api.github.com/repos/gonum/stat/pulls/comments{/number}","comments_url":"https://api.github.com/repos/gonum/stat/issues/96/comments","statuses_url":"https://api.github.com/repos/gonum/stat/statuses/e8912267aea639da06959fff704032f010fa85e4","head":{"label":"Armadilloa16:master","ref":"master","sha":"e8912267aea639da06959fff704032f010fa85e4","user":{"login":"Armadilloa16","id":11642131,"avatar_url":"https://avatars.githubusercontent.com/u/11642131?v=3","gravatar_id":"","url":"https://api.github.com/users/Armadilloa16","html_url":"https://github.com/Armadilloa16","followers_url":"https://api.github.com/users/Armadilloa16/followers","following_url":"https://api.github.com/users/Armadilloa16/following{/other_user}","gists_url":"https://api.github.com/users/Armadilloa16/gists{/gist_id}","starred_url":"https://api.github.com/users/Armadilloa16/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Armadilloa16/subscriptions","organizations_url":"https://api.github.com/users/Armadilloa16/orgs","repos_url":"https://api.github.com/users/Armadilloa16/repos","events_url":"https://api.github.com/users/Armadilloa16/events{/privacy}","received_events_url":"https://api.github.com/users/Armadilloa16/received_events","type":"User","site_admin":false},"repo":{"id":54007172,"name":"stat","full_name":"Armadilloa16/stat","owner":{"login":"Armadilloa16","id":11642131,"avatar_url":"https://avatars.githubusercontent.com/u/11642131?v=3","gravatar_id":"","url":"https://api.github.com/users/Armadilloa16","html_url":"https://github.com/Armadilloa16","followers_url":"https://api.github.com/users/Armadilloa16/followers","following_url":"https://api.github.com/users/Armadilloa16/following{/other_user}","gists_url":"https://api.github.com/users/Armadilloa16/gists{/gist_id}","starred_url":"https://api.github.com/users/Armadilloa16/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Armadilloa16/subscriptions","organizations_url":"https://api.github.com/users/Armadilloa16/orgs","repos_url":"https://api.github.com/users/Armadilloa16/repos","events_url":"https://api.github.com/users/Armadilloa16/events{/privacy}","received_events_url":"https://api.github.com/users/Armadilloa16/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Armadilloa16/stat","description":"Statistics package for Go","fork":true,"url":"https://api.github.com/repos/Armadilloa16/stat","forks_url":"https://api.github.com/repos/Armadilloa16/stat/forks","keys_url":"https://api.github.com/repos/Armadilloa16/stat/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Armadilloa16/stat/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Armadilloa16/stat/teams","hooks_url":"https://api.github.com/repos/Armadilloa16/stat/hooks","issue_events_url":"https://api.github.com/repos/Armadilloa16/stat/issues/events{/number}","events_url":"https://api.github.com/repos/Armadilloa16/stat/events","assignees_url":"https://api.github.com/repos/Armadilloa16/stat/assignees{/user}","branches_url":"https://api.github.com/repos/Armadilloa16/stat/branches{/branch}","tags_url":"https://api.github.com/repos/Armadilloa16/stat/tags","blobs_url":"https://api.github.com/repos/Armadilloa16/stat/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Armadilloa16/stat/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Armadilloa16/stat/git/refs{/sha}","trees_url":"https://api.github.com/repos/Armadilloa16/stat/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Armadilloa16/stat/statuses/{sha}","languages_url":"https://api.github.com/repos/Armadilloa16/stat/languages","stargazers_url":"https://api.github.com/repos/Armadilloa16/stat/stargazers","contributors_url":"https://api.github.com/repos/Armadilloa16/stat/contributors","subscribers_url":"https://api.github.com/repos/Armadilloa16/stat/subscribers","subscription_url":"https://api.github.com/repos/Armadilloa16/stat/subscription","commits_url":"https://api.github.com/repos/Armadilloa16/stat/commits{/sha}","git_commits_url":"https://api.github.com/repos/Armadilloa16/stat/git/commits{/sha}","comments_url":"https://api.github.com/repos/Armadilloa16/stat/comments{/number}","issue_comment_url":"https://api.github.com/repos/Armadilloa16/stat/issues/comments{/number}","contents_url":"https://api.github.com/repos/Armadilloa16/stat/contents/{+path}","compare_url":"https://api.github.com/repos/Armadilloa16/stat/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Armadilloa16/stat/merges","archive_url":"https://api.github.com/repos/Armadilloa16/stat/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Armadilloa16/stat/downloads","issues_url":"https://api.github.com/repos/Armadilloa16/stat/issues{/number}","pulls_url":"https://api.github.com/repos/Armadilloa16/stat/pulls{/number}","milestones_url":"https://api.github.com/repos/Armadilloa16/stat/milestones{/number}","notifications_url":"https://api.github.com/repos/Armadilloa16/stat/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Armadilloa16/stat/labels{/name}","releases_url":"https://api.github.com/repos/Armadilloa16/stat/releases{/id}","deployments_url":"https://api.github.com/repos/Armadilloa16/stat/deployments","created_at":"2016-03-16T06:38:02Z","updated_at":"2016-03-16T06:38:04Z","pushed_at":"2016-03-16T07:22:24Z","git_url":"git://github.com/Armadilloa16/stat.git","ssh_url":"git@github.com:Armadilloa16/stat.git","clone_url":"https://github.com/Armadilloa16/stat.git","svn_url":"https://github.com/Armadilloa16/stat","homepage":"","size":336,"stargazers_count":0,"watchers_count":0,"language":"Go","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":"gonum:master","ref":"master","sha":"12755f6f34a9f05175a174a7da35c7b5f4d15a8d","user":{"login":"gonum","id":3771091,"avatar_url":"https://avatars.githubusercontent.com/u/3771091?v=3","gravatar_id":"","url":"https://api.github.com/users/gonum","html_url":"https://github.com/gonum","followers_url":"https://api.github.com/users/gonum/followers","following_url":"https://api.github.com/users/gonum/following{/other_user}","gists_url":"https://api.github.com/users/gonum/gists{/gist_id}","starred_url":"https://api.github.com/users/gonum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gonum/subscriptions","organizations_url":"https://api.github.com/users/gonum/orgs","repos_url":"https://api.github.com/users/gonum/repos","events_url":"https://api.github.com/users/gonum/events{/privacy}","received_events_url":"https://api.github.com/users/gonum/received_events","type":"Organization","site_admin":false},"repo":{"id":22622955,"name":"stat","full_name":"gonum/stat","owner":{"login":"gonum","id":3771091,"avatar_url":"https://avatars.githubusercontent.com/u/3771091?v=3","gravatar_id":"","url":"https://api.github.com/users/gonum","html_url":"https://github.com/gonum","followers_url":"https://api.github.com/users/gonum/followers","following_url":"https://api.github.com/users/gonum/following{/other_user}","gists_url":"https://api.github.com/users/gonum/gists{/gist_id}","starred_url":"https://api.github.com/users/gonum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gonum/subscriptions","organizations_url":"https://api.github.com/users/gonum/orgs","repos_url":"https://api.github.com/users/gonum/repos","events_url":"https://api.github.com/users/gonum/events{/privacy}","received_events_url":"https://api.github.com/users/gonum/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/gonum/stat","description":"Statistics package for Go","fork":false,"url":"https://api.github.com/repos/gonum/stat","forks_url":"https://api.github.com/repos/gonum/stat/forks","keys_url":"https://api.github.com/repos/gonum/stat/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gonum/stat/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gonum/stat/teams","hooks_url":"https://api.github.com/repos/gonum/stat/hooks","issue_events_url":"https://api.github.com/repos/gonum/stat/issues/events{/number}","events_url":"https://api.github.com/repos/gonum/stat/events","assignees_url":"https://api.github.com/repos/gonum/stat/assignees{/user}","branches_url":"https://api.github.com/repos/gonum/stat/branches{/branch}","tags_url":"https://api.github.com/repos/gonum/stat/tags","blobs_url":"https://api.github.com/repos/gonum/stat/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gonum/stat/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gonum/stat/git/refs{/sha}","trees_url":"https://api.github.com/repos/gonum/stat/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gonum/stat/statuses/{sha}","languages_url":"https://api.github.com/repos/gonum/stat/languages","stargazers_url":"https://api.github.com/repos/gonum/stat/stargazers","contributors_url":"https://api.github.com/repos/gonum/stat/contributors","subscribers_url":"https://api.github.com/repos/gonum/stat/subscribers","subscription_url":"https://api.github.com/repos/gonum/stat/subscription","commits_url":"https://api.github.com/repos/gonum/stat/commits{/sha}","git_commits_url":"https://api.github.com/repos/gonum/stat/git/commits{/sha}","comments_url":"https://api.github.com/repos/gonum/stat/comments{/number}","issue_comment_url":"https://api.github.com/repos/gonum/stat/issues/comments{/number}","contents_url":"https://api.github.com/repos/gonum/stat/contents/{+path}","compare_url":"https://api.github.com/repos/gonum/stat/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gonum/stat/merges","archive_url":"https://api.github.com/repos/gonum/stat/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gonum/stat/downloads","issues_url":"https://api.github.com/repos/gonum/stat/issues{/number}","pulls_url":"https://api.github.com/repos/gonum/stat/pulls{/number}","milestones_url":"https://api.github.com/repos/gonum/stat/milestones{/number}","notifications_url":"https://api.github.com/repos/gonum/stat/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gonum/stat/labels{/name}","releases_url":"https://api.github.com/repos/gonum/stat/releases{/id}","deployments_url":"https://api.github.com/repos/gonum/stat/deployments","created_at":"2014-08-04T23:07:41Z","updated_at":"2016-03-07T21:18:16Z","pushed_at":"2016-03-16T07:23:51Z","git_url":"git://github.com/gonum/stat.git","ssh_url":"git@github.com:gonum/stat.git","clone_url":"https://github.com/gonum/stat.git","svn_url":"https://github.com/gonum/stat","homepage":"","size":385,"stargazers_count":104,"watchers_count":104,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":12,"mirror_url":null,"open_issues_count":14,"forks":12,"open_issues":14,"watchers":104,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/gonum/stat/pulls/96"},"html":{"href":"https://github.com/gonum/stat/pull/96"},"issue":{"href":"https://api.github.com/repos/gonum/stat/issues/96"},"comments":{"href":"https://api.github.com/repos/gonum/stat/issues/96/comments"},"review_comments":{"href":"https://api.github.com/repos/gonum/stat/pulls/96/comments"},"review_comment":{"href":"https://api.github.com/repos/gonum/stat/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/gonum/stat/pulls/96/commits"},"statuses":{"href":"https://api.github.com/repos/gonum/stat/statuses/e8912267aea639da06959fff704032f010fa85e4"}}}}