{"action":"created","comment":{"url":"https://api.github.com/repos/tianheyu927/gps/pulls/comments/68516848","id":68516848,"diff_hunk":"@@ -50,9 +55,78 @@ def forward(self, bottom, top):\n \n         # TODO(kevin) implement this (look at ioc_loss_layer.cpp in caffe)\n         # python/gps/algorithm/policy_opt/policy_layers.py might also be helpful\n+        loss = 0.0\n+        dc = self.demo_counts_\n+        sc = self.sample_counts_\n+\n+        # log importance weights of demos and samples.\n+        d_log_iw = bottom[2].data\n+        s_log_iw = bottom[3].data\n+\n+        # Sum over time and compute max value for safe logsum.\n+        for i in xrange(self.num_demos):\n+            dc[i] = 0.0\n+            for t in xrange(self.T):\n+                dc[i] += 0.5 * bottom[0].data[i, t, 0] # Not sure why the feature should be 0\n+            loss += dc[i]\n+            # Add importance weight to demo feature count. Will be negated.\n+            dc[i] += d_log_iw[i]\n+        # Divide by number of demos.\n+        loss /= self.num_demos\n+\n+        max_val = -dc[0]\n+        for i in xrange(self.num_samples):\n+            sc[i] = 0.0\n+            for t in xrange(self.T):\n+                sc[i] += 0.5 * bottom[1].data[i, t, 0]\n+            # Add importance weight to demo feature count. Will be negated.\n+            sc[i] += s_log_iw[i]\n+            if -sc[i] > max_val:\n+                max_val = -sc[i]\n+\n+        # Do a safe log-sum-exp operation.\n+        append_demos = self.layer_params['append_demos'] # We need to set this somewhere?\n+        if append_demos:\n+            for i in xrange(self.num_demos):\n+                if -dc[i] > max_val:\n+                    max_val = -dc[i]\n+            for i in xrange(self.num_demos):\n+                dc[i] = -dc[i] - max_val\n+        for i in xrange(self.num_samples):\n+            sc[i] = -sc[i] - max_val\n+        dc = np.exp(dc)\n+        sc = np.exp(sc)\n+\n+        self.partition = 0.0\n+        if append_demos:\n+            self.partition += np.sum(dc, axis = 0)\n+        self.partition += np.sum(sc, axis = 0)\n+        loss += np.log(self.partition) + max_val\n+        top[0].data[...] = loss\n+        # Need to increment iteration here?\n \n     def backward(self, top, propagate_down, bottom):\n         # compute backward pass (derivative of objective w.r.t. bottom)\n-        batch_size = bottom[0].shape[0]\n+        batch_size = bottom[0].shape[0] # Do we need to use this here?","path":"python/gps/algorithm/cost/ioc_layers.py","position":null,"original_position":82,"commit_id":"d2029c3f9f907be49870cdb8980d4471d9d9d2d0","original_commit_id":"d2029c3f9f907be49870cdb8980d4471d9d9d2d0","user":{"login":"cbfinn","id":1254657,"avatar_url":"https://avatars.githubusercontent.com/u/1254657?v=3","gravatar_id":"","url":"https://api.github.com/users/cbfinn","html_url":"https://github.com/cbfinn","followers_url":"https://api.github.com/users/cbfinn/followers","following_url":"https://api.github.com/users/cbfinn/following{/other_user}","gists_url":"https://api.github.com/users/cbfinn/gists{/gist_id}","starred_url":"https://api.github.com/users/cbfinn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cbfinn/subscriptions","organizations_url":"https://api.github.com/users/cbfinn/orgs","repos_url":"https://api.github.com/users/cbfinn/repos","events_url":"https://api.github.com/users/cbfinn/events{/privacy}","received_events_url":"https://api.github.com/users/cbfinn/received_events","type":"User","site_admin":false},"body":"no, we can remove it.","created_at":"2016-06-27T02:26:22Z","updated_at":"2016-06-27T02:26:22Z","html_url":"https://github.com/tianheyu927/gps/pull/1#discussion_r68516848","pull_request_url":"https://api.github.com/repos/tianheyu927/gps/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/tianheyu927/gps/pulls/comments/68516848"},"html":{"href":"https://github.com/tianheyu927/gps/pull/1#discussion_r68516848"},"pull_request":{"href":"https://api.github.com/repos/tianheyu927/gps/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/tianheyu927/gps/pulls/1","id":74543359,"html_url":"https://github.com/tianheyu927/gps/pull/1","diff_url":"https://github.com/tianheyu927/gps/pull/1.diff","patch_url":"https://github.com/tianheyu927/gps/pull/1.patch","issue_url":"https://api.github.com/repos/tianheyu927/gps/issues/1","number":1,"state":"open","locked":false,"title":"Kevin update","user":{"login":"cbfinn","id":1254657,"avatar_url":"https://avatars.githubusercontent.com/u/1254657?v=3","gravatar_id":"","url":"https://api.github.com/users/cbfinn","html_url":"https://github.com/cbfinn","followers_url":"https://api.github.com/users/cbfinn/followers","following_url":"https://api.github.com/users/cbfinn/following{/other_user}","gists_url":"https://api.github.com/users/cbfinn/gists{/gist_id}","starred_url":"https://api.github.com/users/cbfinn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cbfinn/subscriptions","organizations_url":"https://api.github.com/users/cbfinn/orgs","repos_url":"https://api.github.com/users/cbfinn/repos","events_url":"https://api.github.com/users/cbfinn/events{/privacy}","received_events_url":"https://api.github.com/users/cbfinn/received_events","type":"User","site_admin":false},"body":"Making a PR so I can comment direction on the code.","created_at":"2016-06-21T02:36:54Z","updated_at":"2016-06-27T02:26:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"59f413964791a93749e3388793e2b94a15d4de22","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/tianheyu927/gps/pulls/1/commits","review_comments_url":"https://api.github.com/repos/tianheyu927/gps/pulls/1/comments","review_comment_url":"https://api.github.com/repos/tianheyu927/gps/pulls/comments{/number}","comments_url":"https://api.github.com/repos/tianheyu927/gps/issues/1/comments","statuses_url":"https://api.github.com/repos/tianheyu927/gps/statuses/d2029c3f9f907be49870cdb8980d4471d9d9d2d0","head":{"label":"tianheyu927:kevin_update","ref":"kevin_update","sha":"d2029c3f9f907be49870cdb8980d4471d9d9d2d0","user":{"login":"tianheyu927","id":14038135,"avatar_url":"https://avatars.githubusercontent.com/u/14038135?v=3","gravatar_id":"","url":"https://api.github.com/users/tianheyu927","html_url":"https://github.com/tianheyu927","followers_url":"https://api.github.com/users/tianheyu927/followers","following_url":"https://api.github.com/users/tianheyu927/following{/other_user}","gists_url":"https://api.github.com/users/tianheyu927/gists{/gist_id}","starred_url":"https://api.github.com/users/tianheyu927/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tianheyu927/subscriptions","organizations_url":"https://api.github.com/users/tianheyu927/orgs","repos_url":"https://api.github.com/users/tianheyu927/repos","events_url":"https://api.github.com/users/tianheyu927/events{/privacy}","received_events_url":"https://api.github.com/users/tianheyu927/received_events","type":"User","site_admin":false},"repo":{"id":61260810,"name":"gps","full_name":"tianheyu927/gps","owner":{"login":"tianheyu927","id":14038135,"avatar_url":"https://avatars.githubusercontent.com/u/14038135?v=3","gravatar_id":"","url":"https://api.github.com/users/tianheyu927","html_url":"https://github.com/tianheyu927","followers_url":"https://api.github.com/users/tianheyu927/followers","following_url":"https://api.github.com/users/tianheyu927/following{/other_user}","gists_url":"https://api.github.com/users/tianheyu927/gists{/gist_id}","starred_url":"https://api.github.com/users/tianheyu927/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tianheyu927/subscriptions","organizations_url":"https://api.github.com/users/tianheyu927/orgs","repos_url":"https://api.github.com/users/tianheyu927/repos","events_url":"https://api.github.com/users/tianheyu927/events{/privacy}","received_events_url":"https://api.github.com/users/tianheyu927/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tianheyu927/gps","description":"Guided Policy Search","fork":true,"url":"https://api.github.com/repos/tianheyu927/gps","forks_url":"https://api.github.com/repos/tianheyu927/gps/forks","keys_url":"https://api.github.com/repos/tianheyu927/gps/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tianheyu927/gps/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tianheyu927/gps/teams","hooks_url":"https://api.github.com/repos/tianheyu927/gps/hooks","issue_events_url":"https://api.github.com/repos/tianheyu927/gps/issues/events{/number}","events_url":"https://api.github.com/repos/tianheyu927/gps/events","assignees_url":"https://api.github.com/repos/tianheyu927/gps/assignees{/user}","branches_url":"https://api.github.com/repos/tianheyu927/gps/branches{/branch}","tags_url":"https://api.github.com/repos/tianheyu927/gps/tags","blobs_url":"https://api.github.com/repos/tianheyu927/gps/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tianheyu927/gps/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tianheyu927/gps/git/refs{/sha}","trees_url":"https://api.github.com/repos/tianheyu927/gps/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tianheyu927/gps/statuses/{sha}","languages_url":"https://api.github.com/repos/tianheyu927/gps/languages","stargazers_url":"https://api.github.com/repos/tianheyu927/gps/stargazers","contributors_url":"https://api.github.com/repos/tianheyu927/gps/contributors","subscribers_url":"https://api.github.com/repos/tianheyu927/gps/subscribers","subscription_url":"https://api.github.com/repos/tianheyu927/gps/subscription","commits_url":"https://api.github.com/repos/tianheyu927/gps/commits{/sha}","git_commits_url":"https://api.github.com/repos/tianheyu927/gps/git/commits{/sha}","comments_url":"https://api.github.com/repos/tianheyu927/gps/comments{/number}","issue_comment_url":"https://api.github.com/repos/tianheyu927/gps/issues/comments{/number}","contents_url":"https://api.github.com/repos/tianheyu927/gps/contents/{+path}","compare_url":"https://api.github.com/repos/tianheyu927/gps/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tianheyu927/gps/merges","archive_url":"https://api.github.com/repos/tianheyu927/gps/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tianheyu927/gps/downloads","issues_url":"https://api.github.com/repos/tianheyu927/gps/issues{/number}","pulls_url":"https://api.github.com/repos/tianheyu927/gps/pulls{/number}","milestones_url":"https://api.github.com/repos/tianheyu927/gps/milestones{/number}","notifications_url":"https://api.github.com/repos/tianheyu927/gps/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tianheyu927/gps/labels{/name}","releases_url":"https://api.github.com/repos/tianheyu927/gps/releases{/id}","deployments_url":"https://api.github.com/repos/tianheyu927/gps/deployments","created_at":"2016-06-16T03:57:53Z","updated_at":"2016-06-16T03:57:55Z","pushed_at":"2016-06-26T23:26:16Z","git_url":"git://github.com/tianheyu927/gps.git","ssh_url":"git@github.com:tianheyu927/gps.git","clone_url":"https://github.com/tianheyu927/gps.git","svn_url":"https://github.com/tianheyu927/gps","homepage":"http://rll.berkeley.edu/gps/","size":1108,"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":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"tianheyu927:master","ref":"master","sha":"38e089e6579b173f8f1d716d6d2b418c536181bf","user":{"login":"tianheyu927","id":14038135,"avatar_url":"https://avatars.githubusercontent.com/u/14038135?v=3","gravatar_id":"","url":"https://api.github.com/users/tianheyu927","html_url":"https://github.com/tianheyu927","followers_url":"https://api.github.com/users/tianheyu927/followers","following_url":"https://api.github.com/users/tianheyu927/following{/other_user}","gists_url":"https://api.github.com/users/tianheyu927/gists{/gist_id}","starred_url":"https://api.github.com/users/tianheyu927/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tianheyu927/subscriptions","organizations_url":"https://api.github.com/users/tianheyu927/orgs","repos_url":"https://api.github.com/users/tianheyu927/repos","events_url":"https://api.github.com/users/tianheyu927/events{/privacy}","received_events_url":"https://api.github.com/users/tianheyu927/received_events","type":"User","site_admin":false},"repo":{"id":61260810,"name":"gps","full_name":"tianheyu927/gps","owner":{"login":"tianheyu927","id":14038135,"avatar_url":"https://avatars.githubusercontent.com/u/14038135?v=3","gravatar_id":"","url":"https://api.github.com/users/tianheyu927","html_url":"https://github.com/tianheyu927","followers_url":"https://api.github.com/users/tianheyu927/followers","following_url":"https://api.github.com/users/tianheyu927/following{/other_user}","gists_url":"https://api.github.com/users/tianheyu927/gists{/gist_id}","starred_url":"https://api.github.com/users/tianheyu927/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tianheyu927/subscriptions","organizations_url":"https://api.github.com/users/tianheyu927/orgs","repos_url":"https://api.github.com/users/tianheyu927/repos","events_url":"https://api.github.com/users/tianheyu927/events{/privacy}","received_events_url":"https://api.github.com/users/tianheyu927/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tianheyu927/gps","description":"Guided Policy Search","fork":true,"url":"https://api.github.com/repos/tianheyu927/gps","forks_url":"https://api.github.com/repos/tianheyu927/gps/forks","keys_url":"https://api.github.com/repos/tianheyu927/gps/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tianheyu927/gps/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tianheyu927/gps/teams","hooks_url":"https://api.github.com/repos/tianheyu927/gps/hooks","issue_events_url":"https://api.github.com/repos/tianheyu927/gps/issues/events{/number}","events_url":"https://api.github.com/repos/tianheyu927/gps/events","assignees_url":"https://api.github.com/repos/tianheyu927/gps/assignees{/user}","branches_url":"https://api.github.com/repos/tianheyu927/gps/branches{/branch}","tags_url":"https://api.github.com/repos/tianheyu927/gps/tags","blobs_url":"https://api.github.com/repos/tianheyu927/gps/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tianheyu927/gps/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tianheyu927/gps/git/refs{/sha}","trees_url":"https://api.github.com/repos/tianheyu927/gps/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tianheyu927/gps/statuses/{sha}","languages_url":"https://api.github.com/repos/tianheyu927/gps/languages","stargazers_url":"https://api.github.com/repos/tianheyu927/gps/stargazers","contributors_url":"https://api.github.com/repos/tianheyu927/gps/contributors","subscribers_url":"https://api.github.com/repos/tianheyu927/gps/subscribers","subscription_url":"https://api.github.com/repos/tianheyu927/gps/subscription","commits_url":"https://api.github.com/repos/tianheyu927/gps/commits{/sha}","git_commits_url":"https://api.github.com/repos/tianheyu927/gps/git/commits{/sha}","comments_url":"https://api.github.com/repos/tianheyu927/gps/comments{/number}","issue_comment_url":"https://api.github.com/repos/tianheyu927/gps/issues/comments{/number}","contents_url":"https://api.github.com/repos/tianheyu927/gps/contents/{+path}","compare_url":"https://api.github.com/repos/tianheyu927/gps/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tianheyu927/gps/merges","archive_url":"https://api.github.com/repos/tianheyu927/gps/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tianheyu927/gps/downloads","issues_url":"https://api.github.com/repos/tianheyu927/gps/issues{/number}","pulls_url":"https://api.github.com/repos/tianheyu927/gps/pulls{/number}","milestones_url":"https://api.github.com/repos/tianheyu927/gps/milestones{/number}","notifications_url":"https://api.github.com/repos/tianheyu927/gps/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tianheyu927/gps/labels{/name}","releases_url":"https://api.github.com/repos/tianheyu927/gps/releases{/id}","deployments_url":"https://api.github.com/repos/tianheyu927/gps/deployments","created_at":"2016-06-16T03:57:53Z","updated_at":"2016-06-16T03:57:55Z","pushed_at":"2016-06-26T23:26:16Z","git_url":"git://github.com/tianheyu927/gps.git","ssh_url":"git@github.com:tianheyu927/gps.git","clone_url":"https://github.com/tianheyu927/gps.git","svn_url":"https://github.com/tianheyu927/gps","homepage":"http://rll.berkeley.edu/gps/","size":1108,"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":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/tianheyu927/gps/pulls/1"},"html":{"href":"https://github.com/tianheyu927/gps/pull/1"},"issue":{"href":"https://api.github.com/repos/tianheyu927/gps/issues/1"},"comments":{"href":"https://api.github.com/repos/tianheyu927/gps/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/tianheyu927/gps/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/tianheyu927/gps/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/tianheyu927/gps/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/tianheyu927/gps/statuses/d2029c3f9f907be49870cdb8980d4471d9d9d2d0"}}}}
{"actor":{"display_login":"cbfinn"}}