{"action":"created","comment":{"url":"https://api.github.com/repos/improbable-research/keanu/pulls/comments/197752950","pull_request_review_id":131554911,"id":197752950,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5Nzc1Mjk1MA==","diff_hunk":"@@ -528,6 +601,67 @@ private static void addSampleFromCache(Map<Long, List<?>> samples, Map<Long, ?>\n             this.sampleAtAcceptedPosition = sampleAtAcceptedPosition;\n             this.acceptedLeapfrogCount = acceptedLeapfrogCount;\n             this.shouldContinueFlag = shouldContinueFlag;\n+            this.deltaLikelihoodOfLeapfrog = deltaLikelihoodOfLeapfrog;\n+            this.treeSize = treeSize;\n+        }\n+    }\n+\n+    private static class AutoTune {\n+\n+        double stepSize;\n+        double averageAcceptanceProb;\n+        double targetAcceptanceProb;\n+        double logStepSize;\n+        double logStepSizeFrozen;\n+        double adaptCount;\n+        double shrinkageTarget;\n+\n+        AutoTune(double stepSize, double targetAcceptanceProb, double logStepSize, int adaptCount) {\n+            this.stepSize = stepSize;\n+            this.averageAcceptanceProb = 0;\n+            this.targetAcceptanceProb = targetAcceptanceProb;\n+            this.logStepSize = logStepSize;\n+            this.logStepSizeFrozen = Math.log(1);\n+            this.adaptCount = adaptCount;\n+            this.shrinkageTarget = Math.log(10 * stepSize);\n+        }\n+    }\n+\n+    private static double findStartingStepSize(Map<Long, DoubleTensor> position,\n+                                               Map<Long, DoubleTensor> gradient,\n+                                               List<Vertex<DoubleTensor>> vertices,\n+                                               List<Vertex> probabilisticVertices,\n+                                               Map<Long, Long> latentSetAndCascadeCache,\n+                                               KeanuRandom random) {\n+        double stepsize = 1;\n+        double probBeforeLeapfrog = Math.exp(getLogProb(probabilisticVertices));\n+        Map<Long, DoubleTensor> momentums = new HashMap<>();\n+        initializeMomentumForEachVertex(vertices, momentums, random);\n+        leapfrog(vertices, latentSetAndCascadeCache, probabilisticVertices, position, gradient, momentums, stepsize);\n+        double probAfterLeapfrog = Math.exp(getLogProb(probabilisticVertices));\n+        double likelihoodRatio = probAfterLeapfrog / probBeforeLeapfrog;\n+        double scalingFactor = likelihoodRatio > 0.5 ? 1 : -1;\n+\n+        while (Math.pow(likelihoodRatio, scalingFactor) > Math.pow(2, -scalingFactor)) {\n+            stepsize = stepsize * Math.pow(2, scalingFactor);\n+            leapfrog(vertices, latentSetAndCascadeCache, probabilisticVertices, position, gradient, momentums, stepsize);\n+            likelihoodRatio = Math.exp(getLogProb(probabilisticVertices)) / probBeforeLeapfrog;\n+        }\n+\n+        return stepsize;\n+    }\n+\n+    private static double adaptStepSize(AutoTune autoTune, BuiltTree tree, int sampleNum) {\n+        if (sampleNum <= autoTune.adaptCount) {\n+            double percentageLeftToTune = (1 / (sampleNum + STABILISER));","path":"keanu-project/src/main/java/io/improbable/keanu/algorithms/mcmc/NUTS.java","position":296,"original_position":296,"commit_id":"358e93722491985b260b3f96fd89b34e2609687f","original_commit_id":"358e93722491985b260b3f96fd89b34e2609687f","user":{"login":"GeorgeNash","id":5854544,"node_id":"MDQ6VXNlcjU4NTQ1NDQ=","avatar_url":"https://avatars1.githubusercontent.com/u/5854544?v=4","gravatar_id":"","url":"https://api.github.com/users/GeorgeNash","html_url":"https://github.com/GeorgeNash","followers_url":"https://api.github.com/users/GeorgeNash/followers","following_url":"https://api.github.com/users/GeorgeNash/following{/other_user}","gists_url":"https://api.github.com/users/GeorgeNash/gists{/gist_id}","starred_url":"https://api.github.com/users/GeorgeNash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GeorgeNash/subscriptions","organizations_url":"https://api.github.com/users/GeorgeNash/orgs","repos_url":"https://api.github.com/users/GeorgeNash/repos","events_url":"https://api.github.com/users/GeorgeNash/events{/privacy}","received_events_url":"https://api.github.com/users/GeorgeNash/received_events","type":"User","site_admin":false},"body":"Yeah good idea, looks a bit intense doesn't it. I've improved the formatting.","created_at":"2018-06-25T10:45:04Z","updated_at":"2018-06-25T10:45:04Z","html_url":"https://github.com/improbable-research/keanu/pull/100#discussion_r197752950","pull_request_url":"https://api.github.com/repos/improbable-research/keanu/pulls/100","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/improbable-research/keanu/pulls/comments/197752950"},"html":{"href":"https://github.com/improbable-research/keanu/pull/100#discussion_r197752950"},"pull_request":{"href":"https://api.github.com/repos/improbable-research/keanu/pulls/100"}},"in_reply_to_id":197731519},"pull_request":{"url":"https://api.github.com/repos/improbable-research/keanu/pulls/100","id":196207914,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk2MjA3OTE0","html_url":"https://github.com/improbable-research/keanu/pull/100","diff_url":"https://github.com/improbable-research/keanu/pull/100.diff","patch_url":"https://github.com/improbable-research/keanu/pull/100.patch","issue_url":"https://api.github.com/repos/improbable-research/keanu/issues/100","number":100,"state":"open","locked":false,"title":"NUTS Algo 6","user":{"login":"GeorgeNash","id":5854544,"node_id":"MDQ6VXNlcjU4NTQ1NDQ=","avatar_url":"https://avatars1.githubusercontent.com/u/5854544?v=4","gravatar_id":"","url":"https://api.github.com/users/GeorgeNash","html_url":"https://github.com/GeorgeNash","followers_url":"https://api.github.com/users/GeorgeNash/followers","following_url":"https://api.github.com/users/GeorgeNash/following{/other_user}","gists_url":"https://api.github.com/users/GeorgeNash/gists{/gist_id}","starred_url":"https://api.github.com/users/GeorgeNash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GeorgeNash/subscriptions","organizations_url":"https://api.github.com/users/GeorgeNash/orgs","repos_url":"https://api.github.com/users/GeorgeNash/repos","events_url":"https://api.github.com/users/GeorgeNash/events{/privacy}","received_events_url":"https://api.github.com/users/GeorgeNash/received_events","type":"User","site_admin":false},"body":"NUTS Algorithm 6 from: https://arxiv.org/pdf/1111.4246.pdf\r\n\r\nThis calculates a best starting point for the stepsize and tunes the stepsize every sample for a parameterizable amount of samples.","created_at":"2018-06-20T16:51:18Z","updated_at":"2018-06-25T10:45:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f630a8ecb4dca702c3dbbaa7794307decb43a9a7","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/improbable-research/keanu/pulls/100/commits","review_comments_url":"https://api.github.com/repos/improbable-research/keanu/pulls/100/comments","review_comment_url":"https://api.github.com/repos/improbable-research/keanu/pulls/comments{/number}","comments_url":"https://api.github.com/repos/improbable-research/keanu/issues/100/comments","statuses_url":"https://api.github.com/repos/improbable-research/keanu/statuses/358e93722491985b260b3f96fd89b34e2609687f","head":{"label":"improbable-research:feature/nutsAlgo6","ref":"feature/nutsAlgo6","sha":"358e93722491985b260b3f96fd89b34e2609687f","user":{"login":"improbable-research","id":37903994,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM3OTAzOTk0","avatar_url":"https://avatars1.githubusercontent.com/u/37903994?v=4","gravatar_id":"","url":"https://api.github.com/users/improbable-research","html_url":"https://github.com/improbable-research","followers_url":"https://api.github.com/users/improbable-research/followers","following_url":"https://api.github.com/users/improbable-research/following{/other_user}","gists_url":"https://api.github.com/users/improbable-research/gists{/gist_id}","starred_url":"https://api.github.com/users/improbable-research/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/improbable-research/subscriptions","organizations_url":"https://api.github.com/users/improbable-research/orgs","repos_url":"https://api.github.com/users/improbable-research/repos","events_url":"https://api.github.com/users/improbable-research/events{/privacy}","received_events_url":"https://api.github.com/users/improbable-research/received_events","type":"Organization","site_admin":false},"repo":{"id":128393918,"node_id":"MDEwOlJlcG9zaXRvcnkxMjgzOTM5MTg=","name":"keanu","full_name":"improbable-research/keanu","owner":{"login":"improbable-research","id":37903994,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM3OTAzOTk0","avatar_url":"https://avatars1.githubusercontent.com/u/37903994?v=4","gravatar_id":"","url":"https://api.github.com/users/improbable-research","html_url":"https://github.com/improbable-research","followers_url":"https://api.github.com/users/improbable-research/followers","following_url":"https://api.github.com/users/improbable-research/following{/other_user}","gists_url":"https://api.github.com/users/improbable-research/gists{/gist_id}","starred_url":"https://api.github.com/users/improbable-research/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/improbable-research/subscriptions","organizations_url":"https://api.github.com/users/improbable-research/orgs","repos_url":"https://api.github.com/users/improbable-research/repos","events_url":"https://api.github.com/users/improbable-research/events{/privacy}","received_events_url":"https://api.github.com/users/improbable-research/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/improbable-research/keanu","description":"A probabilistic approach from an Improbabilistic company","fork":false,"url":"https://api.github.com/repos/improbable-research/keanu","forks_url":"https://api.github.com/repos/improbable-research/keanu/forks","keys_url":"https://api.github.com/repos/improbable-research/keanu/keys{/key_id}","collaborators_url":"https://api.github.com/repos/improbable-research/keanu/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/improbable-research/keanu/teams","hooks_url":"https://api.github.com/repos/improbable-research/keanu/hooks","issue_events_url":"https://api.github.com/repos/improbable-research/keanu/issues/events{/number}","events_url":"https://api.github.com/repos/improbable-research/keanu/events","assignees_url":"https://api.github.com/repos/improbable-research/keanu/assignees{/user}","branches_url":"https://api.github.com/repos/improbable-research/keanu/branches{/branch}","tags_url":"https://api.github.com/repos/improbable-research/keanu/tags","blobs_url":"https://api.github.com/repos/improbable-research/keanu/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/improbable-research/keanu/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/improbable-research/keanu/git/refs{/sha}","trees_url":"https://api.github.com/repos/improbable-research/keanu/git/trees{/sha}","statuses_url":"https://api.github.com/repos/improbable-research/keanu/statuses/{sha}","languages_url":"https://api.github.com/repos/improbable-research/keanu/languages","stargazers_url":"https://api.github.com/repos/improbable-research/keanu/stargazers","contributors_url":"https://api.github.com/repos/improbable-research/keanu/contributors","subscribers_url":"https://api.github.com/repos/improbable-research/keanu/subscribers","subscription_url":"https://api.github.com/repos/improbable-research/keanu/subscription","commits_url":"https://api.github.com/repos/improbable-research/keanu/commits{/sha}","git_commits_url":"https://api.github.com/repos/improbable-research/keanu/git/commits{/sha}","comments_url":"https://api.github.com/repos/improbable-research/keanu/comments{/number}","issue_comment_url":"https://api.github.com/repos/improbable-research/keanu/issues/comments{/number}","contents_url":"https://api.github.com/repos/improbable-research/keanu/contents/{+path}","compare_url":"https://api.github.com/repos/improbable-research/keanu/compare/{base}...{head}","merges_url":"https://api.github.com/repos/improbable-research/keanu/merges","archive_url":"https://api.github.com/repos/improbable-research/keanu/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/improbable-research/keanu/downloads","issues_url":"https://api.github.com/repos/improbable-research/keanu/issues{/number}","pulls_url":"https://api.github.com/repos/improbable-research/keanu/pulls{/number}","milestones_url":"https://api.github.com/repos/improbable-research/keanu/milestones{/number}","notifications_url":"https://api.github.com/repos/improbable-research/keanu/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/improbable-research/keanu/labels{/name}","releases_url":"https://api.github.com/repos/improbable-research/keanu/releases{/id}","deployments_url":"https://api.github.com/repos/improbable-research/keanu/deployments","created_at":"2018-04-06T12:48:36Z","updated_at":"2018-06-20T22:02:06Z","pushed_at":"2018-06-25T08:21:31Z","git_url":"git://github.com/improbable-research/keanu.git","ssh_url":"git@github.com:improbable-research/keanu.git","clone_url":"https://github.com/improbable-research/keanu.git","svn_url":"https://github.com/improbable-research/keanu","homepage":"","size":2342,"stargazers_count":63,"watchers_count":63,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":12,"mirror_url":null,"archived":false,"open_issues_count":3,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":12,"open_issues":3,"watchers":63,"default_branch":"develop"}},"base":{"label":"improbable-research:develop","ref":"develop","sha":"2e9c0c6cafd931c37a76d04e194b6c5baea8c5c1","user":{"login":"improbable-research","id":37903994,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM3OTAzOTk0","avatar_url":"https://avatars1.githubusercontent.com/u/37903994?v=4","gravatar_id":"","url":"https://api.github.com/users/improbable-research","html_url":"https://github.com/improbable-research","followers_url":"https://api.github.com/users/improbable-research/followers","following_url":"https://api.github.com/users/improbable-research/following{/other_user}","gists_url":"https://api.github.com/users/improbable-research/gists{/gist_id}","starred_url":"https://api.github.com/users/improbable-research/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/improbable-research/subscriptions","organizations_url":"https://api.github.com/users/improbable-research/orgs","repos_url":"https://api.github.com/users/improbable-research/repos","events_url":"https://api.github.com/users/improbable-research/events{/privacy}","received_events_url":"https://api.github.com/users/improbable-research/received_events","type":"Organization","site_admin":false},"repo":{"id":128393918,"node_id":"MDEwOlJlcG9zaXRvcnkxMjgzOTM5MTg=","name":"keanu","full_name":"improbable-research/keanu","owner":{"login":"improbable-research","id":37903994,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM3OTAzOTk0","avatar_url":"https://avatars1.githubusercontent.com/u/37903994?v=4","gravatar_id":"","url":"https://api.github.com/users/improbable-research","html_url":"https://github.com/improbable-research","followers_url":"https://api.github.com/users/improbable-research/followers","following_url":"https://api.github.com/users/improbable-research/following{/other_user}","gists_url":"https://api.github.com/users/improbable-research/gists{/gist_id}","starred_url":"https://api.github.com/users/improbable-research/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/improbable-research/subscriptions","organizations_url":"https://api.github.com/users/improbable-research/orgs","repos_url":"https://api.github.com/users/improbable-research/repos","events_url":"https://api.github.com/users/improbable-research/events{/privacy}","received_events_url":"https://api.github.com/users/improbable-research/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/improbable-research/keanu","description":"A probabilistic approach from an Improbabilistic company","fork":false,"url":"https://api.github.com/repos/improbable-research/keanu","forks_url":"https://api.github.com/repos/improbable-research/keanu/forks","keys_url":"https://api.github.com/repos/improbable-research/keanu/keys{/key_id}","collaborators_url":"https://api.github.com/repos/improbable-research/keanu/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/improbable-research/keanu/teams","hooks_url":"https://api.github.com/repos/improbable-research/keanu/hooks","issue_events_url":"https://api.github.com/repos/improbable-research/keanu/issues/events{/number}","events_url":"https://api.github.com/repos/improbable-research/keanu/events","assignees_url":"https://api.github.com/repos/improbable-research/keanu/assignees{/user}","branches_url":"https://api.github.com/repos/improbable-research/keanu/branches{/branch}","tags_url":"https://api.github.com/repos/improbable-research/keanu/tags","blobs_url":"https://api.github.com/repos/improbable-research/keanu/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/improbable-research/keanu/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/improbable-research/keanu/git/refs{/sha}","trees_url":"https://api.github.com/repos/improbable-research/keanu/git/trees{/sha}","statuses_url":"https://api.github.com/repos/improbable-research/keanu/statuses/{sha}","languages_url":"https://api.github.com/repos/improbable-research/keanu/languages","stargazers_url":"https://api.github.com/repos/improbable-research/keanu/stargazers","contributors_url":"https://api.github.com/repos/improbable-research/keanu/contributors","subscribers_url":"https://api.github.com/repos/improbable-research/keanu/subscribers","subscription_url":"https://api.github.com/repos/improbable-research/keanu/subscription","commits_url":"https://api.github.com/repos/improbable-research/keanu/commits{/sha}","git_commits_url":"https://api.github.com/repos/improbable-research/keanu/git/commits{/sha}","comments_url":"https://api.github.com/repos/improbable-research/keanu/comments{/number}","issue_comment_url":"https://api.github.com/repos/improbable-research/keanu/issues/comments{/number}","contents_url":"https://api.github.com/repos/improbable-research/keanu/contents/{+path}","compare_url":"https://api.github.com/repos/improbable-research/keanu/compare/{base}...{head}","merges_url":"https://api.github.com/repos/improbable-research/keanu/merges","archive_url":"https://api.github.com/repos/improbable-research/keanu/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/improbable-research/keanu/downloads","issues_url":"https://api.github.com/repos/improbable-research/keanu/issues{/number}","pulls_url":"https://api.github.com/repos/improbable-research/keanu/pulls{/number}","milestones_url":"https://api.github.com/repos/improbable-research/keanu/milestones{/number}","notifications_url":"https://api.github.com/repos/improbable-research/keanu/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/improbable-research/keanu/labels{/name}","releases_url":"https://api.github.com/repos/improbable-research/keanu/releases{/id}","deployments_url":"https://api.github.com/repos/improbable-research/keanu/deployments","created_at":"2018-04-06T12:48:36Z","updated_at":"2018-06-20T22:02:06Z","pushed_at":"2018-06-25T08:21:31Z","git_url":"git://github.com/improbable-research/keanu.git","ssh_url":"git@github.com:improbable-research/keanu.git","clone_url":"https://github.com/improbable-research/keanu.git","svn_url":"https://github.com/improbable-research/keanu","homepage":"","size":2342,"stargazers_count":63,"watchers_count":63,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":12,"mirror_url":null,"archived":false,"open_issues_count":3,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":12,"open_issues":3,"watchers":63,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/improbable-research/keanu/pulls/100"},"html":{"href":"https://github.com/improbable-research/keanu/pull/100"},"issue":{"href":"https://api.github.com/repos/improbable-research/keanu/issues/100"},"comments":{"href":"https://api.github.com/repos/improbable-research/keanu/issues/100/comments"},"review_comments":{"href":"https://api.github.com/repos/improbable-research/keanu/pulls/100/comments"},"review_comment":{"href":"https://api.github.com/repos/improbable-research/keanu/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/improbable-research/keanu/pulls/100/commits"},"statuses":{"href":"https://api.github.com/repos/improbable-research/keanu/statuses/358e93722491985b260b3f96fd89b34e2609687f"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"GeorgeNash"}}