{"action":"created","comment":{"url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/pulls/comments/60942217","id":60942217,"diff_hunk":"@@ -0,0 +1,79 @@\n+from collections import Mapping\n+from numbers import Integral\n+from numbers import Real\n+\n+from scipy.stats._distn_infrastructure import rv_frozen\n+from scipy.stats.distributions import randint\n+from scipy.stats.distributions import uniform\n+\n+from sklearn.utils import check_random_state\n+from sklearn.utils.fixes import sp_version\n+\n+\n+class Categorical:\n+    def __init__(self, *args):\n+        self.values = args\n+\n+    def rvs(self, random_state=None):\n+        rng = check_random_state(random_state)\n+        return self.values[rng.randint(len(self.values))]\n+\n+    @property\n+    def low(self):\n+        return min(self.values)\n+\n+    @property\n+    def high(self):\n+        return max(self.values)\n+\n+\n+class Discrete:\n+    def __init__(self, low, high):\n+        self.low = low\n+        self.high = high\n+\n+    def rvs(self, random_state=None):\n+        return randint(self.low, self.high).rvs(random_state=random_state)\n+\n+\n+class Continuous:\n+    def __init__(self, low, high):\n+        self.low = low\n+        self.high = high\n+\n+    def rvs(self, random_state=None):\n+        return uniform(self.low, self.high).rvs(random_state=random_state)\n+\n+\n+def points(grid, random_state=None):\n+    if isinstance(grid, Mapping):\n+        grid = [grid]\n+\n+    for sub_grid in grid:\n+        for k, v in sub_grid.items():\n+            if isinstance(v, (Categorical, Continuous, Discrete)):\n+                pass\n+\n+            elif len(v) > 2 or isinstance(v[0], str):\n+                sub_grid[k] = Categorical(*v)\n+\n+            # important to check for Integral first as int(3) is\n+            # also a Real but not the other way around\n+            elif isinstance(v[0], Integral):\n+                sub_grid[k] = randint(*v)","path":"skopt/sample.py","position":63,"original_position":63,"commit_id":"c506899e108fcc0bcf5b65746a6d5f28e09bc1d9","original_commit_id":"c506899e108fcc0bcf5b65746a6d5f28e09bc1d9","user":{"login":"MechCoder","id":1867024,"avatar_url":"https://avatars.githubusercontent.com/u/1867024?v=3","gravatar_id":"","url":"https://api.github.com/users/MechCoder","html_url":"https://github.com/MechCoder","followers_url":"https://api.github.com/users/MechCoder/followers","following_url":"https://api.github.com/users/MechCoder/following{/other_user}","gists_url":"https://api.github.com/users/MechCoder/gists{/gist_id}","starred_url":"https://api.github.com/users/MechCoder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MechCoder/subscriptions","organizations_url":"https://api.github.com/users/MechCoder/orgs","repos_url":"https://api.github.com/users/MechCoder/repos","events_url":"https://api.github.com/users/MechCoder/events{/privacy}","received_events_url":"https://api.github.com/users/MechCoder/received_events","type":"User","site_admin":false},"body":"Why not `Discrete` here? Just to support lower versions of SciPy? In that case we should be do the handling inside `Discrete` and not outside..","created_at":"2016-04-25T16:19:43Z","updated_at":"2016-04-25T16:19:43Z","html_url":"https://github.com/scikit-optimize/scikit-optimize/pull/70#discussion_r60942217","pull_request_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/pulls/70","_links":{"self":{"href":"https://api.github.com/repos/scikit-optimize/scikit-optimize/pulls/comments/60942217"},"html":{"href":"https://github.com/scikit-optimize/scikit-optimize/pull/70#discussion_r60942217"},"pull_request":{"href":"https://api.github.com/repos/scikit-optimize/scikit-optimize/pulls/70"}}},"pull_request":{"url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/pulls/70","id":67676478,"html_url":"https://github.com/scikit-optimize/scikit-optimize/pull/70","diff_url":"https://github.com/scikit-optimize/scikit-optimize/pull/70.diff","patch_url":"https://github.com/scikit-optimize/scikit-optimize/pull/70.patch","issue_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/issues/70","number":70,"state":"open","locked":false,"title":"[WIP] API for specifying discrete and categorical variables","user":{"login":"betatim","id":1448859,"avatar_url":"https://avatars.githubusercontent.com/u/1448859?v=3","gravatar_id":"","url":"https://api.github.com/users/betatim","html_url":"https://github.com/betatim","followers_url":"https://api.github.com/users/betatim/followers","following_url":"https://api.github.com/users/betatim/following{/other_user}","gists_url":"https://api.github.com/users/betatim/gists{/gist_id}","starred_url":"https://api.github.com/users/betatim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/betatim/subscriptions","organizations_url":"https://api.github.com/users/betatim/orgs","repos_url":"https://api.github.com/users/betatim/repos","events_url":"https://api.github.com/users/betatim/events{/privacy}","received_events_url":"https://api.github.com/users/betatim/received_events","type":"User","site_admin":false},"body":"This is a proposal for an API to specify and sample variables that are categorical and/or discrete.\r\n\r\nIt follows up on the discussion in #59\r\n\r\nThe best place to start to learn about the API is `skopt/tests/test_sample.py`","created_at":"2016-04-25T07:36:32Z","updated_at":"2016-04-25T16:19:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e15b10781e17056033980ffe9a5502c52e2fa874","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/pulls/70/commits","review_comments_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/pulls/70/comments","review_comment_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/pulls/comments{/number}","comments_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/issues/70/comments","statuses_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/statuses/c506899e108fcc0bcf5b65746a6d5f28e09bc1d9","head":{"label":"betatim:param-sampler","ref":"param-sampler","sha":"c506899e108fcc0bcf5b65746a6d5f28e09bc1d9","user":{"login":"betatim","id":1448859,"avatar_url":"https://avatars.githubusercontent.com/u/1448859?v=3","gravatar_id":"","url":"https://api.github.com/users/betatim","html_url":"https://github.com/betatim","followers_url":"https://api.github.com/users/betatim/followers","following_url":"https://api.github.com/users/betatim/following{/other_user}","gists_url":"https://api.github.com/users/betatim/gists{/gist_id}","starred_url":"https://api.github.com/users/betatim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/betatim/subscriptions","organizations_url":"https://api.github.com/users/betatim/orgs","repos_url":"https://api.github.com/users/betatim/repos","events_url":"https://api.github.com/users/betatim/events{/privacy}","received_events_url":"https://api.github.com/users/betatim/received_events","type":"User","site_admin":false},"repo":{"id":54460558,"name":"BlackBox","full_name":"betatim/BlackBox","owner":{"login":"betatim","id":1448859,"avatar_url":"https://avatars.githubusercontent.com/u/1448859?v=3","gravatar_id":"","url":"https://api.github.com/users/betatim","html_url":"https://github.com/betatim","followers_url":"https://api.github.com/users/betatim/followers","following_url":"https://api.github.com/users/betatim/following{/other_user}","gists_url":"https://api.github.com/users/betatim/gists{/gist_id}","starred_url":"https://api.github.com/users/betatim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/betatim/subscriptions","organizations_url":"https://api.github.com/users/betatim/orgs","repos_url":"https://api.github.com/users/betatim/repos","events_url":"https://api.github.com/users/betatim/events{/privacy}","received_events_url":"https://api.github.com/users/betatim/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/betatim/BlackBox","description":"A sandmine for blackbox optimization methods following the scipy.optimize interface","fork":true,"url":"https://api.github.com/repos/betatim/BlackBox","forks_url":"https://api.github.com/repos/betatim/BlackBox/forks","keys_url":"https://api.github.com/repos/betatim/BlackBox/keys{/key_id}","collaborators_url":"https://api.github.com/repos/betatim/BlackBox/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/betatim/BlackBox/teams","hooks_url":"https://api.github.com/repos/betatim/BlackBox/hooks","issue_events_url":"https://api.github.com/repos/betatim/BlackBox/issues/events{/number}","events_url":"https://api.github.com/repos/betatim/BlackBox/events","assignees_url":"https://api.github.com/repos/betatim/BlackBox/assignees{/user}","branches_url":"https://api.github.com/repos/betatim/BlackBox/branches{/branch}","tags_url":"https://api.github.com/repos/betatim/BlackBox/tags","blobs_url":"https://api.github.com/repos/betatim/BlackBox/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/betatim/BlackBox/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/betatim/BlackBox/git/refs{/sha}","trees_url":"https://api.github.com/repos/betatim/BlackBox/git/trees{/sha}","statuses_url":"https://api.github.com/repos/betatim/BlackBox/statuses/{sha}","languages_url":"https://api.github.com/repos/betatim/BlackBox/languages","stargazers_url":"https://api.github.com/repos/betatim/BlackBox/stargazers","contributors_url":"https://api.github.com/repos/betatim/BlackBox/contributors","subscribers_url":"https://api.github.com/repos/betatim/BlackBox/subscribers","subscription_url":"https://api.github.com/repos/betatim/BlackBox/subscription","commits_url":"https://api.github.com/repos/betatim/BlackBox/commits{/sha}","git_commits_url":"https://api.github.com/repos/betatim/BlackBox/git/commits{/sha}","comments_url":"https://api.github.com/repos/betatim/BlackBox/comments{/number}","issue_comment_url":"https://api.github.com/repos/betatim/BlackBox/issues/comments{/number}","contents_url":"https://api.github.com/repos/betatim/BlackBox/contents/{+path}","compare_url":"https://api.github.com/repos/betatim/BlackBox/compare/{base}...{head}","merges_url":"https://api.github.com/repos/betatim/BlackBox/merges","archive_url":"https://api.github.com/repos/betatim/BlackBox/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/betatim/BlackBox/downloads","issues_url":"https://api.github.com/repos/betatim/BlackBox/issues{/number}","pulls_url":"https://api.github.com/repos/betatim/BlackBox/pulls{/number}","milestones_url":"https://api.github.com/repos/betatim/BlackBox/milestones{/number}","notifications_url":"https://api.github.com/repos/betatim/BlackBox/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/betatim/BlackBox/labels{/name}","releases_url":"https://api.github.com/repos/betatim/BlackBox/releases{/id}","deployments_url":"https://api.github.com/repos/betatim/BlackBox/deployments","created_at":"2016-03-22T09:04:39Z","updated_at":"2016-03-22T09:04:40Z","pushed_at":"2016-04-25T14:54:22Z","git_url":"git://github.com/betatim/BlackBox.git","ssh_url":"git@github.com:betatim/BlackBox.git","clone_url":"https://github.com/betatim/BlackBox.git","svn_url":"https://github.com/betatim/BlackBox","homepage":null,"size":73,"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":"scikit-optimize:master","ref":"master","sha":"6591f3717a89de7d56b32f774ba572edbccc4803","user":{"login":"scikit-optimize","id":18578550,"avatar_url":"https://avatars.githubusercontent.com/u/18578550?v=3","gravatar_id":"","url":"https://api.github.com/users/scikit-optimize","html_url":"https://github.com/scikit-optimize","followers_url":"https://api.github.com/users/scikit-optimize/followers","following_url":"https://api.github.com/users/scikit-optimize/following{/other_user}","gists_url":"https://api.github.com/users/scikit-optimize/gists{/gist_id}","starred_url":"https://api.github.com/users/scikit-optimize/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scikit-optimize/subscriptions","organizations_url":"https://api.github.com/users/scikit-optimize/orgs","repos_url":"https://api.github.com/users/scikit-optimize/repos","events_url":"https://api.github.com/users/scikit-optimize/events{/privacy}","received_events_url":"https://api.github.com/users/scikit-optimize/received_events","type":"Organization","site_admin":false},"repo":{"id":54340642,"name":"scikit-optimize","full_name":"scikit-optimize/scikit-optimize","owner":{"login":"scikit-optimize","id":18578550,"avatar_url":"https://avatars.githubusercontent.com/u/18578550?v=3","gravatar_id":"","url":"https://api.github.com/users/scikit-optimize","html_url":"https://github.com/scikit-optimize","followers_url":"https://api.github.com/users/scikit-optimize/followers","following_url":"https://api.github.com/users/scikit-optimize/following{/other_user}","gists_url":"https://api.github.com/users/scikit-optimize/gists{/gist_id}","starred_url":"https://api.github.com/users/scikit-optimize/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scikit-optimize/subscriptions","organizations_url":"https://api.github.com/users/scikit-optimize/orgs","repos_url":"https://api.github.com/users/scikit-optimize/repos","events_url":"https://api.github.com/users/scikit-optimize/events{/privacy}","received_events_url":"https://api.github.com/users/scikit-optimize/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/scikit-optimize/scikit-optimize","description":"A sandbox for blackbox optimization methods following the scipy.optimize interface","fork":false,"url":"https://api.github.com/repos/scikit-optimize/scikit-optimize","forks_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/forks","keys_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/keys{/key_id}","collaborators_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/teams","hooks_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/hooks","issue_events_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/issues/events{/number}","events_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/events","assignees_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/assignees{/user}","branches_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/branches{/branch}","tags_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/tags","blobs_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/git/refs{/sha}","trees_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/git/trees{/sha}","statuses_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/statuses/{sha}","languages_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/languages","stargazers_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/stargazers","contributors_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/contributors","subscribers_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/subscribers","subscription_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/subscription","commits_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/commits{/sha}","git_commits_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/git/commits{/sha}","comments_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/comments{/number}","issue_comment_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/issues/comments{/number}","contents_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/contents/{+path}","compare_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/compare/{base}...{head}","merges_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/merges","archive_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/downloads","issues_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/issues{/number}","pulls_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/pulls{/number}","milestones_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/milestones{/number}","notifications_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/labels{/name}","releases_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/releases{/id}","deployments_url":"https://api.github.com/repos/scikit-optimize/scikit-optimize/deployments","created_at":"2016-03-20T21:10:54Z","updated_at":"2016-04-24T21:21:46Z","pushed_at":"2016-04-25T14:54:23Z","git_url":"git://github.com/scikit-optimize/scikit-optimize.git","ssh_url":"git@github.com:scikit-optimize/scikit-optimize.git","clone_url":"https://github.com/scikit-optimize/scikit-optimize.git","svn_url":"https://github.com/scikit-optimize/scikit-optimize","homepage":"","size":106,"stargazers_count":25,"watchers_count":25,"language":"Mako","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":22,"forks":5,"open_issues":22,"watchers":25,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scikit-optimize/scikit-optimize/pulls/70"},"html":{"href":"https://github.com/scikit-optimize/scikit-optimize/pull/70"},"issue":{"href":"https://api.github.com/repos/scikit-optimize/scikit-optimize/issues/70"},"comments":{"href":"https://api.github.com/repos/scikit-optimize/scikit-optimize/issues/70/comments"},"review_comments":{"href":"https://api.github.com/repos/scikit-optimize/scikit-optimize/pulls/70/comments"},"review_comment":{"href":"https://api.github.com/repos/scikit-optimize/scikit-optimize/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/scikit-optimize/scikit-optimize/pulls/70/commits"},"statuses":{"href":"https://api.github.com/repos/scikit-optimize/scikit-optimize/statuses/c506899e108fcc0bcf5b65746a6d5f28e09bc1d9"}}}}