{"action":"created","comment":{"url":"https://api.github.com/repos/bartvm/blocks/pulls/comments/24904382","id":24904382,"diff_hunk":"@@ -0,0 +1,181 @@\n+\"\"\"Defines models.\n+\n+A model is a thin layer of abstraction between the user-defined computation\n+graph, bricks, parameters and main loop extensions. This module provides\n+the basic :class:`AbstractModel` interface as well as its implementations\n+(currently only :class:`Model`).\n+\n+\"\"\"\n+import logging\n+from abc import ABCMeta, abstractmethod\n+from collections import OrderedDict\n+from itertools import chain\n+\n+from six import add_metaclass\n+\n+from blocks.graph import ComputationGraph\n+from blocks.select import Selector\n+from blocks.filter import VariableFilter, get_brick\n+from blocks.roles import PARAMETER\n+\n+logger = logging.getLogger()\n+\n+\n+@add_metaclass(ABCMeta)\n+class AbstractModel(object):\n+    \"\"\"A parameterized entity trained in the main loop.\n+\n+    A model is a parameterized entity the user trains a in a main loop.\n+    The following are traits of every model:\n+\n+    * It has parameters and supports a way to access them. In addition\n+    to returning handles to parameter objects it can return their values\n+    as numpy arrays and set their values to given numpy arrays.\n+\n+    * It has an optimality criterion.\n+\n+    * It can be serialized and deserialized by mean of pickling.\n+\n+    * It might have bricks as its components.\n+\n+    This class provides an interface for models. For experiments use\n+    a subclass, e.g. the :class:`Model`.\n+\n+    \"\"\"\n+    @abstractmethod\n+    def get_params(self):\n+        \"\"\"Return the model parameters.\n+\n+        Returns\n+        -------\n+        params : OrderedDict\n+            Dictionary of (name, parameter) pairs.\n+\n+        \"\"\"\n+        pass\n+\n+    def get_param_values(self):\n+        \"\"\"Return the values of model parameters.\n+\n+        The default implementation assumes that parameters are Theano\n+        shared variables.\n+\n+        Returns\n+        -------\n+        param_values : OrderedDict\n+            Dictionary of (parameter name, :class:`~numpy.ndarray`) pairs.\n+\n+        \"\"\"\n+        return OrderedDict((name, param.get_value())\n+                           for name, param in self.get_params().items())\n+\n+    def set_param_values(self, param_values):\n+        \"\"\"Set the values of model parameters.\n+\n+        The default implementation assumes that parameters are Theano\n+        shared variables.\n+\n+        Parameters\n+        ----------\n+        param_values : OrderedDict\n+            Dictionary of (parameter name, :class:`~numpy.ndarray`) pairs.\n+\n+        \"\"\"\n+        params = self.get_params()\n+\n+        unknown = set(param_values) - set(params)\n+        missing = set(params) - set(param_values)\n+        if len(unknown):\n+            logger.error(\"unknown parameter names:\\n\".format(unknown))","path":"blocks/model.py","position":89,"original_position":89,"commit_id":"cfa87dee23c5fec1eabba58f3d25ca14444a4923","original_commit_id":"cfa87dee23c5fec1eabba58f3d25ca14444a4923","user":{"login":"bartvm","id":2299595,"avatar_url":"https://avatars.githubusercontent.com/u/2299595?v=3","gravatar_id":"","url":"https://api.github.com/users/bartvm","html_url":"https://github.com/bartvm","followers_url":"https://api.github.com/users/bartvm/followers","following_url":"https://api.github.com/users/bartvm/following{/other_user}","gists_url":"https://api.github.com/users/bartvm/gists{/gist_id}","starred_url":"https://api.github.com/users/bartvm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bartvm/subscriptions","organizations_url":"https://api.github.com/users/bartvm/orgs","repos_url":"https://api.github.com/users/bartvm/repos","events_url":"https://api.github.com/users/bartvm/events{/privacy}","received_events_url":"https://api.github.com/users/bartvm/received_events","type":"User","site_admin":false},"body":"Okay then, at least add a `NullHandler` for the main module. That would make these errors pass silently instead of crash with a mysterious \"no handler found\" message if they occur outside of the main loop. Just put this in `blocks/__init__.py`:\r\n\r\n```python\r\nimport logging\r\nlogger = logging.getLogger(__name__)\r\nlogger.addHandler(logging.NullHandler())\r\n```","created_at":"2015-02-18T14:35:41Z","updated_at":"2015-02-18T14:35:41Z","html_url":"https://github.com/bartvm/blocks/pull/298#discussion_r24904382","pull_request_url":"https://api.github.com/repos/bartvm/blocks/pulls/298","_links":{"self":{"href":"https://api.github.com/repos/bartvm/blocks/pulls/comments/24904382"},"html":{"href":"https://github.com/bartvm/blocks/pull/298#discussion_r24904382"},"pull_request":{"href":"https://api.github.com/repos/bartvm/blocks/pulls/298"}}},"pull_request":{"url":"https://api.github.com/repos/bartvm/blocks/pulls/298","id":29447011,"html_url":"https://github.com/bartvm/blocks/pull/298","diff_url":"https://github.com/bartvm/blocks/pull/298.diff","patch_url":"https://github.com/bartvm/blocks/pull/298.patch","issue_url":"https://api.github.com/repos/bartvm/blocks/issues/298","number":298,"state":"open","locked":false,"title":"Model","user":{"login":"rizar","id":654434,"avatar_url":"https://avatars.githubusercontent.com/u/654434?v=3","gravatar_id":"","url":"https://api.github.com/users/rizar","html_url":"https://github.com/rizar","followers_url":"https://api.github.com/users/rizar/followers","following_url":"https://api.github.com/users/rizar/following{/other_user}","gists_url":"https://api.github.com/users/rizar/gists{/gist_id}","starred_url":"https://api.github.com/users/rizar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rizar/subscriptions","organizations_url":"https://api.github.com/users/rizar/orgs","repos_url":"https://api.github.com/users/rizar/repos","events_url":"https://api.github.com/users/rizar/events{/privacy}","received_events_url":"https://api.github.com/users/rizar/received_events","type":"User","site_admin":false},"body":"This pull request introduces a `Model` interface and its subclass `DifferentiableCostModel`. The purpose of these classes is to be passed as a `model` argument to the `MainLoop` constructor.\r\n\r\n## Why do we need it? \r\n\r\nThe shortest answer: because the assumption that there is always a differentiable cost is to heavy. I would not like to see it hard-coded everywhere. \r\n\r\nMore verbosely:\r\n\r\n* There is a need for an interface to model parameters. For instance the `Dump` extension needs them. If we let it extract them directly from the computation graph we a) can never interfere into this process b) we are bound to differentiable costs only.\r\n\r\n* It would be nice to give extension access to the optimization criterion. That would allow very nice defaults, e.g. the `DataStreamMonitoring` in the case of a simple Theano cost could automatically add it to the list of monitored variables. \r\n\r\nI will answer the concern that have been already raised via email in subsequent comments.\r\n\r\n","created_at":"2015-02-17T14:47:35Z","updated_at":"2015-02-18T14:35:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c475942252d5d3d9031382b4096efd0fa5b54e24","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bartvm/blocks/pulls/298/commits","review_comments_url":"https://api.github.com/repos/bartvm/blocks/pulls/298/comments","review_comment_url":"https://api.github.com/repos/bartvm/blocks/pulls/comments/{number}","comments_url":"https://api.github.com/repos/bartvm/blocks/issues/298/comments","statuses_url":"https://api.github.com/repos/bartvm/blocks/statuses/cfa87dee23c5fec1eabba58f3d25ca14444a4923","head":{"label":"bartvm:model","ref":"model","sha":"cfa87dee23c5fec1eabba58f3d25ca14444a4923","user":{"login":"bartvm","id":2299595,"avatar_url":"https://avatars.githubusercontent.com/u/2299595?v=3","gravatar_id":"","url":"https://api.github.com/users/bartvm","html_url":"https://github.com/bartvm","followers_url":"https://api.github.com/users/bartvm/followers","following_url":"https://api.github.com/users/bartvm/following{/other_user}","gists_url":"https://api.github.com/users/bartvm/gists{/gist_id}","starred_url":"https://api.github.com/users/bartvm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bartvm/subscriptions","organizations_url":"https://api.github.com/users/bartvm/orgs","repos_url":"https://api.github.com/users/bartvm/repos","events_url":"https://api.github.com/users/bartvm/events{/privacy}","received_events_url":"https://api.github.com/users/bartvm/received_events","type":"User","site_admin":false},"repo":{"id":24829371,"name":"blocks","full_name":"bartvm/blocks","owner":{"login":"bartvm","id":2299595,"avatar_url":"https://avatars.githubusercontent.com/u/2299595?v=3","gravatar_id":"","url":"https://api.github.com/users/bartvm","html_url":"https://github.com/bartvm","followers_url":"https://api.github.com/users/bartvm/followers","following_url":"https://api.github.com/users/bartvm/following{/other_user}","gists_url":"https://api.github.com/users/bartvm/gists{/gist_id}","starred_url":"https://api.github.com/users/bartvm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bartvm/subscriptions","organizations_url":"https://api.github.com/users/bartvm/orgs","repos_url":"https://api.github.com/users/bartvm/repos","events_url":"https://api.github.com/users/bartvm/events{/privacy}","received_events_url":"https://api.github.com/users/bartvm/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bartvm/blocks","description":"A Theano framework for building and training neural networks","fork":false,"url":"https://api.github.com/repos/bartvm/blocks","forks_url":"https://api.github.com/repos/bartvm/blocks/forks","keys_url":"https://api.github.com/repos/bartvm/blocks/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bartvm/blocks/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bartvm/blocks/teams","hooks_url":"https://api.github.com/repos/bartvm/blocks/hooks","issue_events_url":"https://api.github.com/repos/bartvm/blocks/issues/events{/number}","events_url":"https://api.github.com/repos/bartvm/blocks/events","assignees_url":"https://api.github.com/repos/bartvm/blocks/assignees{/user}","branches_url":"https://api.github.com/repos/bartvm/blocks/branches{/branch}","tags_url":"https://api.github.com/repos/bartvm/blocks/tags","blobs_url":"https://api.github.com/repos/bartvm/blocks/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bartvm/blocks/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bartvm/blocks/git/refs{/sha}","trees_url":"https://api.github.com/repos/bartvm/blocks/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bartvm/blocks/statuses/{sha}","languages_url":"https://api.github.com/repos/bartvm/blocks/languages","stargazers_url":"https://api.github.com/repos/bartvm/blocks/stargazers","contributors_url":"https://api.github.com/repos/bartvm/blocks/contributors","subscribers_url":"https://api.github.com/repos/bartvm/blocks/subscribers","subscription_url":"https://api.github.com/repos/bartvm/blocks/subscription","commits_url":"https://api.github.com/repos/bartvm/blocks/commits{/sha}","git_commits_url":"https://api.github.com/repos/bartvm/blocks/git/commits{/sha}","comments_url":"https://api.github.com/repos/bartvm/blocks/comments{/number}","issue_comment_url":"https://api.github.com/repos/bartvm/blocks/issues/comments/{number}","contents_url":"https://api.github.com/repos/bartvm/blocks/contents/{+path}","compare_url":"https://api.github.com/repos/bartvm/blocks/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bartvm/blocks/merges","archive_url":"https://api.github.com/repos/bartvm/blocks/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bartvm/blocks/downloads","issues_url":"https://api.github.com/repos/bartvm/blocks/issues{/number}","pulls_url":"https://api.github.com/repos/bartvm/blocks/pulls{/number}","milestones_url":"https://api.github.com/repos/bartvm/blocks/milestones{/number}","notifications_url":"https://api.github.com/repos/bartvm/blocks/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bartvm/blocks/labels{/name}","releases_url":"https://api.github.com/repos/bartvm/blocks/releases{/id}","created_at":"2014-10-06T00:08:32Z","updated_at":"2015-02-18T09:47:54Z","pushed_at":"2015-02-18T11:41:54Z","git_url":"git://github.com/bartvm/blocks.git","ssh_url":"git@github.com:bartvm/blocks.git","clone_url":"https://github.com/bartvm/blocks.git","svn_url":"https://github.com/bartvm/blocks","homepage":"","size":15898,"stargazers_count":95,"watchers_count":95,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":29,"mirror_url":null,"open_issues_count":47,"forks":29,"open_issues":47,"watchers":95,"default_branch":"master"}},"base":{"label":"bartvm:master","ref":"master","sha":"f932295c9f9ec9533934b200dd6bc18fd7da888c","user":{"login":"bartvm","id":2299595,"avatar_url":"https://avatars.githubusercontent.com/u/2299595?v=3","gravatar_id":"","url":"https://api.github.com/users/bartvm","html_url":"https://github.com/bartvm","followers_url":"https://api.github.com/users/bartvm/followers","following_url":"https://api.github.com/users/bartvm/following{/other_user}","gists_url":"https://api.github.com/users/bartvm/gists{/gist_id}","starred_url":"https://api.github.com/users/bartvm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bartvm/subscriptions","organizations_url":"https://api.github.com/users/bartvm/orgs","repos_url":"https://api.github.com/users/bartvm/repos","events_url":"https://api.github.com/users/bartvm/events{/privacy}","received_events_url":"https://api.github.com/users/bartvm/received_events","type":"User","site_admin":false},"repo":{"id":24829371,"name":"blocks","full_name":"bartvm/blocks","owner":{"login":"bartvm","id":2299595,"avatar_url":"https://avatars.githubusercontent.com/u/2299595?v=3","gravatar_id":"","url":"https://api.github.com/users/bartvm","html_url":"https://github.com/bartvm","followers_url":"https://api.github.com/users/bartvm/followers","following_url":"https://api.github.com/users/bartvm/following{/other_user}","gists_url":"https://api.github.com/users/bartvm/gists{/gist_id}","starred_url":"https://api.github.com/users/bartvm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bartvm/subscriptions","organizations_url":"https://api.github.com/users/bartvm/orgs","repos_url":"https://api.github.com/users/bartvm/repos","events_url":"https://api.github.com/users/bartvm/events{/privacy}","received_events_url":"https://api.github.com/users/bartvm/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bartvm/blocks","description":"A Theano framework for building and training neural networks","fork":false,"url":"https://api.github.com/repos/bartvm/blocks","forks_url":"https://api.github.com/repos/bartvm/blocks/forks","keys_url":"https://api.github.com/repos/bartvm/blocks/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bartvm/blocks/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bartvm/blocks/teams","hooks_url":"https://api.github.com/repos/bartvm/blocks/hooks","issue_events_url":"https://api.github.com/repos/bartvm/blocks/issues/events{/number}","events_url":"https://api.github.com/repos/bartvm/blocks/events","assignees_url":"https://api.github.com/repos/bartvm/blocks/assignees{/user}","branches_url":"https://api.github.com/repos/bartvm/blocks/branches{/branch}","tags_url":"https://api.github.com/repos/bartvm/blocks/tags","blobs_url":"https://api.github.com/repos/bartvm/blocks/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bartvm/blocks/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bartvm/blocks/git/refs{/sha}","trees_url":"https://api.github.com/repos/bartvm/blocks/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bartvm/blocks/statuses/{sha}","languages_url":"https://api.github.com/repos/bartvm/blocks/languages","stargazers_url":"https://api.github.com/repos/bartvm/blocks/stargazers","contributors_url":"https://api.github.com/repos/bartvm/blocks/contributors","subscribers_url":"https://api.github.com/repos/bartvm/blocks/subscribers","subscription_url":"https://api.github.com/repos/bartvm/blocks/subscription","commits_url":"https://api.github.com/repos/bartvm/blocks/commits{/sha}","git_commits_url":"https://api.github.com/repos/bartvm/blocks/git/commits{/sha}","comments_url":"https://api.github.com/repos/bartvm/blocks/comments{/number}","issue_comment_url":"https://api.github.com/repos/bartvm/blocks/issues/comments/{number}","contents_url":"https://api.github.com/repos/bartvm/blocks/contents/{+path}","compare_url":"https://api.github.com/repos/bartvm/blocks/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bartvm/blocks/merges","archive_url":"https://api.github.com/repos/bartvm/blocks/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bartvm/blocks/downloads","issues_url":"https://api.github.com/repos/bartvm/blocks/issues{/number}","pulls_url":"https://api.github.com/repos/bartvm/blocks/pulls{/number}","milestones_url":"https://api.github.com/repos/bartvm/blocks/milestones{/number}","notifications_url":"https://api.github.com/repos/bartvm/blocks/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bartvm/blocks/labels{/name}","releases_url":"https://api.github.com/repos/bartvm/blocks/releases{/id}","created_at":"2014-10-06T00:08:32Z","updated_at":"2015-02-18T09:47:54Z","pushed_at":"2015-02-18T11:41:54Z","git_url":"git://github.com/bartvm/blocks.git","ssh_url":"git@github.com:bartvm/blocks.git","clone_url":"https://github.com/bartvm/blocks.git","svn_url":"https://github.com/bartvm/blocks","homepage":"","size":15898,"stargazers_count":95,"watchers_count":95,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":29,"mirror_url":null,"open_issues_count":47,"forks":29,"open_issues":47,"watchers":95,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bartvm/blocks/pulls/298"},"html":{"href":"https://github.com/bartvm/blocks/pull/298"},"issue":{"href":"https://api.github.com/repos/bartvm/blocks/issues/298"},"comments":{"href":"https://api.github.com/repos/bartvm/blocks/issues/298/comments"},"review_comments":{"href":"https://api.github.com/repos/bartvm/blocks/pulls/298/comments"},"review_comment":{"href":"https://api.github.com/repos/bartvm/blocks/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/bartvm/blocks/pulls/298/commits"},"statuses":{"href":"https://api.github.com/repos/bartvm/blocks/statuses/cfa87dee23c5fec1eabba58f3d25ca14444a4923"}}}}