{"action":"created","comment":{"url":"https://api.github.com/repos/libmir/mir/pulls/comments/68502134","id":68502134,"diff_hunk":"@@ -0,0 +1,123 @@\n+/**\n+Discrete distributions.\n+\n+License: $(LINK2 http://boost.org/LICENSE_1_0.txt, Boost License 1.0).\n+\n+Authors: Ilya Yaroshenko, Sebastian Wilzbach\n+*/\n+\n+module mir.random.discrete;\n+\n+import std.traits : isNumeric;\n+\n+/**\n+Setup a _discrete distribution sampler.\n+Given an array of cumulative density points `cdPoints`,\n+a _discrete distribution is defined.\n+The cumulative density points can be calculated from probabilities or counts\n+using `std.algorithm.iteration.cumulativeFold`. Hence `cdPoints` is assumed to be sorted.\n+\n+Params:\n+    cdPoints = cumulative density points\n+\n+Returns:\n+    A $(LREF Discrete) sampler that can be called to sample from the distribution.\n+*/\n+Discrete!T discrete(T)(const(T)[] cdPoints)\n+{\n+    return Discrete!T(cdPoints);\n+}\n+\n+///\n+unittest\n+{\n+    // 10%, 20%, 20%, 40%, 10%\n+    auto cdPoints = [0.1, 0.3, 0.5, 0.9, 1];\n+    auto ds = discrete(cdPoints);\n+\n+    // sample from the discrete distribution\n+    auto obs = new uint[cdPoints.length];\n+    foreach (i; 0..1000)\n+        obs[ds()]++;\n+}\n+\n+/**\n+_Discrete distribution sampler that draws random values from a _discrete\n+distribution given an array of the respective cumulative density points.\n+`cdPoints` is an array of the cummulative sum over the probabilities\n+or counts of a _discrete distribution without a starting zero.\n+\n+Complexity: O(log n) where n is the number of `cdPoints`.\n+*/\n+struct Discrete(T)","path":"source/mir/random/discrete.d","position":52,"original_position":52,"commit_id":"7562bb4c0505358c90e3238ede19335c82e47954","original_commit_id":"7562bb4c0505358c90e3238ede19335c82e47954","user":{"login":"WebDrake","id":125075,"avatar_url":"https://avatars.githubusercontent.com/u/125075?v=3","gravatar_id":"","url":"https://api.github.com/users/WebDrake","html_url":"https://github.com/WebDrake","followers_url":"https://api.github.com/users/WebDrake/followers","following_url":"https://api.github.com/users/WebDrake/following{/other_user}","gists_url":"https://api.github.com/users/WebDrake/gists{/gist_id}","starred_url":"https://api.github.com/users/WebDrake/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WebDrake/subscriptions","organizations_url":"https://api.github.com/users/WebDrake/orgs","repos_url":"https://api.github.com/users/WebDrake/repos","events_url":"https://api.github.com/users/WebDrake/events{/privacy}","received_events_url":"https://api.github.com/users/WebDrake/received_events","type":"User","site_admin":false},"body":"Well, if you want to take a look: https://github.com/WebDrake/hap/blob/e25fc15a17e4e439333740d2a9894fc7d3c94012/source/hap/random/distribution.d#L232\r\n\r\nNote there are things that won't be useful here (it's a class, it's a forward range...) but it should be straightforward to take most of the good bits and use them with the functor-based approach here.","created_at":"2016-06-26T12:16:22Z","updated_at":"2016-06-26T12:16:22Z","html_url":"https://github.com/libmir/mir/pull/234#discussion_r68502134","pull_request_url":"https://api.github.com/repos/libmir/mir/pulls/234","_links":{"self":{"href":"https://api.github.com/repos/libmir/mir/pulls/comments/68502134"},"html":{"href":"https://github.com/libmir/mir/pull/234#discussion_r68502134"},"pull_request":{"href":"https://api.github.com/repos/libmir/mir/pulls/234"}}},"pull_request":{"url":"https://api.github.com/repos/libmir/mir/pulls/234","id":75215993,"html_url":"https://github.com/libmir/mir/pull/234","diff_url":"https://github.com/libmir/mir/pull/234.diff","patch_url":"https://github.com/libmir/mir/pull/234.patch","issue_url":"https://api.github.com/repos/libmir/mir/issues/234","number":234,"state":"closed","locked":false,"title":"Add std.random.discrete: Discrete sampler","user":{"login":"wilzbach","id":4370550,"avatar_url":"https://avatars.githubusercontent.com/u/4370550?v=3","gravatar_id":"","url":"https://api.github.com/users/wilzbach","html_url":"https://github.com/wilzbach","followers_url":"https://api.github.com/users/wilzbach/followers","following_url":"https://api.github.com/users/wilzbach/following{/other_user}","gists_url":"https://api.github.com/users/wilzbach/gists{/gist_id}","starred_url":"https://api.github.com/users/wilzbach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wilzbach/subscriptions","organizations_url":"https://api.github.com/users/wilzbach/orgs","repos_url":"https://api.github.com/users/wilzbach/repos","events_url":"https://api.github.com/users/wilzbach/events{/privacy}","received_events_url":"https://api.github.com/users/wilzbach/received_events","type":"User","site_admin":false},"body":"[preview docs](http://preview.mir.rocks/mir_random_discrete.html)","created_at":"2016-06-25T22:29:34Z","updated_at":"2016-06-26T12:16:22Z","closed_at":"2016-06-26T10:30:54Z","merged_at":"2016-06-26T10:30:54Z","merge_commit_sha":"b6c255f0ef3dfe167a56324eaae33cedc4d668c3","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/libmir/mir/pulls/234/commits","review_comments_url":"https://api.github.com/repos/libmir/mir/pulls/234/comments","review_comment_url":"https://api.github.com/repos/libmir/mir/pulls/comments{/number}","comments_url":"https://api.github.com/repos/libmir/mir/issues/234/comments","statuses_url":"https://api.github.com/repos/libmir/mir/statuses/7562bb4c0505358c90e3238ede19335c82e47954","head":{"label":"wilzbach:mixture","ref":"mixture","sha":"7562bb4c0505358c90e3238ede19335c82e47954","user":{"login":"wilzbach","id":4370550,"avatar_url":"https://avatars.githubusercontent.com/u/4370550?v=3","gravatar_id":"","url":"https://api.github.com/users/wilzbach","html_url":"https://github.com/wilzbach","followers_url":"https://api.github.com/users/wilzbach/followers","following_url":"https://api.github.com/users/wilzbach/following{/other_user}","gists_url":"https://api.github.com/users/wilzbach/gists{/gist_id}","starred_url":"https://api.github.com/users/wilzbach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wilzbach/subscriptions","organizations_url":"https://api.github.com/users/wilzbach/orgs","repos_url":"https://api.github.com/users/wilzbach/repos","events_url":"https://api.github.com/users/wilzbach/events{/privacy}","received_events_url":"https://api.github.com/users/wilzbach/received_events","type":"User","site_admin":false},"repo":{"id":53214767,"name":"mir","full_name":"wilzbach/mir","owner":{"login":"wilzbach","id":4370550,"avatar_url":"https://avatars.githubusercontent.com/u/4370550?v=3","gravatar_id":"","url":"https://api.github.com/users/wilzbach","html_url":"https://github.com/wilzbach","followers_url":"https://api.github.com/users/wilzbach/followers","following_url":"https://api.github.com/users/wilzbach/following{/other_user}","gists_url":"https://api.github.com/users/wilzbach/gists{/gist_id}","starred_url":"https://api.github.com/users/wilzbach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wilzbach/subscriptions","organizations_url":"https://api.github.com/users/wilzbach/orgs","repos_url":"https://api.github.com/users/wilzbach/repos","events_url":"https://api.github.com/users/wilzbach/events{/privacy}","received_events_url":"https://api.github.com/users/wilzbach/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/wilzbach/mir","description":"Generic Numeric Library","fork":true,"url":"https://api.github.com/repos/wilzbach/mir","forks_url":"https://api.github.com/repos/wilzbach/mir/forks","keys_url":"https://api.github.com/repos/wilzbach/mir/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wilzbach/mir/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wilzbach/mir/teams","hooks_url":"https://api.github.com/repos/wilzbach/mir/hooks","issue_events_url":"https://api.github.com/repos/wilzbach/mir/issues/events{/number}","events_url":"https://api.github.com/repos/wilzbach/mir/events","assignees_url":"https://api.github.com/repos/wilzbach/mir/assignees{/user}","branches_url":"https://api.github.com/repos/wilzbach/mir/branches{/branch}","tags_url":"https://api.github.com/repos/wilzbach/mir/tags","blobs_url":"https://api.github.com/repos/wilzbach/mir/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wilzbach/mir/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wilzbach/mir/git/refs{/sha}","trees_url":"https://api.github.com/repos/wilzbach/mir/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wilzbach/mir/statuses/{sha}","languages_url":"https://api.github.com/repos/wilzbach/mir/languages","stargazers_url":"https://api.github.com/repos/wilzbach/mir/stargazers","contributors_url":"https://api.github.com/repos/wilzbach/mir/contributors","subscribers_url":"https://api.github.com/repos/wilzbach/mir/subscribers","subscription_url":"https://api.github.com/repos/wilzbach/mir/subscription","commits_url":"https://api.github.com/repos/wilzbach/mir/commits{/sha}","git_commits_url":"https://api.github.com/repos/wilzbach/mir/git/commits{/sha}","comments_url":"https://api.github.com/repos/wilzbach/mir/comments{/number}","issue_comment_url":"https://api.github.com/repos/wilzbach/mir/issues/comments{/number}","contents_url":"https://api.github.com/repos/wilzbach/mir/contents/{+path}","compare_url":"https://api.github.com/repos/wilzbach/mir/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wilzbach/mir/merges","archive_url":"https://api.github.com/repos/wilzbach/mir/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wilzbach/mir/downloads","issues_url":"https://api.github.com/repos/wilzbach/mir/issues{/number}","pulls_url":"https://api.github.com/repos/wilzbach/mir/pulls{/number}","milestones_url":"https://api.github.com/repos/wilzbach/mir/milestones{/number}","notifications_url":"https://api.github.com/repos/wilzbach/mir/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wilzbach/mir/labels{/name}","releases_url":"https://api.github.com/repos/wilzbach/mir/releases{/id}","deployments_url":"https://api.github.com/repos/wilzbach/mir/deployments","created_at":"2016-03-05T17:50:27Z","updated_at":"2016-04-07T18:31:16Z","pushed_at":"2016-06-26T12:15:39Z","git_url":"git://github.com/wilzbach/mir.git","ssh_url":"git@github.com:wilzbach/mir.git","clone_url":"https://github.com/wilzbach/mir.git","svn_url":"https://github.com/wilzbach/mir","homepage":"","size":1675,"stargazers_count":1,"watchers_count":1,"language":"D","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":1,"default_branch":"master"}},"base":{"label":"libmir:master","ref":"master","sha":"03c87f6f573ccd85fd7762909256e1eddebc8271","user":{"login":"libmir","id":18573637,"avatar_url":"https://avatars.githubusercontent.com/u/18573637?v=3","gravatar_id":"","url":"https://api.github.com/users/libmir","html_url":"https://github.com/libmir","followers_url":"https://api.github.com/users/libmir/followers","following_url":"https://api.github.com/users/libmir/following{/other_user}","gists_url":"https://api.github.com/users/libmir/gists{/gist_id}","starred_url":"https://api.github.com/users/libmir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/libmir/subscriptions","organizations_url":"https://api.github.com/users/libmir/orgs","repos_url":"https://api.github.com/users/libmir/repos","events_url":"https://api.github.com/users/libmir/events{/privacy}","received_events_url":"https://api.github.com/users/libmir/received_events","type":"Organization","site_admin":false},"repo":{"id":37379986,"name":"mir","full_name":"libmir/mir","owner":{"login":"libmir","id":18573637,"avatar_url":"https://avatars.githubusercontent.com/u/18573637?v=3","gravatar_id":"","url":"https://api.github.com/users/libmir","html_url":"https://github.com/libmir","followers_url":"https://api.github.com/users/libmir/followers","following_url":"https://api.github.com/users/libmir/following{/other_user}","gists_url":"https://api.github.com/users/libmir/gists{/gist_id}","starred_url":"https://api.github.com/users/libmir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/libmir/subscriptions","organizations_url":"https://api.github.com/users/libmir/orgs","repos_url":"https://api.github.com/users/libmir/repos","events_url":"https://api.github.com/users/libmir/events{/privacy}","received_events_url":"https://api.github.com/users/libmir/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/libmir/mir","description":"Generic Numerical Library","fork":false,"url":"https://api.github.com/repos/libmir/mir","forks_url":"https://api.github.com/repos/libmir/mir/forks","keys_url":"https://api.github.com/repos/libmir/mir/keys{/key_id}","collaborators_url":"https://api.github.com/repos/libmir/mir/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/libmir/mir/teams","hooks_url":"https://api.github.com/repos/libmir/mir/hooks","issue_events_url":"https://api.github.com/repos/libmir/mir/issues/events{/number}","events_url":"https://api.github.com/repos/libmir/mir/events","assignees_url":"https://api.github.com/repos/libmir/mir/assignees{/user}","branches_url":"https://api.github.com/repos/libmir/mir/branches{/branch}","tags_url":"https://api.github.com/repos/libmir/mir/tags","blobs_url":"https://api.github.com/repos/libmir/mir/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/libmir/mir/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/libmir/mir/git/refs{/sha}","trees_url":"https://api.github.com/repos/libmir/mir/git/trees{/sha}","statuses_url":"https://api.github.com/repos/libmir/mir/statuses/{sha}","languages_url":"https://api.github.com/repos/libmir/mir/languages","stargazers_url":"https://api.github.com/repos/libmir/mir/stargazers","contributors_url":"https://api.github.com/repos/libmir/mir/contributors","subscribers_url":"https://api.github.com/repos/libmir/mir/subscribers","subscription_url":"https://api.github.com/repos/libmir/mir/subscription","commits_url":"https://api.github.com/repos/libmir/mir/commits{/sha}","git_commits_url":"https://api.github.com/repos/libmir/mir/git/commits{/sha}","comments_url":"https://api.github.com/repos/libmir/mir/comments{/number}","issue_comment_url":"https://api.github.com/repos/libmir/mir/issues/comments{/number}","contents_url":"https://api.github.com/repos/libmir/mir/contents/{+path}","compare_url":"https://api.github.com/repos/libmir/mir/compare/{base}...{head}","merges_url":"https://api.github.com/repos/libmir/mir/merges","archive_url":"https://api.github.com/repos/libmir/mir/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/libmir/mir/downloads","issues_url":"https://api.github.com/repos/libmir/mir/issues{/number}","pulls_url":"https://api.github.com/repos/libmir/mir/pulls{/number}","milestones_url":"https://api.github.com/repos/libmir/mir/milestones{/number}","notifications_url":"https://api.github.com/repos/libmir/mir/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/libmir/mir/labels{/name}","releases_url":"https://api.github.com/repos/libmir/mir/releases{/id}","deployments_url":"https://api.github.com/repos/libmir/mir/deployments","created_at":"2015-06-13T16:59:39Z","updated_at":"2016-06-25T22:44:30Z","pushed_at":"2016-06-26T12:15:39Z","git_url":"git://github.com/libmir/mir.git","ssh_url":"git@github.com:libmir/mir.git","clone_url":"https://github.com/libmir/mir.git","svn_url":"https://github.com/libmir/mir","homepage":"http://mir.dlang.io","size":1746,"stargazers_count":32,"watchers_count":32,"language":"D","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":56,"forks":7,"open_issues":56,"watchers":32,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/libmir/mir/pulls/234"},"html":{"href":"https://github.com/libmir/mir/pull/234"},"issue":{"href":"https://api.github.com/repos/libmir/mir/issues/234"},"comments":{"href":"https://api.github.com/repos/libmir/mir/issues/234/comments"},"review_comments":{"href":"https://api.github.com/repos/libmir/mir/pulls/234/comments"},"review_comment":{"href":"https://api.github.com/repos/libmir/mir/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/libmir/mir/pulls/234/commits"},"statuses":{"href":"https://api.github.com/repos/libmir/mir/statuses/7562bb4c0505358c90e3238ede19335c82e47954"}}}}
{"actor":{"display_login":"WebDrake"}}