GitHub PullRequestReviewCommentEvent at 2014-12-18 20:20:01
Repository: scikit-learn
Actor: ogrisel
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/22068335","id":22068335,"diff_hunk":"@@ -164,17 +164,43 @@ def __init__(self, param_distributions, n_iter, random_state=None):\n         self.random_state = random_state\n \n     def __iter__(self):\n+        samples = []\n+        # check if all distributions are given as lists\n+        # in this case we want to sample without replacement\n+        all_lists = np.all([not hasattr(v, \"rvs\")\n+                            for v in self.param_distributions.values()])\n         rnd = check_random_state(self.random_state)\n-        # Always sort the keys of a dictionary, for reproducibility\n-        items = sorted(self.param_distributions.items())\n-        for _ in range(self.n_iter):\n-            params = dict()\n-            for k, v in items:\n-                if hasattr(v, \"rvs\"):\n-                    params[k] = v.rvs()\n-                else:\n-                    params[k] = v[rnd.randint(len(v))]\n-            yield params\n+\n+        if all_lists:\n+            param_grid = list(ParameterGrid(self.param_distributions))\n+            grid_size = len(param_grid)\n+\n+        if all_lists and self.n_iter > 0.1 * grid_size:\n+            # get complete grid and yield from it\n+            if grid_size < self.n_iter:\n+                raise ValueError(\"The total space of parameters %d is smaller than n_iter=%d. \"\n+                                 % (grid_size, self.n_iter)\n+                                 + \"For exhaustive searches, use GridSearchCV.\")\n+            for i in rnd.permutation(grid_size)[:self.n_iter]:\n+                yield param_grid[i]\n+\n+        else:","path":"sklearn/grid_search.py","position":34,"original_position":34,"commit_id":"133f3fd0b5abd39eb2b51d75cfe57b6701c0873b","original_commit_id":"133f3fd0b5abd39eb2b51d75cfe57b6701c0873b","user":{"login":"ogrisel","id":89061,"avatar_url":"https://avatars.githubusercontent.com/u/89061?v=3","gravatar_id":"","url":"https://api.github.com/users/ogrisel","html_url":"https://github.com/ogrisel","followers_url":"https://api.github.com/users/ogrisel/followers","following_url":"https://api.github.com/users/ogrisel/following{/other_user}","gists_url":"https://api.github.com/users/ogrisel/gists{/gist_id}","starred_url":"https://api.github.com/users/ogrisel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ogrisel/subscriptions","organizations_url":"https://api.github.com/users/ogrisel/orgs","repos_url":"https://api.github.com/users/ogrisel/repos","events_url":"https://api.github.com/users/ogrisel/events{/privacy}","received_events_url":"https://api.github.com/users/ogrisel/received_events","type":"User","site_admin":false},"body":"Please add a comment that if the number of requested iterations is much smaller than the number of possible combinations of parameter values with can do sampling without replacement naively by maintaining a tabu list of past samples without running into the risk of infinite loops.","created_at":"2014-12-18T20:20:01Z","updated_at":"2014-12-18T20:20:01Z","html_url":"https://github.com/scikit-learn/scikit-learn/pull/3850#discussion_r22068335","pull_request_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3850","_links":{"self":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/22068335"},"html":{"href":"https://github.com/scikit-learn/scikit-learn/pull/3850#discussion_r22068335"},"pull_request":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3850"}}},"pull_request":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3850","id":24379484,"html_url":"https://github.com/scikit-learn/scikit-learn/pull/3850","diff_url":"https://github.com/scikit-learn/scikit-learn/pull/3850.diff","patch_url":"https://github.com/scikit-learn/scikit-learn/pull/3850.patch","issue_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/3850","number":3850,"state":"open","locked":false,"title":"MRG Make ParameterSampler sample without replacement","user":{"login":"amueller","id":449558,"avatar_url":"https://avatars.githubusercontent.com/u/449558?v=3","gravatar_id":"","url":"https://api.github.com/users/amueller","html_url":"https://github.com/amueller","followers_url":"https://api.github.com/users/amueller/followers","following_url":"https://api.github.com/users/amueller/following{/other_user}","gists_url":"https://api.github.com/users/amueller/gists{/gist_id}","starred_url":"https://api.github.com/users/amueller/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amueller/subscriptions","organizations_url":"https://api.github.com/users/amueller/orgs","repos_url":"https://api.github.com/users/amueller/repos","events_url":"https://api.github.com/users/amueller/events{/privacy}","received_events_url":"https://api.github.com/users/amueller/received_events","type":"User","site_admin":false},"body":"Fixes #3792.\r\nI think this issue came up before so maybe it is worth addressing.\r\nThis makes the ParametersSampler sample without replacement if all parameters are lists.\r\nThis has a couple of gotchas:\r\n\r\n* It changes current behavior, in particular I raise an error if there are less possible settings than ``n_iter``.\r\n* I don't know if there is a way to detect finite support in a scipy distribution, so we can not do it there. That means that ``'bla' : bernoulli(0.5)`` is not equivalent any more to ``'bla': [0, 1]`` (the first does sampling with replacement, the second without)\r\n\r\nPossibilities to resolve these would be:\r\n* give a warning instead of a value error when ``n_iter`` > ``grid_size`` and produce a smaller grid (or sample with replacement in this case?). Might invalidate the ``__len__`` implementation.\r\n* add a parameter ``with_replacement``, set it to ``None``, and go to a deprecation cycle to set it to ``False``. The parameter would only do something in the case all parameters are lists, though.\r\n* Hack into the scipy dists, check if something is discrete and use lower and upper to get the support. If a user tries to implement his own distribution with finite support, we would still be screwed.","created_at":"2014-11-13T16:16:31Z","updated_at":"2014-12-18T20:20:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"40e5a209b39551733ecca5d50e782851084d436f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3850/commits","review_comments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3850/comments","review_comment_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/{number}","comments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/3850/comments","statuses_url":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/133f3fd0b5abd39eb2b51d75cfe57b6701c0873b","head":{"label":"amueller:randomized_search_no_replacement","ref":"randomized_search_no_replacement","sha":"133f3fd0b5abd39eb2b51d75cfe57b6701c0873b","user":{"login":"amueller","id":449558,"avatar_url":"https://avatars.githubusercontent.com/u/449558?v=3","gravatar_id":"","url":"https://api.github.com/users/amueller","html_url":"https://github.com/amueller","followers_url":"https://api.github.com/users/amueller/followers","following_url":"https://api.github.com/users/amueller/following{/other_user}","gists_url":"https://api.github.com/users/amueller/gists{/gist_id}","starred_url":"https://api.github.com/users/amueller/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amueller/subscriptions","organizations_url":"https://api.github.com/users/amueller/orgs","repos_url":"https://api.github.com/users/amueller/repos","events_url":"https://api.github.com/users/amueller/events{/privacy}","received_events_url":"https://api.github.com/users/amueller/received_events","type":"User","site_admin":false},"repo":{"id":1622872,"name":"scikit-learn","full_name":"amueller/scikit-learn","owner":{"login":"amueller","id":449558,"avatar_url":"https://avatars.githubusercontent.com/u/449558?v=3","gravatar_id":"","url":"https://api.github.com/users/amueller","html_url":"https://github.com/amueller","followers_url":"https://api.github.com/users/amueller/followers","following_url":"https://api.github.com/users/amueller/following{/other_user}","gists_url":"https://api.github.com/users/amueller/gists{/gist_id}","starred_url":"https://api.github.com/users/amueller/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amueller/subscriptions","organizations_url":"https://api.github.com/users/amueller/orgs","repos_url":"https://api.github.com/users/amueller/repos","events_url":"https://api.github.com/users/amueller/events{/privacy}","received_events_url":"https://api.github.com/users/amueller/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/amueller/scikit-learn","description":"scikit-learn main repo","fork":true,"url":"https://api.github.com/repos/amueller/scikit-learn","forks_url":"https://api.github.com/repos/amueller/scikit-learn/forks","keys_url":"https://api.github.com/repos/amueller/scikit-learn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/amueller/scikit-learn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/amueller/scikit-learn/teams","hooks_url":"https://api.github.com/repos/amueller/scikit-learn/hooks","issue_events_url":"https://api.github.com/repos/amueller/scikit-learn/issues/events{/number}","events_url":"https://api.github.com/repos/amueller/scikit-learn/events","assignees_url":"https://api.github.com/repos/amueller/scikit-learn/assignees{/user}","branches_url":"https://api.github.com/repos/amueller/scikit-learn/branches{/branch}","tags_url":"https://api.github.com/repos/amueller/scikit-learn/tags","blobs_url":"https://api.github.com/repos/amueller/scikit-learn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/amueller/scikit-learn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/amueller/scikit-learn/git/refs{/sha}","trees_url":"https://api.github.com/repos/amueller/scikit-learn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/amueller/scikit-learn/statuses/{sha}","languages_url":"https://api.github.com/repos/amueller/scikit-learn/languages","stargazers_url":"https://api.github.com/repos/amueller/scikit-learn/stargazers","contributors_url":"https://api.github.com/repos/amueller/scikit-learn/contributors","subscribers_url":"https://api.github.com/repos/amueller/scikit-learn/subscribers","subscription_url":"https://api.github.com/repos/amueller/scikit-learn/subscription","commits_url":"https://api.github.com/repos/amueller/scikit-learn/commits{/sha}","git_commits_url":"https://api.github.com/repos/amueller/scikit-learn/git/commits{/sha}","comments_url":"https://api.github.com/repos/amueller/scikit-learn/comments{/number}","issue_comment_url":"https://api.github.com/repos/amueller/scikit-learn/issues/comments/{number}","contents_url":"https://api.github.com/repos/amueller/scikit-learn/contents/{+path}","compare_url":"https://api.github.com/repos/amueller/scikit-learn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/amueller/scikit-learn/merges","archive_url":"https://api.github.com/repos/amueller/scikit-learn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/amueller/scikit-learn/downloads","issues_url":"https://api.github.com/repos/amueller/scikit-learn/issues{/number}","pulls_url":"https://api.github.com/repos/amueller/scikit-learn/pulls{/number}","milestones_url":"https://api.github.com/repos/amueller/scikit-learn/milestones{/number}","notifications_url":"https://api.github.com/repos/amueller/scikit-learn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/amueller/scikit-learn/labels{/name}","releases_url":"https://api.github.com/repos/amueller/scikit-learn/releases{/id}","created_at":"2011-04-16T12:41:21Z","updated_at":"2014-07-16T14:32:49Z","pushed_at":"2014-12-17T19:02:38Z","git_url":"git://github.com/amueller/scikit-learn.git","ssh_url":"git@github.com:amueller/scikit-learn.git","clone_url":"https://github.com/amueller/scikit-learn.git","svn_url":"https://github.com/amueller/scikit-learn","homepage":"http://scikit-learn.sourceforge.net","size":79960,"stargazers_count":5,"watchers_count":5,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":3,"mirror_url":null,"open_issues_count":1,"forks":3,"open_issues":1,"watchers":5,"default_branch":"master"}},"base":{"label":"scikit-learn:master","ref":"master","sha":"5b90e97ebf39f8ec2b0a27c6d18c6291bff20baa","user":{"login":"scikit-learn","id":365630,"avatar_url":"https://avatars.githubusercontent.com/u/365630?v=3","gravatar_id":"","url":"https://api.github.com/users/scikit-learn","html_url":"https://github.com/scikit-learn","followers_url":"https://api.github.com/users/scikit-learn/followers","following_url":"https://api.github.com/users/scikit-learn/following{/other_user}","gists_url":"https://api.github.com/users/scikit-learn/gists{/gist_id}","starred_url":"https://api.github.com/users/scikit-learn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scikit-learn/subscriptions","organizations_url":"https://api.github.com/users/scikit-learn/orgs","repos_url":"https://api.github.com/users/scikit-learn/repos","events_url":"https://api.github.com/users/scikit-learn/events{/privacy}","received_events_url":"https://api.github.com/users/scikit-learn/received_events","type":"Organization","site_admin":false},"repo":{"id":843222,"name":"scikit-learn","full_name":"scikit-learn/scikit-learn","owner":{"login":"scikit-learn","id":365630,"avatar_url":"https://avatars.githubusercontent.com/u/365630?v=3","gravatar_id":"","url":"https://api.github.com/users/scikit-learn","html_url":"https://github.com/scikit-learn","followers_url":"https://api.github.com/users/scikit-learn/followers","following_url":"https://api.github.com/users/scikit-learn/following{/other_user}","gists_url":"https://api.github.com/users/scikit-learn/gists{/gist_id}","starred_url":"https://api.github.com/users/scikit-learn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scikit-learn/subscriptions","organizations_url":"https://api.github.com/users/scikit-learn/orgs","repos_url":"https://api.github.com/users/scikit-learn/repos","events_url":"https://api.github.com/users/scikit-learn/events{/privacy}","received_events_url":"https://api.github.com/users/scikit-learn/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/scikit-learn/scikit-learn","description":"scikit-learn: machine learning in Python","fork":false,"url":"https://api.github.com/repos/scikit-learn/scikit-learn","forks_url":"https://api.github.com/repos/scikit-learn/scikit-learn/forks","keys_url":"https://api.github.com/repos/scikit-learn/scikit-learn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/scikit-learn/scikit-learn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/scikit-learn/scikit-learn/teams","hooks_url":"https://api.github.com/repos/scikit-learn/scikit-learn/hooks","issue_events_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/events{/number}","events_url":"https://api.github.com/repos/scikit-learn/scikit-learn/events","assignees_url":"https://api.github.com/repos/scikit-learn/scikit-learn/assignees{/user}","branches_url":"https://api.github.com/repos/scikit-learn/scikit-learn/branches{/branch}","tags_url":"https://api.github.com/repos/scikit-learn/scikit-learn/tags","blobs_url":"https://api.github.com/repos/scikit-learn/scikit-learn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/scikit-learn/scikit-learn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/scikit-learn/scikit-learn/git/refs{/sha}","trees_url":"https://api.github.com/repos/scikit-learn/scikit-learn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/{sha}","languages_url":"https://api.github.com/repos/scikit-learn/scikit-learn/languages","stargazers_url":"https://api.github.com/repos/scikit-learn/scikit-learn/stargazers","contributors_url":"https://api.github.com/repos/scikit-learn/scikit-learn/contributors","subscribers_url":"https://api.github.com/repos/scikit-learn/scikit-learn/subscribers","subscription_url":"https://api.github.com/repos/scikit-learn/scikit-learn/subscription","commits_url":"https://api.github.com/repos/scikit-learn/scikit-learn/commits{/sha}","git_commits_url":"https://api.github.com/repos/scikit-learn/scikit-learn/git/commits{/sha}","comments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/comments{/number}","issue_comment_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/comments/{number}","contents_url":"https://api.github.com/repos/scikit-learn/scikit-learn/contents/{+path}","compare_url":"https://api.github.com/repos/scikit-learn/scikit-learn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/scikit-learn/scikit-learn/merges","archive_url":"https://api.github.com/repos/scikit-learn/scikit-learn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/scikit-learn/scikit-learn/downloads","issues_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues{/number}","pulls_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls{/number}","milestones_url":"https://api.github.com/repos/scikit-learn/scikit-learn/milestones{/number}","notifications_url":"https://api.github.com/repos/scikit-learn/scikit-learn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/scikit-learn/scikit-learn/labels{/name}","releases_url":"https://api.github.com/repos/scikit-learn/scikit-learn/releases{/id}","created_at":"2010-08-17T09:43:38Z","updated_at":"2014-12-18T18:50:41Z","pushed_at":"2014-12-18T18:50:41Z","git_url":"git://github.com/scikit-learn/scikit-learn.git","ssh_url":"git@github.com:scikit-learn/scikit-learn.git","clone_url":"https://github.com/scikit-learn/scikit-learn.git","svn_url":"https://github.com/scikit-learn/scikit-learn","homepage":"http://scikit-learn.org","size":104497,"stargazers_count":4584,"watchers_count":4584,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2653,"mirror_url":null,"open_issues_count":537,"forks":2653,"open_issues":537,"watchers":4584,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3850"},"html":{"href":"https://github.com/scikit-learn/scikit-learn/pull/3850"},"issue":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/3850"},"comments":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/3850/comments"},"review_comments":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3850/comments"},"review_comment":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3850/commits"},"statuses":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/133f3fd0b5abd39eb2b51d75cfe57b6701c0873b"}}}}