{"action":"created","comment":{"url":"https://api.github.com/repos/scipy/scipy/pulls/comments/41727488","id":41727488,"diff_hunk":"@@ -379,35 +382,41 @@ def __init__(self, func, bounds, args=(),\n             raise ValueError(\"The population initialization method must be one\"\n                              \"of 'latinhypercube' or 'random'\")\n \n-        self.population_energies = np.ones(\n-            popsize * parameter_count) * np.inf\n+        self.population_energies = np.ones(self.population_size) * np.inf\n \n         self.disp = disp\n \n     def init_population_lhs(self):\n         \"\"\"\n-        Initializes the population with Latin Hypercube Sampling\n-        Latin Hypercube Sampling ensures that the sampling of parameter space\n-        is maximised.\n+        Initializes the population with Latin Hypercube Sampling.\n+        Latin Hypercube Sampling ensures that each parameter is uniformly\n+        sampled over its range.\n         \"\"\"\n-        samples = np.size(self.population, 0)\n-        N = np.size(self.population, 1)\n         rng = self.random_number_generator\n \n-        # Generate the intervals\n-        segsize = 1.0 / samples\n+        # Each parameter range needs to be sampled uniformly. The scaled\n+        # parameter range ([0, 1)) needs to be split into\n+        # `self.population_size` segments, each of which has the following\n+        # size:\n+        segsize = 1.0 / self.population_size\n \n-        # Fill points uniformly in each interval\n-        rdrange = rng.rand(samples, N) * segsize\n-        rdrange += np.atleast_2d(\n-            np.linspace(0., 1., samples, endpoint=False)).T\n+        # Within each segment we sample from a uniform random distribution.\n+        # We need to do this sampling for each parameter.\n+        samples = segsize * rng.rand(self.population_size,\n+                                     self.parameter_count)\n \n-        # Make the random pairings\n-        self.population = np.zeros_like(rdrange)\n+        # Offset each segment to cover the entire parameter range [0, 1)\n+        samples += np.atleast_2d(\n+            np.linspace(0., 1., self.population_size, endpoint=False)).T","path":"scipy/optimize/_differentialevolution.py","position":77,"original_position":77,"commit_id":"39facc1f1f7aa9c4daf3c1dab1c81bbb7c4b936a","original_commit_id":"39facc1f1f7aa9c4daf3c1dab1c81bbb7c4b936a","user":{"login":"dlax","id":1046124,"avatar_url":"https://avatars.githubusercontent.com/u/1046124?v=3","gravatar_id":"","url":"https://api.github.com/users/dlax","html_url":"https://github.com/dlax","followers_url":"https://api.github.com/users/dlax/followers","following_url":"https://api.github.com/users/dlax/following{/other_user}","gists_url":"https://api.github.com/users/dlax/gists{/gist_id}","starred_url":"https://api.github.com/users/dlax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dlax/subscriptions","organizations_url":"https://api.github.com/users/dlax/orgs","repos_url":"https://api.github.com/users/dlax/repos","events_url":"https://api.github.com/users/dlax/events{/privacy}","received_events_url":"https://api.github.com/users/dlax/received_events","type":"User","site_admin":false},"body":"Andrew Nelson wrote:\n> In scipy/optimize/_differentialevolution.py\n> <https://github.com/scipy/scipy/pull/5132#discussion_r41716415>:\n>\n>>\n>> -        # Make the random pairings\n>> -        self.population = np.zeros_like(rdrange)\n>> +        # Offset each segment to cover the entire parameter range [0, 1)\n>> +        samples += np.atleast_2d(\n>> +            np.linspace(0., 1., self.population_size, endpoint=False)).T\n>\n> I could undoubtedly be done in one line. However, one of the comments\n> made in #5101 <https://github.com/scipy/scipy/issues/5101> was that the\n> source code was difficult to follow (commenting, etc).\n>\n> This line is split into two to try and make it clearer what the\n> |samples| array is and how it is created. I actually felt that the code\n> as it existed was clear already, but then I originally wrote the code.\n>\n> I think that two lines is clearer, but I'm easy either way.\n\nHmm, ok... Not convinced ;) I still think a single statement, maybe \nsplitted into two lines with a comment between would be clearer.\n\nAlso, I'd find `np.linspace(0., 1., self.population_size, \nendpoint=False)[:, np.newaxis]` clearer than the `atleast_2d` + `.T` combo.\n\n","created_at":"2015-10-12T06:55:54Z","updated_at":"2015-10-12T06:55:54Z","html_url":"https://github.com/scipy/scipy/pull/5132#discussion_r41727488","pull_request_url":"https://api.github.com/repos/scipy/scipy/pulls/5132","_links":{"self":{"href":"https://api.github.com/repos/scipy/scipy/pulls/comments/41727488"},"html":{"href":"https://github.com/scipy/scipy/pull/5132#discussion_r41727488"},"pull_request":{"href":"https://api.github.com/repos/scipy/scipy/pulls/5132"}}},"pull_request":{"url":"https://api.github.com/repos/scipy/scipy/pulls/5132","id":41984013,"html_url":"https://github.com/scipy/scipy/pull/5132","diff_url":"https://github.com/scipy/scipy/pull/5132.diff","patch_url":"https://github.com/scipy/scipy/pull/5132.patch","issue_url":"https://api.github.com/repos/scipy/scipy/issues/5132","number":5132,"state":"open","locked":false,"title":"MAINT: differential_evolution improve init_population_lhs comments closes #5101.","user":{"login":"andyfaff","id":702934,"avatar_url":"https://avatars.githubusercontent.com/u/702934?v=3","gravatar_id":"","url":"https://api.github.com/users/andyfaff","html_url":"https://github.com/andyfaff","followers_url":"https://api.github.com/users/andyfaff/followers","following_url":"https://api.github.com/users/andyfaff/following{/other_user}","gists_url":"https://api.github.com/users/andyfaff/gists{/gist_id}","starred_url":"https://api.github.com/users/andyfaff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andyfaff/subscriptions","organizations_url":"https://api.github.com/users/andyfaff/orgs","repos_url":"https://api.github.com/users/andyfaff/repos","events_url":"https://api.github.com/users/andyfaff/events{/privacy}","received_events_url":"https://api.github.com/users/andyfaff/received_events","type":"User","site_admin":false},"body":"This PR modifies:\r\n1) The init_population_lhs method to clarify what the code does.\r\n2) It adds `population_size` and `parameter_count` attributes to the DifferentialEvolutionSolver class.\r\n3) Adds extra comment lines in the optimizing loop in the `solve` method to clarify what's occurring.\r\n\r\nThis is to address some comments made in #5101\r\n\r\n@Hvass-Labs, @dlax ","created_at":"2015-08-10T03:00:15Z","updated_at":"2015-10-12T06:55:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d2ad91ea230d1ef5619e6faf2706f06893c4d758","assignee":null,"milestone":{"url":"https://api.github.com/repos/scipy/scipy/milestones/26","html_url":"https://github.com/scipy/scipy/milestones/0.17.0","labels_url":"https://api.github.com/repos/scipy/scipy/milestones/26/labels","id":1096839,"number":26,"title":"0.17.0","description":"","creator":{"login":"rgommers","id":98330,"avatar_url":"https://avatars.githubusercontent.com/u/98330?v=3","gravatar_id":"","url":"https://api.github.com/users/rgommers","html_url":"https://github.com/rgommers","followers_url":"https://api.github.com/users/rgommers/followers","following_url":"https://api.github.com/users/rgommers/following{/other_user}","gists_url":"https://api.github.com/users/rgommers/gists{/gist_id}","starred_url":"https://api.github.com/users/rgommers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rgommers/subscriptions","organizations_url":"https://api.github.com/users/rgommers/orgs","repos_url":"https://api.github.com/users/rgommers/repos","events_url":"https://api.github.com/users/rgommers/events{/privacy}","received_events_url":"https://api.github.com/users/rgommers/received_events","type":"User","site_admin":false},"open_issues":17,"closed_issues":151,"state":"open","created_at":"2015-05-05T13:00:06Z","updated_at":"2015-10-11T13:14:17Z","due_on":"2015-11-29T23:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/scipy/scipy/pulls/5132/commits","review_comments_url":"https://api.github.com/repos/scipy/scipy/pulls/5132/comments","review_comment_url":"https://api.github.com/repos/scipy/scipy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/scipy/scipy/issues/5132/comments","statuses_url":"https://api.github.com/repos/scipy/scipy/statuses/39facc1f1f7aa9c4daf3c1dab1c81bbb7c4b936a","head":{"label":"andyfaff:lhs_comment","ref":"lhs_comment","sha":"39facc1f1f7aa9c4daf3c1dab1c81bbb7c4b936a","user":{"login":"andyfaff","id":702934,"avatar_url":"https://avatars.githubusercontent.com/u/702934?v=3","gravatar_id":"","url":"https://api.github.com/users/andyfaff","html_url":"https://github.com/andyfaff","followers_url":"https://api.github.com/users/andyfaff/followers","following_url":"https://api.github.com/users/andyfaff/following{/other_user}","gists_url":"https://api.github.com/users/andyfaff/gists{/gist_id}","starred_url":"https://api.github.com/users/andyfaff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andyfaff/subscriptions","organizations_url":"https://api.github.com/users/andyfaff/orgs","repos_url":"https://api.github.com/users/andyfaff/repos","events_url":"https://api.github.com/users/andyfaff/events{/privacy}","received_events_url":"https://api.github.com/users/andyfaff/received_events","type":"User","site_admin":false},"repo":{"id":17390686,"name":"scipy","full_name":"andyfaff/scipy","owner":{"login":"andyfaff","id":702934,"avatar_url":"https://avatars.githubusercontent.com/u/702934?v=3","gravatar_id":"","url":"https://api.github.com/users/andyfaff","html_url":"https://github.com/andyfaff","followers_url":"https://api.github.com/users/andyfaff/followers","following_url":"https://api.github.com/users/andyfaff/following{/other_user}","gists_url":"https://api.github.com/users/andyfaff/gists{/gist_id}","starred_url":"https://api.github.com/users/andyfaff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andyfaff/subscriptions","organizations_url":"https://api.github.com/users/andyfaff/orgs","repos_url":"https://api.github.com/users/andyfaff/repos","events_url":"https://api.github.com/users/andyfaff/events{/privacy}","received_events_url":"https://api.github.com/users/andyfaff/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/andyfaff/scipy","description":"Scipy main repository","fork":true,"url":"https://api.github.com/repos/andyfaff/scipy","forks_url":"https://api.github.com/repos/andyfaff/scipy/forks","keys_url":"https://api.github.com/repos/andyfaff/scipy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/andyfaff/scipy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/andyfaff/scipy/teams","hooks_url":"https://api.github.com/repos/andyfaff/scipy/hooks","issue_events_url":"https://api.github.com/repos/andyfaff/scipy/issues/events{/number}","events_url":"https://api.github.com/repos/andyfaff/scipy/events","assignees_url":"https://api.github.com/repos/andyfaff/scipy/assignees{/user}","branches_url":"https://api.github.com/repos/andyfaff/scipy/branches{/branch}","tags_url":"https://api.github.com/repos/andyfaff/scipy/tags","blobs_url":"https://api.github.com/repos/andyfaff/scipy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/andyfaff/scipy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/andyfaff/scipy/git/refs{/sha}","trees_url":"https://api.github.com/repos/andyfaff/scipy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/andyfaff/scipy/statuses/{sha}","languages_url":"https://api.github.com/repos/andyfaff/scipy/languages","stargazers_url":"https://api.github.com/repos/andyfaff/scipy/stargazers","contributors_url":"https://api.github.com/repos/andyfaff/scipy/contributors","subscribers_url":"https://api.github.com/repos/andyfaff/scipy/subscribers","subscription_url":"https://api.github.com/repos/andyfaff/scipy/subscription","commits_url":"https://api.github.com/repos/andyfaff/scipy/commits{/sha}","git_commits_url":"https://api.github.com/repos/andyfaff/scipy/git/commits{/sha}","comments_url":"https://api.github.com/repos/andyfaff/scipy/comments{/number}","issue_comment_url":"https://api.github.com/repos/andyfaff/scipy/issues/comments{/number}","contents_url":"https://api.github.com/repos/andyfaff/scipy/contents/{+path}","compare_url":"https://api.github.com/repos/andyfaff/scipy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/andyfaff/scipy/merges","archive_url":"https://api.github.com/repos/andyfaff/scipy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/andyfaff/scipy/downloads","issues_url":"https://api.github.com/repos/andyfaff/scipy/issues{/number}","pulls_url":"https://api.github.com/repos/andyfaff/scipy/pulls{/number}","milestones_url":"https://api.github.com/repos/andyfaff/scipy/milestones{/number}","notifications_url":"https://api.github.com/repos/andyfaff/scipy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/andyfaff/scipy/labels{/name}","releases_url":"https://api.github.com/repos/andyfaff/scipy/releases{/id}","created_at":"2014-03-04T04:46:50Z","updated_at":"2015-01-08T09:28:22Z","pushed_at":"2015-08-23T23:07:11Z","git_url":"git://github.com/andyfaff/scipy.git","ssh_url":"git@github.com:andyfaff/scipy.git","clone_url":"https://github.com/andyfaff/scipy.git","svn_url":"https://github.com/andyfaff/scipy","homepage":"http://scipy.org/","size":60077,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":0,"forks":2,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"scipy:master","ref":"master","sha":"ac598a1e28cd8c10066defdcbdaf1b7c59db37df","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}","created_at":"2011-03-09T18:52:03Z","updated_at":"2015-10-11T08:22:51Z","pushed_at":"2015-10-12T06:34:16Z","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":92852,"stargazers_count":1872,"watchers_count":1872,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1056,"mirror_url":null,"open_issues_count":903,"forks":1056,"open_issues":903,"watchers":1872,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scipy/scipy/pulls/5132"},"html":{"href":"https://github.com/scipy/scipy/pull/5132"},"issue":{"href":"https://api.github.com/repos/scipy/scipy/issues/5132"},"comments":{"href":"https://api.github.com/repos/scipy/scipy/issues/5132/comments"},"review_comments":{"href":"https://api.github.com/repos/scipy/scipy/pulls/5132/comments"},"review_comment":{"href":"https://api.github.com/repos/scipy/scipy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/scipy/scipy/pulls/5132/commits"},"statuses":{"href":"https://api.github.com/repos/scipy/scipy/statuses/39facc1f1f7aa9c4daf3c1dab1c81bbb7c4b936a"}}}}