{"action":"created","comment":{"url":"https://api.github.com/repos/pymc-devs/pymc3/pulls/comments/109285036","pull_request_review_id":30382301,"id":109285036,"diff_hunk":"@@ -0,0 +1,219 @@\n+from collections import namedtuple\n+\n+from ..arraystep import Competence\n+from .base_hmc import BaseHMC\n+from pymc3.theanof import join_nonshared_inputs, floatX, gradient\n+import theano.tensor as tt\n+import numpy as np\n+\n+__all__ = ['SGFS']\n+\n+class BaseStochasticGradient(ArrayStepShared):\n+    \"\"\"\n+    BaseStochasticGradient Object\n+    \n+    For working with BaseStochasticGradient Object\n+    we need to supply the probabilistic model \n+    (:code:`model`)\n+\n+    :code:`minibatch_tensors` is a list of tensors (can be shared variables)\n+    to which mini-batch samples are set during the optimization.\n+    These tensors are observations (:code:`obs=`) in :code:`observed_RVs`.\n+    \n+    :code:`minibatches` is a generator of a list of :code:`numpy.ndarray`.\n+    Each item of the list will be set to tensors in :code:`minibatch_tensors`.\n+\n+    Parameters\n+    -------\n+    vars : list\n+        List of variables for sampler\n+    total_size : int\n+        Total size of the training data\n+    batch_size`: int\n+        Batch Size for each step\n+    n_iter : int\n+        The number of iterations to run\n+    burn_in : int\n+        Burn in period\n+    minibatches : dict\n+        A dictionary keyed with an Observed Variable and a generator \n+        of numpy.ndarray as the observed data for the var\n+    model : PyMC Model\n+        Optional model for sampling step. Defaults to None (taken from context)\n+    mode :  string or `Mode` instance.\n+        compilation mode passed to Theano functions\n+    \"\"\"\n+    default_blocked = False\n+\n+    def __init__(self, vars=None, batch_size=None, n_iter=None, total_size=None, \n+            burn_in=None, model=None, mode=None, **kwargs):\n+        \n+        model = pm.modelcontext(model)\n+\n+        if vars is None:\n+            vars = model.vars\n+        vars = pm.inputvars(vars)\n+\n+        shared = pm.make_shared_replacements(vars, model)\n+        super(BaseStochasticGradient, self).__init__(vars, shared)\n+        \n+        self.batch_size = batch_size or 128\n+        self.n_iter = n_iter or 100\n+        self.total_size = total_size\n+        self.burn_in = burn_in or 100\n+        if total_size is None:\n+            raise ValueError('total_size must be specified')\n+        \n+        # Check generator/tensors are available for each observed RVs\n+        if all(v in minibatches for v in model.observed_RVs):\n+            raise ValueError('All observed variables must have an assigned generator')\n+     \n+        self.batch_size = batch_size or 128\n+        self.n_iter = n_iter or 100\n+        self.total_size = total_size\n+        if total_size is None:\n+            raise ValueError('total_size must be specified')\n+        self.burn_in = burn_in or 100\n+  \n+        \n+        self.step_size = step_size or 0.25\n+        self.total_size = total_size\n+        if not self.total_size:\n+            raise ValueError('Total Size of training data has to be specified')\n+\n+        self.t = theano.scalar('t')\n+        \n+        # Check all free RVs are continous\n+        self.independent_variables = model.free_RVs\n+        self.dependent_variables = model.observed_RVs\n+        # Because: dsize = int(np.prod(v.shape))\n+        self.q_size = sum(v.dsize for v in self.independent_variables) \n+         \n+    def next_minibatch(self):\n+        idx = #None\n+        batch_x = self.data.X[idx, :]\n+        batch_y = self.data.Y[idx, :]    \n+        return batch_x, batch_y\n+ \n+    def dlogp_elemwise(self):\n+        terms = [tt.gradient(v.logp_elemwiset, self.independent_variables) for v in self.dependent_variables]\n+        return self.model.fn(tt.add(*terms))\n+\n+    def logp_elemwise(self):\n+        terms = [v.logp_elemwiset for v in model.observed_RVs]\n+        return self.model.fn(tt.add(*terms))\n+ \n+\n+    def dlogp_elemwise(self):","path":"pymc3/step_methods/hmc/stochastic_fisher_scoring.py","position":107,"original_position":107,"commit_id":"a337e0b58976ee12684901580c22649526d2bbb7","original_commit_id":"a337e0b58976ee12684901580c22649526d2bbb7","user":{"login":"ColCarroll","id":2295568,"avatar_url":"https://avatars0.githubusercontent.com/u/2295568?v=3","gravatar_id":"","url":"https://api.github.com/users/ColCarroll","html_url":"https://github.com/ColCarroll","followers_url":"https://api.github.com/users/ColCarroll/followers","following_url":"https://api.github.com/users/ColCarroll/following{/other_user}","gists_url":"https://api.github.com/users/ColCarroll/gists{/gist_id}","starred_url":"https://api.github.com/users/ColCarroll/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ColCarroll/subscriptions","organizations_url":"https://api.github.com/users/ColCarroll/orgs","repos_url":"https://api.github.com/users/ColCarroll/repos","events_url":"https://api.github.com/users/ColCarroll/events{/privacy}","received_events_url":"https://api.github.com/users/ColCarroll/received_events","type":"User","site_admin":false},"body":"this is defined twice","created_at":"2017-04-01T13:31:16Z","updated_at":"2017-04-01T13:38:59Z","html_url":"https://github.com/pymc-devs/pymc3/pull/1977#discussion_r109285036","pull_request_url":"https://api.github.com/repos/pymc-devs/pymc3/pulls/1977","_links":{"self":{"href":"https://api.github.com/repos/pymc-devs/pymc3/pulls/comments/109285036"},"html":{"href":"https://github.com/pymc-devs/pymc3/pull/1977#discussion_r109285036"},"pull_request":{"href":"https://api.github.com/repos/pymc-devs/pymc3/pulls/1977"}}},"pull_request":{"url":"https://api.github.com/repos/pymc-devs/pymc3/pulls/1977","id":113550072,"html_url":"https://github.com/pymc-devs/pymc3/pull/1977","diff_url":"https://github.com/pymc-devs/pymc3/pull/1977.diff","patch_url":"https://github.com/pymc-devs/pymc3/pull/1977.patch","issue_url":"https://api.github.com/repos/pymc-devs/pymc3/issues/1977","number":1977,"state":"open","locked":false,"title":"[WIP] Stochastic Gradient Fisher Scoring ","user":{"login":"shkr","id":5184832,"avatar_url":"https://avatars3.githubusercontent.com/u/5184832?v=3","gravatar_id":"","url":"https://api.github.com/users/shkr","html_url":"https://github.com/shkr","followers_url":"https://api.github.com/users/shkr/followers","following_url":"https://api.github.com/users/shkr/following{/other_user}","gists_url":"https://api.github.com/users/shkr/gists{/gist_id}","starred_url":"https://api.github.com/users/shkr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shkr/subscriptions","organizations_url":"https://api.github.com/users/shkr/orgs","repos_url":"https://api.github.com/users/shkr/repos","events_url":"https://api.github.com/users/shkr/events{/privacy}","received_events_url":"https://api.github.com/users/shkr/received_events","type":"User","site_admin":false},"body":"Issue #1958 ","created_at":"2017-03-31T00:05:11Z","updated_at":"2017-04-01T13:38:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c5c23c83f7ebcc7ef9f75701d4a786d1d4bc6c54","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/pymc-devs/pymc3/pulls/1977/commits","review_comments_url":"https://api.github.com/repos/pymc-devs/pymc3/pulls/1977/comments","review_comment_url":"https://api.github.com/repos/pymc-devs/pymc3/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pymc-devs/pymc3/issues/1977/comments","statuses_url":"https://api.github.com/repos/pymc-devs/pymc3/statuses/a337e0b58976ee12684901580c22649526d2bbb7","head":{"label":"shkr:stgbs","ref":"stgbs","sha":"a337e0b58976ee12684901580c22649526d2bbb7","user":{"login":"shkr","id":5184832,"avatar_url":"https://avatars3.githubusercontent.com/u/5184832?v=3","gravatar_id":"","url":"https://api.github.com/users/shkr","html_url":"https://github.com/shkr","followers_url":"https://api.github.com/users/shkr/followers","following_url":"https://api.github.com/users/shkr/following{/other_user}","gists_url":"https://api.github.com/users/shkr/gists{/gist_id}","starred_url":"https://api.github.com/users/shkr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shkr/subscriptions","organizations_url":"https://api.github.com/users/shkr/orgs","repos_url":"https://api.github.com/users/shkr/repos","events_url":"https://api.github.com/users/shkr/events{/privacy}","received_events_url":"https://api.github.com/users/shkr/received_events","type":"User","site_admin":false},"repo":{"id":86278195,"name":"pymc3","full_name":"shkr/pymc3","owner":{"login":"shkr","id":5184832,"avatar_url":"https://avatars3.githubusercontent.com/u/5184832?v=3","gravatar_id":"","url":"https://api.github.com/users/shkr","html_url":"https://github.com/shkr","followers_url":"https://api.github.com/users/shkr/followers","following_url":"https://api.github.com/users/shkr/following{/other_user}","gists_url":"https://api.github.com/users/shkr/gists{/gist_id}","starred_url":"https://api.github.com/users/shkr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shkr/subscriptions","organizations_url":"https://api.github.com/users/shkr/orgs","repos_url":"https://api.github.com/users/shkr/repos","events_url":"https://api.github.com/users/shkr/events{/privacy}","received_events_url":"https://api.github.com/users/shkr/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/shkr/pymc3","description":"Probabilistic Programming in Python: Bayesian Modeling and Probabilistic Machine Learning with Theano","fork":true,"url":"https://api.github.com/repos/shkr/pymc3","forks_url":"https://api.github.com/repos/shkr/pymc3/forks","keys_url":"https://api.github.com/repos/shkr/pymc3/keys{/key_id}","collaborators_url":"https://api.github.com/repos/shkr/pymc3/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/shkr/pymc3/teams","hooks_url":"https://api.github.com/repos/shkr/pymc3/hooks","issue_events_url":"https://api.github.com/repos/shkr/pymc3/issues/events{/number}","events_url":"https://api.github.com/repos/shkr/pymc3/events","assignees_url":"https://api.github.com/repos/shkr/pymc3/assignees{/user}","branches_url":"https://api.github.com/repos/shkr/pymc3/branches{/branch}","tags_url":"https://api.github.com/repos/shkr/pymc3/tags","blobs_url":"https://api.github.com/repos/shkr/pymc3/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/shkr/pymc3/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/shkr/pymc3/git/refs{/sha}","trees_url":"https://api.github.com/repos/shkr/pymc3/git/trees{/sha}","statuses_url":"https://api.github.com/repos/shkr/pymc3/statuses/{sha}","languages_url":"https://api.github.com/repos/shkr/pymc3/languages","stargazers_url":"https://api.github.com/repos/shkr/pymc3/stargazers","contributors_url":"https://api.github.com/repos/shkr/pymc3/contributors","subscribers_url":"https://api.github.com/repos/shkr/pymc3/subscribers","subscription_url":"https://api.github.com/repos/shkr/pymc3/subscription","commits_url":"https://api.github.com/repos/shkr/pymc3/commits{/sha}","git_commits_url":"https://api.github.com/repos/shkr/pymc3/git/commits{/sha}","comments_url":"https://api.github.com/repos/shkr/pymc3/comments{/number}","issue_comment_url":"https://api.github.com/repos/shkr/pymc3/issues/comments{/number}","contents_url":"https://api.github.com/repos/shkr/pymc3/contents/{+path}","compare_url":"https://api.github.com/repos/shkr/pymc3/compare/{base}...{head}","merges_url":"https://api.github.com/repos/shkr/pymc3/merges","archive_url":"https://api.github.com/repos/shkr/pymc3/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/shkr/pymc3/downloads","issues_url":"https://api.github.com/repos/shkr/pymc3/issues{/number}","pulls_url":"https://api.github.com/repos/shkr/pymc3/pulls{/number}","milestones_url":"https://api.github.com/repos/shkr/pymc3/milestones{/number}","notifications_url":"https://api.github.com/repos/shkr/pymc3/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/shkr/pymc3/labels{/name}","releases_url":"https://api.github.com/repos/shkr/pymc3/releases{/id}","deployments_url":"https://api.github.com/repos/shkr/pymc3/deployments","created_at":"2017-03-27T01:30:28Z","updated_at":"2017-03-27T01:30:31Z","pushed_at":"2017-04-01T07:16:12Z","git_url":"git://github.com/shkr/pymc3.git","ssh_url":"git@github.com:shkr/pymc3.git","clone_url":"https://github.com/shkr/pymc3.git","svn_url":"https://github.com/shkr/pymc3","homepage":"http://pymc-devs.github.io/pymc3/","size":205321,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"pymc-devs:master","ref":"master","sha":"9ee9f2cb1e0b733be7d9cc80fced9b910a343abe","user":{"login":"pymc-devs","id":81121,"avatar_url":"https://avatars0.githubusercontent.com/u/81121?v=3","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":192904,"name":"pymc3","full_name":"pymc-devs/pymc3","owner":{"login":"pymc-devs","id":81121,"avatar_url":"https://avatars0.githubusercontent.com/u/81121?v=3","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/pymc3","description":"Probabilistic Programming in Python: Bayesian Modeling and Probabilistic Machine Learning with Theano","fork":false,"url":"https://api.github.com/repos/pymc-devs/pymc3","forks_url":"https://api.github.com/repos/pymc-devs/pymc3/forks","keys_url":"https://api.github.com/repos/pymc-devs/pymc3/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pymc-devs/pymc3/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pymc-devs/pymc3/teams","hooks_url":"https://api.github.com/repos/pymc-devs/pymc3/hooks","issue_events_url":"https://api.github.com/repos/pymc-devs/pymc3/issues/events{/number}","events_url":"https://api.github.com/repos/pymc-devs/pymc3/events","assignees_url":"https://api.github.com/repos/pymc-devs/pymc3/assignees{/user}","branches_url":"https://api.github.com/repos/pymc-devs/pymc3/branches{/branch}","tags_url":"https://api.github.com/repos/pymc-devs/pymc3/tags","blobs_url":"https://api.github.com/repos/pymc-devs/pymc3/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pymc-devs/pymc3/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pymc-devs/pymc3/git/refs{/sha}","trees_url":"https://api.github.com/repos/pymc-devs/pymc3/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pymc-devs/pymc3/statuses/{sha}","languages_url":"https://api.github.com/repos/pymc-devs/pymc3/languages","stargazers_url":"https://api.github.com/repos/pymc-devs/pymc3/stargazers","contributors_url":"https://api.github.com/repos/pymc-devs/pymc3/contributors","subscribers_url":"https://api.github.com/repos/pymc-devs/pymc3/subscribers","subscription_url":"https://api.github.com/repos/pymc-devs/pymc3/subscription","commits_url":"https://api.github.com/repos/pymc-devs/pymc3/commits{/sha}","git_commits_url":"https://api.github.com/repos/pymc-devs/pymc3/git/commits{/sha}","comments_url":"https://api.github.com/repos/pymc-devs/pymc3/comments{/number}","issue_comment_url":"https://api.github.com/repos/pymc-devs/pymc3/issues/comments{/number}","contents_url":"https://api.github.com/repos/pymc-devs/pymc3/contents/{+path}","compare_url":"https://api.github.com/repos/pymc-devs/pymc3/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pymc-devs/pymc3/merges","archive_url":"https://api.github.com/repos/pymc-devs/pymc3/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pymc-devs/pymc3/downloads","issues_url":"https://api.github.com/repos/pymc-devs/pymc3/issues{/number}","pulls_url":"https://api.github.com/repos/pymc-devs/pymc3/pulls{/number}","milestones_url":"https://api.github.com/repos/pymc-devs/pymc3/milestones{/number}","notifications_url":"https://api.github.com/repos/pymc-devs/pymc3/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pymc-devs/pymc3/labels{/name}","releases_url":"https://api.github.com/repos/pymc-devs/pymc3/releases{/id}","deployments_url":"https://api.github.com/repos/pymc-devs/pymc3/deployments","created_at":"2009-05-05T09:43:50Z","updated_at":"2017-04-01T08:18:32Z","pushed_at":"2017-04-01T09:44:38Z","git_url":"git://github.com/pymc-devs/pymc3.git","ssh_url":"git@github.com:pymc-devs/pymc3.git","clone_url":"https://github.com/pymc-devs/pymc3.git","svn_url":"https://github.com/pymc-devs/pymc3","homepage":"http://pymc-devs.github.io/pymc3/","size":206901,"stargazers_count":2076,"watchers_count":2076,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":506,"mirror_url":null,"open_issues_count":189,"forks":506,"open_issues":189,"watchers":2076,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pymc-devs/pymc3/pulls/1977"},"html":{"href":"https://github.com/pymc-devs/pymc3/pull/1977"},"issue":{"href":"https://api.github.com/repos/pymc-devs/pymc3/issues/1977"},"comments":{"href":"https://api.github.com/repos/pymc-devs/pymc3/issues/1977/comments"},"review_comments":{"href":"https://api.github.com/repos/pymc-devs/pymc3/pulls/1977/comments"},"review_comment":{"href":"https://api.github.com/repos/pymc-devs/pymc3/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pymc-devs/pymc3/pulls/1977/commits"},"statuses":{"href":"https://api.github.com/repos/pymc-devs/pymc3/statuses/a337e0b58976ee12684901580c22649526d2bbb7"}}}}
{"actor":{"display_login":"ColCarroll"}}