{"action":"created","comment":{"url":"https://api.github.com/repos/stan-dev/stan/pulls/comments/45523502","id":45523502,"diff_hunk":"@@ -150,18 +157,170 @@ namespace stan {\n       }\n \n       /**\n-       * Runs stochastic gradient ascent with Adagrad.\n+       * Heuristic grid search to adapt eta to the scale of the problem.\n        *\n-       * @param  variational    variational distribution\n-       * @param  tol_rel_obj    relative tolerance parameter for convergence\n-       * @param  max_iterations max number of iterations to run algorithm\n+       * @param[in] variational initial variational distribution.\n+       * @param adapt_iterations number of iterations to spend doing stochastic\n+       * gradient ascent at each proposed eta value.\n+       * @return adapted (tuned) value of eta via heuristic grid search\n+       * @throw std::domain_error If either (a) the initial ELBO cannot be\n+       * computed at the initial variational distribution, (b) all step-size\n+       * proposals in eta_sequence fail.\n        */\n-      void robbins_monro_adagrad(Q& variational,\n+      double adapt_eta(Q& variational, int adapt_iterations) const {\n+        static const char* function = \"stan::variational::advi::adapt_eta\";\n+\n+        stan::math::check_positive(function,\n+                                   \"Number of adaptation iterations\",\n+                                   adapt_iterations);\n+\n+\n+        if (print_stream_) {\n+          *print_stream_ << \"Begin eta adaptation.\" << std::endl;\n+        }\n+\n+        // Sequence of eta values to try during adaptation\n+        std::queue<double> eta_sequence;","path":"src/stan/variational/advi.hpp","position":null,"original_position":174,"commit_id":"cf8fe029133251fff26c2ea155d3189df2f796a1","original_commit_id":"206dec3c7834ffbead341e150f37c944a9bd9995","user":{"login":"akucukelbir","id":329960,"avatar_url":"https://avatars.githubusercontent.com/u/329960?v=3","gravatar_id":"","url":"https://api.github.com/users/akucukelbir","html_url":"https://github.com/akucukelbir","followers_url":"https://api.github.com/users/akucukelbir/followers","following_url":"https://api.github.com/users/akucukelbir/following{/other_user}","gists_url":"https://api.github.com/users/akucukelbir/gists{/gist_id}","starred_url":"https://api.github.com/users/akucukelbir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akucukelbir/subscriptions","organizations_url":"https://api.github.com/users/akucukelbir/orgs","repos_url":"https://api.github.com/users/akucukelbir/repos","events_url":"https://api.github.com/users/akucukelbir/events{/privacy}","received_events_url":"https://api.github.com/users/akucukelbir/received_events","type":"User","site_admin":false},"body":"done.","created_at":"2015-11-20T21:53:52Z","updated_at":"2015-11-20T21:53:52Z","html_url":"https://github.com/stan-dev/stan/pull/1699#discussion_r45523502","pull_request_url":"https://api.github.com/repos/stan-dev/stan/pulls/1699","_links":{"self":{"href":"https://api.github.com/repos/stan-dev/stan/pulls/comments/45523502"},"html":{"href":"https://github.com/stan-dev/stan/pull/1699#discussion_r45523502"},"pull_request":{"href":"https://api.github.com/repos/stan-dev/stan/pulls/1699"}}},"pull_request":{"url":"https://api.github.com/repos/stan-dev/stan/pulls/1699","id":51285528,"html_url":"https://github.com/stan-dev/stan/pull/1699","diff_url":"https://github.com/stan-dev/stan/pull/1699.diff","patch_url":"https://github.com/stan-dev/stan/pull/1699.patch","issue_url":"https://api.github.com/repos/stan-dev/stan/issues/1699","number":1699,"state":"open","locked":false,"title":"ADVI stepsize sequence parameter (eta) adaptation","user":{"login":"akucukelbir","id":329960,"avatar_url":"https://avatars.githubusercontent.com/u/329960?v=3","gravatar_id":"","url":"https://api.github.com/users/akucukelbir","html_url":"https://github.com/akucukelbir","followers_url":"https://api.github.com/users/akucukelbir/followers","following_url":"https://api.github.com/users/akucukelbir/following{/other_user}","gists_url":"https://api.github.com/users/akucukelbir/gists{/gist_id}","starred_url":"https://api.github.com/users/akucukelbir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akucukelbir/subscriptions","organizations_url":"https://api.github.com/users/akucukelbir/orgs","repos_url":"https://api.github.com/users/akucukelbir/repos","events_url":"https://api.github.com/users/akucukelbir/events{/privacy}","received_events_url":"https://api.github.com/users/akucukelbir/received_events","type":"User","site_admin":false},"body":"#### Summary:\r\n\r\n(Note: goes with https://github.com/stan-dev/cmdstan/pull/223)\r\n\r\nImplements a heuristic grid-search for selecting a decent value for `eta`.\r\n\r\n- We do a grid search over `eta = (100, 10, 1, 0.1, 0.01)`\r\n- The grid search is robust; if `eta=100` is so big that ADVI diverges, it does not halt Stan.\r\n- We implement an adaptation argument structure that mimics NUTS. The new syntax is\r\n```\r\n./my_stanprogram variational eta=[1.0] adapt engaged=[0,1] iter=[50]\r\n```\r\nIf `adapt engaged=1`, then the value for `eta` (default or manual) is ignored. If `adapt engaged=0`, then the value for `eta` is used without any adaptation. `adapt iter` is the number of iterations to spend on each configuration of `eta` during the grid search.\r\n\r\n##### TODO\r\n- [x] Convert `queue` logic to something else.\r\n\r\n#### Intended Effect:\r\n\r\nMakes ADVI more \"black box\". It should converge faster and more reliably for more models than before.\r\n\r\n#### How to Verify:\r\n\r\nRun your favorite model. Run the tests. \r\n\r\n```\r\n$ ./runTests.py src/test/unit/variational\r\n```\r\n\r\nIt needs more tests. Here's a list:\r\n\r\n- [ ] Need to test `adapt_eta()` in `advi.hpp`\r\n- [ ] Need to test `stochastic_gradient_ascent()` in `advi.hpp`\r\n- [x] Need to test `src/stan/services/variational/print_progress.hpp`\r\n\r\n#### Side Effects:\r\n\r\nWe write the \"adapted\" value of eta into `output.csv`. This breaks the current `stanprint` summary functionality. So I had to adjust `src/stan/io/stan_csv_reader.hpp`. We could drop that change and take care of it elsewhere.\r\n\r\nWe no longer evaluate `lp` for all the draws from the posterior. I don't know when/how/why we decided to do this, but it's not useful and it slows down the final stage of ADVI significantly.\r\n\r\n#### Documentation:\r\n\r\n- [ ] write documentation in cmdstan manual\r\n- [ ] write documentation in stan manual\r\n\r\n#### Reviewer Suggestions:\r\n\r\nEveryone. I'd like everyone to be happy about these changes so that PyStan and RStan can interface to ADVI.","created_at":"2015-11-19T21:45:17Z","updated_at":"2015-11-20T21:53:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7081a50f7a4b0d86657b9359aca21d79b75a3a60","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/stan-dev/stan/pulls/1699/commits","review_comments_url":"https://api.github.com/repos/stan-dev/stan/pulls/1699/comments","review_comment_url":"https://api.github.com/repos/stan-dev/stan/pulls/comments{/number}","comments_url":"https://api.github.com/repos/stan-dev/stan/issues/1699/comments","statuses_url":"https://api.github.com/repos/stan-dev/stan/statuses/cf8fe029133251fff26c2ea155d3189df2f796a1","head":{"label":"stan-dev:feature/advi-tuning","ref":"feature/advi-tuning","sha":"cf8fe029133251fff26c2ea155d3189df2f796a1","user":{"login":"stan-dev","id":3374820,"avatar_url":"https://avatars.githubusercontent.com/u/3374820?v=3","gravatar_id":"","url":"https://api.github.com/users/stan-dev","html_url":"https://github.com/stan-dev","followers_url":"https://api.github.com/users/stan-dev/followers","following_url":"https://api.github.com/users/stan-dev/following{/other_user}","gists_url":"https://api.github.com/users/stan-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/stan-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stan-dev/subscriptions","organizations_url":"https://api.github.com/users/stan-dev/orgs","repos_url":"https://api.github.com/users/stan-dev/repos","events_url":"https://api.github.com/users/stan-dev/events{/privacy}","received_events_url":"https://api.github.com/users/stan-dev/received_events","type":"Organization","site_admin":false},"repo":{"id":8043756,"name":"stan","full_name":"stan-dev/stan","owner":{"login":"stan-dev","id":3374820,"avatar_url":"https://avatars.githubusercontent.com/u/3374820?v=3","gravatar_id":"","url":"https://api.github.com/users/stan-dev","html_url":"https://github.com/stan-dev","followers_url":"https://api.github.com/users/stan-dev/followers","following_url":"https://api.github.com/users/stan-dev/following{/other_user}","gists_url":"https://api.github.com/users/stan-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/stan-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stan-dev/subscriptions","organizations_url":"https://api.github.com/users/stan-dev/orgs","repos_url":"https://api.github.com/users/stan-dev/repos","events_url":"https://api.github.com/users/stan-dev/events{/privacy}","received_events_url":"https://api.github.com/users/stan-dev/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/stan-dev/stan","description":"Stan development repository (home page is linked below). The master branch contains the current release. The develop branch contains the latest stable development.  See the Developer Process Wiki for details.  ","fork":false,"url":"https://api.github.com/repos/stan-dev/stan","forks_url":"https://api.github.com/repos/stan-dev/stan/forks","keys_url":"https://api.github.com/repos/stan-dev/stan/keys{/key_id}","collaborators_url":"https://api.github.com/repos/stan-dev/stan/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/stan-dev/stan/teams","hooks_url":"https://api.github.com/repos/stan-dev/stan/hooks","issue_events_url":"https://api.github.com/repos/stan-dev/stan/issues/events{/number}","events_url":"https://api.github.com/repos/stan-dev/stan/events","assignees_url":"https://api.github.com/repos/stan-dev/stan/assignees{/user}","branches_url":"https://api.github.com/repos/stan-dev/stan/branches{/branch}","tags_url":"https://api.github.com/repos/stan-dev/stan/tags","blobs_url":"https://api.github.com/repos/stan-dev/stan/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/stan-dev/stan/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/stan-dev/stan/git/refs{/sha}","trees_url":"https://api.github.com/repos/stan-dev/stan/git/trees{/sha}","statuses_url":"https://api.github.com/repos/stan-dev/stan/statuses/{sha}","languages_url":"https://api.github.com/repos/stan-dev/stan/languages","stargazers_url":"https://api.github.com/repos/stan-dev/stan/stargazers","contributors_url":"https://api.github.com/repos/stan-dev/stan/contributors","subscribers_url":"https://api.github.com/repos/stan-dev/stan/subscribers","subscription_url":"https://api.github.com/repos/stan-dev/stan/subscription","commits_url":"https://api.github.com/repos/stan-dev/stan/commits{/sha}","git_commits_url":"https://api.github.com/repos/stan-dev/stan/git/commits{/sha}","comments_url":"https://api.github.com/repos/stan-dev/stan/comments{/number}","issue_comment_url":"https://api.github.com/repos/stan-dev/stan/issues/comments{/number}","contents_url":"https://api.github.com/repos/stan-dev/stan/contents/{+path}","compare_url":"https://api.github.com/repos/stan-dev/stan/compare/{base}...{head}","merges_url":"https://api.github.com/repos/stan-dev/stan/merges","archive_url":"https://api.github.com/repos/stan-dev/stan/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/stan-dev/stan/downloads","issues_url":"https://api.github.com/repos/stan-dev/stan/issues{/number}","pulls_url":"https://api.github.com/repos/stan-dev/stan/pulls{/number}","milestones_url":"https://api.github.com/repos/stan-dev/stan/milestones{/number}","notifications_url":"https://api.github.com/repos/stan-dev/stan/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/stan-dev/stan/labels{/name}","releases_url":"https://api.github.com/repos/stan-dev/stan/releases{/id}","created_at":"2013-02-06T03:25:04Z","updated_at":"2015-11-19T14:53:30Z","pushed_at":"2015-11-20T21:52:20Z","git_url":"git://github.com/stan-dev/stan.git","ssh_url":"git@github.com:stan-dev/stan.git","clone_url":"https://github.com/stan-dev/stan.git","svn_url":"https://github.com/stan-dev/stan","homepage":"http://mc-stan.org","size":218416,"stargazers_count":474,"watchers_count":474,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":113,"mirror_url":null,"open_issues_count":213,"forks":113,"open_issues":213,"watchers":474,"default_branch":"develop"}},"base":{"label":"stan-dev:develop","ref":"develop","sha":"3e380fa886acab742153b5031f7eabdfd467ea6e","user":{"login":"stan-dev","id":3374820,"avatar_url":"https://avatars.githubusercontent.com/u/3374820?v=3","gravatar_id":"","url":"https://api.github.com/users/stan-dev","html_url":"https://github.com/stan-dev","followers_url":"https://api.github.com/users/stan-dev/followers","following_url":"https://api.github.com/users/stan-dev/following{/other_user}","gists_url":"https://api.github.com/users/stan-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/stan-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stan-dev/subscriptions","organizations_url":"https://api.github.com/users/stan-dev/orgs","repos_url":"https://api.github.com/users/stan-dev/repos","events_url":"https://api.github.com/users/stan-dev/events{/privacy}","received_events_url":"https://api.github.com/users/stan-dev/received_events","type":"Organization","site_admin":false},"repo":{"id":8043756,"name":"stan","full_name":"stan-dev/stan","owner":{"login":"stan-dev","id":3374820,"avatar_url":"https://avatars.githubusercontent.com/u/3374820?v=3","gravatar_id":"","url":"https://api.github.com/users/stan-dev","html_url":"https://github.com/stan-dev","followers_url":"https://api.github.com/users/stan-dev/followers","following_url":"https://api.github.com/users/stan-dev/following{/other_user}","gists_url":"https://api.github.com/users/stan-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/stan-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stan-dev/subscriptions","organizations_url":"https://api.github.com/users/stan-dev/orgs","repos_url":"https://api.github.com/users/stan-dev/repos","events_url":"https://api.github.com/users/stan-dev/events{/privacy}","received_events_url":"https://api.github.com/users/stan-dev/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/stan-dev/stan","description":"Stan development repository (home page is linked below). The master branch contains the current release. The develop branch contains the latest stable development.  See the Developer Process Wiki for details.  ","fork":false,"url":"https://api.github.com/repos/stan-dev/stan","forks_url":"https://api.github.com/repos/stan-dev/stan/forks","keys_url":"https://api.github.com/repos/stan-dev/stan/keys{/key_id}","collaborators_url":"https://api.github.com/repos/stan-dev/stan/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/stan-dev/stan/teams","hooks_url":"https://api.github.com/repos/stan-dev/stan/hooks","issue_events_url":"https://api.github.com/repos/stan-dev/stan/issues/events{/number}","events_url":"https://api.github.com/repos/stan-dev/stan/events","assignees_url":"https://api.github.com/repos/stan-dev/stan/assignees{/user}","branches_url":"https://api.github.com/repos/stan-dev/stan/branches{/branch}","tags_url":"https://api.github.com/repos/stan-dev/stan/tags","blobs_url":"https://api.github.com/repos/stan-dev/stan/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/stan-dev/stan/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/stan-dev/stan/git/refs{/sha}","trees_url":"https://api.github.com/repos/stan-dev/stan/git/trees{/sha}","statuses_url":"https://api.github.com/repos/stan-dev/stan/statuses/{sha}","languages_url":"https://api.github.com/repos/stan-dev/stan/languages","stargazers_url":"https://api.github.com/repos/stan-dev/stan/stargazers","contributors_url":"https://api.github.com/repos/stan-dev/stan/contributors","subscribers_url":"https://api.github.com/repos/stan-dev/stan/subscribers","subscription_url":"https://api.github.com/repos/stan-dev/stan/subscription","commits_url":"https://api.github.com/repos/stan-dev/stan/commits{/sha}","git_commits_url":"https://api.github.com/repos/stan-dev/stan/git/commits{/sha}","comments_url":"https://api.github.com/repos/stan-dev/stan/comments{/number}","issue_comment_url":"https://api.github.com/repos/stan-dev/stan/issues/comments{/number}","contents_url":"https://api.github.com/repos/stan-dev/stan/contents/{+path}","compare_url":"https://api.github.com/repos/stan-dev/stan/compare/{base}...{head}","merges_url":"https://api.github.com/repos/stan-dev/stan/merges","archive_url":"https://api.github.com/repos/stan-dev/stan/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/stan-dev/stan/downloads","issues_url":"https://api.github.com/repos/stan-dev/stan/issues{/number}","pulls_url":"https://api.github.com/repos/stan-dev/stan/pulls{/number}","milestones_url":"https://api.github.com/repos/stan-dev/stan/milestones{/number}","notifications_url":"https://api.github.com/repos/stan-dev/stan/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/stan-dev/stan/labels{/name}","releases_url":"https://api.github.com/repos/stan-dev/stan/releases{/id}","created_at":"2013-02-06T03:25:04Z","updated_at":"2015-11-19T14:53:30Z","pushed_at":"2015-11-20T21:52:20Z","git_url":"git://github.com/stan-dev/stan.git","ssh_url":"git@github.com:stan-dev/stan.git","clone_url":"https://github.com/stan-dev/stan.git","svn_url":"https://github.com/stan-dev/stan","homepage":"http://mc-stan.org","size":218416,"stargazers_count":474,"watchers_count":474,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":113,"mirror_url":null,"open_issues_count":213,"forks":113,"open_issues":213,"watchers":474,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/stan-dev/stan/pulls/1699"},"html":{"href":"https://github.com/stan-dev/stan/pull/1699"},"issue":{"href":"https://api.github.com/repos/stan-dev/stan/issues/1699"},"comments":{"href":"https://api.github.com/repos/stan-dev/stan/issues/1699/comments"},"review_comments":{"href":"https://api.github.com/repos/stan-dev/stan/pulls/1699/comments"},"review_comment":{"href":"https://api.github.com/repos/stan-dev/stan/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/stan-dev/stan/pulls/1699/commits"},"statuses":{"href":"https://api.github.com/repos/stan-dev/stan/statuses/cf8fe029133251fff26c2ea155d3189df2f796a1"}}}}