{"action":"created","comment":{"url":"https://api.github.com/repos/pymc-devs/pymc4/pulls/comments/191545287","pull_request_review_id":124138180,"id":191545287,"diff_hunk":"@@ -0,0 +1,129 @@\n+from __future__ import absolute_import\n+from __future__ import division\n+from __future__ import print_function\n+\n+import tensorflow as tf\n+import seaborn as sns\n+import threading\n+import matplotlib.pyplot as plt\n+\n+############################\n+class Context(object):\n+    \"\"\"Functionality for objects that put themselves in a context using\n+    the `with` statement.\n+    \"\"\"\n+    contexts = threading.local()\n+\n+    def __enter__(self):\n+        type(self).get_contexts().append(self)\n+        return self\n+\n+    def __exit__(self, typ, value, traceback):\n+        type(self).get_contexts().pop()\n+\n+def withparent(meth):\n+    \"\"\"Helper wrapper that passes calls to parent's instance\"\"\"\n+    def wrapped(self, *args, **kwargs):\n+        res = meth(self, *args, **kwargs)\n+        if getattr(self, 'parent', None) is not None:\n+            getattr(self.parent, meth.__name__)(*args, **kwargs)\n+        return res\n+    # Unfortunately functools wrapper fails\n+    # when decorating built-in methods so we\n+    # need to fix that improper behaviour\n+    wrapped.__name__ = meth.__name__\n+    return wrapped\n+\n+class treedict(dict):\n+    \"\"\"A dict that passes mutable extending operations used in Model\n+    to parent dict instance.\n+    Extending treedict you will also extend its parent\n+    \"\"\"\n+    def __init__(self, iterable=(), parent=None, **kwargs):\n+        super(treedict, self).__init__(iterable, **kwargs)\n+        assert isinstance(parent, dict) or parent is None\n+        self.parent = parent\n+        if self.parent is not None:\n+            self.parent.update(self)\n+    # typechecking here works bad\n+    __setitem__ = withparent(dict.__setitem__)\n+    update = withparent(dict.update)\n+\n+    def tree_contains(self, item):\n+        # needed for `add_random_variable` method\n+        if isinstance(self.parent, treedict):\n+            return (dict.__contains__(self, item) or\n+                    self.parent.tree_contains(item))\n+        elif isinstance(self.parent, dict):\n+            return (dict.__contains__(self, item) or\n+                    self.parent.__contains__(item))\n+        else:\n+            return dict.__contains__(self, item)\n+################################\n+\n+class Model(Context):","path":"pymc4/model.py","position":64,"original_position":64,"commit_id":"592c5384de053d54a97427c7478c72426e634b41","original_commit_id":"592c5384de053d54a97427c7478c72426e634b41","user":{"login":"ferrine","id":11705326,"avatar_url":"https://avatars0.githubusercontent.com/u/11705326?v=4","gravatar_id":"","url":"https://api.github.com/users/ferrine","html_url":"https://github.com/ferrine","followers_url":"https://api.github.com/users/ferrine/followers","following_url":"https://api.github.com/users/ferrine/following{/other_user}","gists_url":"https://api.github.com/users/ferrine/gists{/gist_id}","starred_url":"https://api.github.com/users/ferrine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ferrine/subscriptions","organizations_url":"https://api.github.com/users/ferrine/orgs","repos_url":"https://api.github.com/users/ferrine/repos","events_url":"https://api.github.com/users/ferrine/events{/privacy}","received_events_url":"https://api.github.com/users/ferrine/received_events","type":"User","site_admin":false},"body":"https://github.com/pymc-devs/pymc3/blob/master/pymc3/model.py#L278\r\nThis code allowed model nesting, you might add this later, without it, treedicts etc are useless","created_at":"2018-05-29T19:28:35Z","updated_at":"2018-05-29T19:28:35Z","html_url":"https://github.com/pymc-devs/pymc4/pull/1#discussion_r191545287","pull_request_url":"https://api.github.com/repos/pymc-devs/pymc4/pulls/1","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/pymc-devs/pymc4/pulls/comments/191545287"},"html":{"href":"https://github.com/pymc-devs/pymc4/pull/1#discussion_r191545287"},"pull_request":{"href":"https://api.github.com/repos/pymc-devs/pymc4/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/pymc-devs/pymc4/pulls/1","id":191230079,"html_url":"https://github.com/pymc-devs/pymc4/pull/1","diff_url":"https://github.com/pymc-devs/pymc4/pull/1.diff","patch_url":"https://github.com/pymc-devs/pymc4/pull/1.patch","issue_url":"https://api.github.com/repos/pymc-devs/pymc4/issues/1","number":1,"state":"open","locked":false,"title":"[WIP] Model context manager, premitive default sampling, random variable class","user":{"login":"sharanry","id":19674071,"avatar_url":"https://avatars2.githubusercontent.com/u/19674071?v=4","gravatar_id":"","url":"https://api.github.com/users/sharanry","html_url":"https://github.com/sharanry","followers_url":"https://api.github.com/users/sharanry/followers","following_url":"https://api.github.com/users/sharanry/following{/other_user}","gists_url":"https://api.github.com/users/sharanry/gists{/gist_id}","starred_url":"https://api.github.com/users/sharanry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sharanry/subscriptions","organizations_url":"https://api.github.com/users/sharanry/orgs","repos_url":"https://api.github.com/users/sharanry/repos","events_url":"https://api.github.com/users/sharanry/events{/privacy}","received_events_url":"https://api.github.com/users/sharanry/received_events","type":"User","site_admin":false},"body":"Test Notebook : https://github.com/sharanry/pymc4/blob/592c5384de053d54a97427c7478c72426e634b41/test.ipynb\r\n\r\n\r\n- Currently the Model class uses `treedict` to keep track of the variables defined under it. Exploring whether `treedict` is actually required or python dictionaries can replace this.\r\n- Will explore the use of contextlib \r\n- Exploring the use of existing pymc3 samplers.\r\n\r\nPS Please forgive my dirty code. Will be cleaning up soon and make it more readable.","created_at":"2018-05-29T18:19:22Z","updated_at":"2018-05-29T19:28:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8269f9ca9067cdb0e50dab4997a948f08f742a97","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/pymc-devs/pymc4/pulls/1/commits","review_comments_url":"https://api.github.com/repos/pymc-devs/pymc4/pulls/1/comments","review_comment_url":"https://api.github.com/repos/pymc-devs/pymc4/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pymc-devs/pymc4/issues/1/comments","statuses_url":"https://api.github.com/repos/pymc-devs/pymc4/statuses/592c5384de053d54a97427c7478c72426e634b41","head":{"label":"sharanry:initial","ref":"initial","sha":"592c5384de053d54a97427c7478c72426e634b41","user":{"login":"sharanry","id":19674071,"avatar_url":"https://avatars2.githubusercontent.com/u/19674071?v=4","gravatar_id":"","url":"https://api.github.com/users/sharanry","html_url":"https://github.com/sharanry","followers_url":"https://api.github.com/users/sharanry/followers","following_url":"https://api.github.com/users/sharanry/following{/other_user}","gists_url":"https://api.github.com/users/sharanry/gists{/gist_id}","starred_url":"https://api.github.com/users/sharanry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sharanry/subscriptions","organizations_url":"https://api.github.com/users/sharanry/orgs","repos_url":"https://api.github.com/users/sharanry/repos","events_url":"https://api.github.com/users/sharanry/events{/privacy}","received_events_url":"https://api.github.com/users/sharanry/received_events","type":"User","site_admin":false},"repo":{"id":135334656,"name":"pymc4","full_name":"sharanry/pymc4","owner":{"login":"sharanry","id":19674071,"avatar_url":"https://avatars2.githubusercontent.com/u/19674071?v=4","gravatar_id":"","url":"https://api.github.com/users/sharanry","html_url":"https://github.com/sharanry","followers_url":"https://api.github.com/users/sharanry/followers","following_url":"https://api.github.com/users/sharanry/following{/other_user}","gists_url":"https://api.github.com/users/sharanry/gists{/gist_id}","starred_url":"https://api.github.com/users/sharanry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sharanry/subscriptions","organizations_url":"https://api.github.com/users/sharanry/orgs","repos_url":"https://api.github.com/users/sharanry/repos","events_url":"https://api.github.com/users/sharanry/events{/privacy}","received_events_url":"https://api.github.com/users/sharanry/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sharanry/pymc4","description":"Pre-release development of high-level probabilistic programming interface for TensorFlow","fork":true,"url":"https://api.github.com/repos/sharanry/pymc4","forks_url":"https://api.github.com/repos/sharanry/pymc4/forks","keys_url":"https://api.github.com/repos/sharanry/pymc4/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sharanry/pymc4/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sharanry/pymc4/teams","hooks_url":"https://api.github.com/repos/sharanry/pymc4/hooks","issue_events_url":"https://api.github.com/repos/sharanry/pymc4/issues/events{/number}","events_url":"https://api.github.com/repos/sharanry/pymc4/events","assignees_url":"https://api.github.com/repos/sharanry/pymc4/assignees{/user}","branches_url":"https://api.github.com/repos/sharanry/pymc4/branches{/branch}","tags_url":"https://api.github.com/repos/sharanry/pymc4/tags","blobs_url":"https://api.github.com/repos/sharanry/pymc4/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sharanry/pymc4/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sharanry/pymc4/git/refs{/sha}","trees_url":"https://api.github.com/repos/sharanry/pymc4/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sharanry/pymc4/statuses/{sha}","languages_url":"https://api.github.com/repos/sharanry/pymc4/languages","stargazers_url":"https://api.github.com/repos/sharanry/pymc4/stargazers","contributors_url":"https://api.github.com/repos/sharanry/pymc4/contributors","subscribers_url":"https://api.github.com/repos/sharanry/pymc4/subscribers","subscription_url":"https://api.github.com/repos/sharanry/pymc4/subscription","commits_url":"https://api.github.com/repos/sharanry/pymc4/commits{/sha}","git_commits_url":"https://api.github.com/repos/sharanry/pymc4/git/commits{/sha}","comments_url":"https://api.github.com/repos/sharanry/pymc4/comments{/number}","issue_comment_url":"https://api.github.com/repos/sharanry/pymc4/issues/comments{/number}","contents_url":"https://api.github.com/repos/sharanry/pymc4/contents/{+path}","compare_url":"https://api.github.com/repos/sharanry/pymc4/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sharanry/pymc4/merges","archive_url":"https://api.github.com/repos/sharanry/pymc4/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sharanry/pymc4/downloads","issues_url":"https://api.github.com/repos/sharanry/pymc4/issues{/number}","pulls_url":"https://api.github.com/repos/sharanry/pymc4/pulls{/number}","milestones_url":"https://api.github.com/repos/sharanry/pymc4/milestones{/number}","notifications_url":"https://api.github.com/repos/sharanry/pymc4/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sharanry/pymc4/labels{/name}","releases_url":"https://api.github.com/repos/sharanry/pymc4/releases{/id}","deployments_url":"https://api.github.com/repos/sharanry/pymc4/deployments","created_at":"2018-05-29T18:05:37Z","updated_at":"2018-05-29T18:05:39Z","pushed_at":"2018-05-29T18:24:12Z","git_url":"git://github.com/sharanry/pymc4.git","ssh_url":"git@github.com:sharanry/pymc4.git","clone_url":"https://github.com/sharanry/pymc4.git","svn_url":"https://github.com/sharanry/pymc4","homepage":null,"size":149,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"pymc-devs:master","ref":"master","sha":"b2b69b32c7d2c28d32826ff735a357ee74fc3183","user":{"login":"pymc-devs","id":81121,"avatar_url":"https://avatars3.githubusercontent.com/u/81121?v=4","gravatar_id":"","url":"https://api.github.com/users/pymc-devs","html_url":"https://github.com/pymc-devs","followers_url":"https://api.github.com/users/pymc-devs/followers","following_url":"https://api.github.com/users/pymc-devs/following{/other_user}","gists_url":"https://api.github.com/users/pymc-devs/gists{/gist_id}","starred_url":"https://api.github.com/users/pymc-devs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pymc-devs/subscriptions","organizations_url":"https://api.github.com/users/pymc-devs/orgs","repos_url":"https://api.github.com/users/pymc-devs/repos","events_url":"https://api.github.com/users/pymc-devs/events{/privacy}","received_events_url":"https://api.github.com/users/pymc-devs/received_events","type":"Organization","site_admin":false},"repo":{"id":132156591,"name":"pymc4","full_name":"pymc-devs/pymc4","owner":{"login":"pymc-devs","id":81121,"avatar_url":"https://avatars3.githubusercontent.com/u/81121?v=4","gravatar_id":"","url":"https://api.github.com/users/pymc-devs","html_url":"https://github.com/pymc-devs","followers_url":"https://api.github.com/users/pymc-devs/followers","following_url":"https://api.github.com/users/pymc-devs/following{/other_user}","gists_url":"https://api.github.com/users/pymc-devs/gists{/gist_id}","starred_url":"https://api.github.com/users/pymc-devs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pymc-devs/subscriptions","organizations_url":"https://api.github.com/users/pymc-devs/orgs","repos_url":"https://api.github.com/users/pymc-devs/repos","events_url":"https://api.github.com/users/pymc-devs/events{/privacy}","received_events_url":"https://api.github.com/users/pymc-devs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pymc-devs/pymc4","description":"Pre-release development of high-level probabilistic programming interface for TensorFlow","fork":false,"url":"https://api.github.com/repos/pymc-devs/pymc4","forks_url":"https://api.github.com/repos/pymc-devs/pymc4/forks","keys_url":"https://api.github.com/repos/pymc-devs/pymc4/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pymc-devs/pymc4/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pymc-devs/pymc4/teams","hooks_url":"https://api.github.com/repos/pymc-devs/pymc4/hooks","issue_events_url":"https://api.github.com/repos/pymc-devs/pymc4/issues/events{/number}","events_url":"https://api.github.com/repos/pymc-devs/pymc4/events","assignees_url":"https://api.github.com/repos/pymc-devs/pymc4/assignees{/user}","branches_url":"https://api.github.com/repos/pymc-devs/pymc4/branches{/branch}","tags_url":"https://api.github.com/repos/pymc-devs/pymc4/tags","blobs_url":"https://api.github.com/repos/pymc-devs/pymc4/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pymc-devs/pymc4/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pymc-devs/pymc4/git/refs{/sha}","trees_url":"https://api.github.com/repos/pymc-devs/pymc4/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pymc-devs/pymc4/statuses/{sha}","languages_url":"https://api.github.com/repos/pymc-devs/pymc4/languages","stargazers_url":"https://api.github.com/repos/pymc-devs/pymc4/stargazers","contributors_url":"https://api.github.com/repos/pymc-devs/pymc4/contributors","subscribers_url":"https://api.github.com/repos/pymc-devs/pymc4/subscribers","subscription_url":"https://api.github.com/repos/pymc-devs/pymc4/subscription","commits_url":"https://api.github.com/repos/pymc-devs/pymc4/commits{/sha}","git_commits_url":"https://api.github.com/repos/pymc-devs/pymc4/git/commits{/sha}","comments_url":"https://api.github.com/repos/pymc-devs/pymc4/comments{/number}","issue_comment_url":"https://api.github.com/repos/pymc-devs/pymc4/issues/comments{/number}","contents_url":"https://api.github.com/repos/pymc-devs/pymc4/contents/{+path}","compare_url":"https://api.github.com/repos/pymc-devs/pymc4/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pymc-devs/pymc4/merges","archive_url":"https://api.github.com/repos/pymc-devs/pymc4/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pymc-devs/pymc4/downloads","issues_url":"https://api.github.com/repos/pymc-devs/pymc4/issues{/number}","pulls_url":"https://api.github.com/repos/pymc-devs/pymc4/pulls{/number}","milestones_url":"https://api.github.com/repos/pymc-devs/pymc4/milestones{/number}","notifications_url":"https://api.github.com/repos/pymc-devs/pymc4/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pymc-devs/pymc4/labels{/name}","releases_url":"https://api.github.com/repos/pymc-devs/pymc4/releases{/id}","deployments_url":"https://api.github.com/repos/pymc-devs/pymc4/deployments","created_at":"2018-05-04T15:18:59Z","updated_at":"2018-05-27T15:28:13Z","pushed_at":"2018-05-29T18:24:14Z","git_url":"git://github.com/pymc-devs/pymc4.git","ssh_url":"git@github.com:pymc-devs/pymc4.git","clone_url":"https://github.com/pymc-devs/pymc4.git","svn_url":"https://github.com/pymc-devs/pymc4","homepage":null,"size":5,"stargazers_count":14,"watchers_count":14,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":1,"open_issues":1,"watchers":14,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pymc-devs/pymc4/pulls/1"},"html":{"href":"https://github.com/pymc-devs/pymc4/pull/1"},"issue":{"href":"https://api.github.com/repos/pymc-devs/pymc4/issues/1"},"comments":{"href":"https://api.github.com/repos/pymc-devs/pymc4/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/pymc-devs/pymc4/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/pymc-devs/pymc4/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pymc-devs/pymc4/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/pymc-devs/pymc4/statuses/592c5384de053d54a97427c7478c72426e634b41"}},"author_association":"NONE"}}
{"actor":{"display_login":"ferrine"}}