{"action":"created","comment":{"url":"https://api.github.com/repos/numenta/nupic.research/pulls/comments/32336720","id":32336720,"diff_hunk":"@@ -0,0 +1,367 @@\n+# ----------------------------------------------------------------------\n+# Numenta Platform for Intelligent Computing (NuPIC)\n+# Copyright (C) 2015, Numenta, Inc.  Unless you have an agreement\n+# with Numenta, Inc., for a separate license for this software code, the\n+# following terms and conditions apply:\n+#\n+# This program is free software: you can redistribute it and/or modify\n+# it under the terms of the GNU General Public License version 3 as\n+# published by the Free Software Foundation.\n+#\n+# This program is distributed in the hope that it will be useful,\n+# but WITHOUT ANY WARRANTY; without even the implied warranty of\n+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n+# See the GNU General Public License for more details.\n+#\n+# You should have received a copy of the GNU General Public License\n+# along with this program.  If not, see http://www.gnu.org/licenses.\n+#\n+# http://numenta.org/licenses/\n+# ----------------------------------------------------------------------\n+\n+import numpy\n+from nupic.bindings.math import GetNTAReal\n+#from nupic.research.union_pooler import UnionPooler\n+from union_pooling.union_pooler import UnionPooler\n+from nupic.support import getArgumentDescriptions\n+from nupic.regions.PyRegion import PyRegion\n+\n+\n+\n+def _getPoolerClass(name):\n+    if name==\"union\":\n+      return UnionPooler\n+    else:\n+      raise RuntimeError(\"Invalid pooling implementation %s. Valid ones are: union\" % (name))\n+\n+\n+def _getDefaultPoolerClass():\n+    return UnionPooler\n+\n+\n+def _buildArgs(poolerClass, self=None, kwargs={}):\n+  \"\"\"\n+  Get the default arguments from the function and assign as instance vars.\n+\n+  Return a list of 3-tuples with (name, description, defaultValue) for each\n+    argument to the function.\n+\n+  Assigns all arguments to the function as instance variables of PoolingRegion.\n+  If the argument was not provided, uses the default value.\n+\n+  Pops any values from kwargs that go to the function.\n+\n+  \"\"\"\n+  # Get the name, description, and default value for each argument\n+  argTuples = getArgumentDescriptions(poolerClass.__init__)\n+  argTuples = argTuples[1:]  # Remove \"self\"\n+\n+  # Get the names of the parameters to our own constructor and remove them\n+  init = PoolingRegion.__init__\n+  ourArgNames = [t[0] for t in getArgumentDescriptions(init)]\n+  # Also remove a few other names that aren't in our constructor but are\n+  #  computed automatically\n+  ourArgNames += [\n+    \"inputDimensions\",\n+  ]\n+  for argTuple in argTuples[:]:\n+    if argTuple[0] in ourArgNames:\n+      argTuples.remove(argTuple)\n+\n+  # Build the dictionary of arguments\n+  if self:\n+    for argTuple in argTuples:\n+      argName = argTuple[0]\n+      if argName in kwargs:\n+        # Argument was provided\n+        argValue = kwargs.pop(argName)\n+      else:\n+        # Argument was not provided; use the default value if there is one, and\n+        #  raise an exception otherwise\n+        if len(argTuple) == 2:\n+          # No default value\n+          raise TypeError(\"Must provide value for '%s'\" % argName)\n+        argValue = argTuple[2]\n+      # Set as an instance variable if \"self\" was passed in\n+      setattr(self, argName, argValue)\n+\n+  return argTuples\n+\n+\n+def _getAdditionalSpecs(poolerClass=_getDefaultPoolerClass()):\n+  \"\"\"Build the additional specs in three groups (for the inspector)\n+\n+  Use the type of the default argument to set the Spec type, defaulting\n+  to \"Byte\" for None and complex types\n+\n+  Determines the pooler parameters based on the selected implementation.\n+  \"\"\"\n+  typeNames = {int: \"UInt32\", float: \"Real32\", str: \"Byte\", bool: \"bool\", tuple: \"tuple\"}\n+\n+  def getArgType(arg):\n+    t = typeNames.get(type(arg), \"Byte\")\n+    count = 0 if t == \"Byte\" else 1\n+    if t == \"tuple\":\n+      t = typeNames.get(type(arg[0]), \"Byte\")\n+      count = len(arg)\n+    if t == \"bool\":\n+      t = \"UInt32\"\n+    return (t, count)\n+\n+  def getConstraints(arg):\n+    t = typeNames.get(type(arg), \"Byte\")\n+    if t == \"Byte\":\n+      return \"multiple\"\n+    elif t == \"bool\":\n+      return \"bool\"\n+    else:\n+      return \"\"\n+\n+  # Get arguments from pooler constructors, figure out types of\n+  # variables and populate poolerSpec.\n+  pArgTuples = _buildArgs(poolerClass)","path":"union_pooling/union_pooling/PoolingRegion.py","position":122,"original_position":122,"commit_id":"7bae2646695d551382e5e07f40066a83402a013f","original_commit_id":"c4141b2f4ce5885bf56e77fcc9733475d5170dd4","user":{"login":"akhilaananthram","id":5855832,"avatar_url":"https://avatars.githubusercontent.com/u/5855832?v=3","gravatar_id":"","url":"https://api.github.com/users/akhilaananthram","html_url":"https://github.com/akhilaananthram","followers_url":"https://api.github.com/users/akhilaananthram/followers","following_url":"https://api.github.com/users/akhilaananthram/following{/other_user}","gists_url":"https://api.github.com/users/akhilaananthram/gists{/gist_id}","starred_url":"https://api.github.com/users/akhilaananthram/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akhilaananthram/subscriptions","organizations_url":"https://api.github.com/users/akhilaananthram/orgs","repos_url":"https://api.github.com/users/akhilaananthram/repos","events_url":"https://api.github.com/users/akhilaananthram/events{/privacy}","received_events_url":"https://api.github.com/users/akhilaananthram/received_events","type":"User","site_admin":false},"body":"If I explicitly define poolerSpec, then I would have to modify this section every time we make a change to UnionPooler's __init__ arguments.  Right now it gets all the arguments that the UnionPooler has by calling _buildArgs. So, if you make a change to UnionPooler, it will make that change here as well automatically.","created_at":"2015-06-12T17:37:35Z","updated_at":"2015-06-12T17:37:35Z","html_url":"https://github.com/numenta/nupic.research/pull/180#discussion_r32336720","pull_request_url":"https://api.github.com/repos/numenta/nupic.research/pulls/180","_links":{"self":{"href":"https://api.github.com/repos/numenta/nupic.research/pulls/comments/32336720"},"html":{"href":"https://github.com/numenta/nupic.research/pull/180#discussion_r32336720"},"pull_request":{"href":"https://api.github.com/repos/numenta/nupic.research/pulls/180"}}},"pull_request":{"url":"https://api.github.com/repos/numenta/nupic.research/pulls/180","id":37511955,"html_url":"https://github.com/numenta/nupic.research/pull/180","diff_url":"https://github.com/numenta/nupic.research/pull/180.diff","patch_url":"https://github.com/numenta/nupic.research/pull/180.patch","issue_url":"https://api.github.com/repos/numenta/nupic.research/issues/180","number":180,"state":"open","locked":false,"title":"Region for the Union Pooler and a demo for integrating it into the network","user":{"login":"akhilaananthram","id":5855832,"avatar_url":"https://avatars.githubusercontent.com/u/5855832?v=3","gravatar_id":"","url":"https://api.github.com/users/akhilaananthram","html_url":"https://github.com/akhilaananthram","followers_url":"https://api.github.com/users/akhilaananthram/followers","following_url":"https://api.github.com/users/akhilaananthram/following{/other_user}","gists_url":"https://api.github.com/users/akhilaananthram/gists{/gist_id}","starred_url":"https://api.github.com/users/akhilaananthram/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akhilaananthram/subscriptions","organizations_url":"https://api.github.com/users/akhilaananthram/orgs","repos_url":"https://api.github.com/users/akhilaananthram/repos","events_url":"https://api.github.com/users/akhilaananthram/events{/privacy}","received_events_url":"https://api.github.com/users/akhilaananthram/received_events","type":"User","site_admin":false},"body":"The region for the union pooler encapsulates union_pooler.py and sets up the inputs for it.  It can be integrated into the network API.\r\n\r\nnetwork_integration_demo.py shows how this region can be integrated.  Because the current TPRegion does not output the active+predicted cells, I have a separate PR in nupic for that: https://github.com/numenta/nupic/pull/2206\r\n\r\n@rmccall84 @scottpurdy \r\n\r\nFixes #69 ","created_at":"2015-06-11T21:42:25Z","updated_at":"2015-06-12T17:37:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fbf5351bd0506d0594e957faa0617d176dc28acb","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/numenta/nupic.research/pulls/180/commits","review_comments_url":"https://api.github.com/repos/numenta/nupic.research/pulls/180/comments","review_comment_url":"https://api.github.com/repos/numenta/nupic.research/pulls/comments{/number}","comments_url":"https://api.github.com/repos/numenta/nupic.research/issues/180/comments","statuses_url":"https://api.github.com/repos/numenta/nupic.research/statuses/7bae2646695d551382e5e07f40066a83402a013f","head":{"label":"akhilaananthram:unionpooler_region","ref":"unionpooler_region","sha":"7bae2646695d551382e5e07f40066a83402a013f","user":{"login":"akhilaananthram","id":5855832,"avatar_url":"https://avatars.githubusercontent.com/u/5855832?v=3","gravatar_id":"","url":"https://api.github.com/users/akhilaananthram","html_url":"https://github.com/akhilaananthram","followers_url":"https://api.github.com/users/akhilaananthram/followers","following_url":"https://api.github.com/users/akhilaananthram/following{/other_user}","gists_url":"https://api.github.com/users/akhilaananthram/gists{/gist_id}","starred_url":"https://api.github.com/users/akhilaananthram/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akhilaananthram/subscriptions","organizations_url":"https://api.github.com/users/akhilaananthram/orgs","repos_url":"https://api.github.com/users/akhilaananthram/repos","events_url":"https://api.github.com/users/akhilaananthram/events{/privacy}","received_events_url":"https://api.github.com/users/akhilaananthram/received_events","type":"User","site_admin":false},"repo":{"id":36838276,"name":"nupic.research","full_name":"akhilaananthram/nupic.research","owner":{"login":"akhilaananthram","id":5855832,"avatar_url":"https://avatars.githubusercontent.com/u/5855832?v=3","gravatar_id":"","url":"https://api.github.com/users/akhilaananthram","html_url":"https://github.com/akhilaananthram","followers_url":"https://api.github.com/users/akhilaananthram/followers","following_url":"https://api.github.com/users/akhilaananthram/following{/other_user}","gists_url":"https://api.github.com/users/akhilaananthram/gists{/gist_id}","starred_url":"https://api.github.com/users/akhilaananthram/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akhilaananthram/subscriptions","organizations_url":"https://api.github.com/users/akhilaananthram/orgs","repos_url":"https://api.github.com/users/akhilaananthram/repos","events_url":"https://api.github.com/users/akhilaananthram/events{/privacy}","received_events_url":"https://api.github.com/users/akhilaananthram/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/akhilaananthram/nupic.research","description":"Experimental algorithms. Unsupported.","fork":true,"url":"https://api.github.com/repos/akhilaananthram/nupic.research","forks_url":"https://api.github.com/repos/akhilaananthram/nupic.research/forks","keys_url":"https://api.github.com/repos/akhilaananthram/nupic.research/keys{/key_id}","collaborators_url":"https://api.github.com/repos/akhilaananthram/nupic.research/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/akhilaananthram/nupic.research/teams","hooks_url":"https://api.github.com/repos/akhilaananthram/nupic.research/hooks","issue_events_url":"https://api.github.com/repos/akhilaananthram/nupic.research/issues/events{/number}","events_url":"https://api.github.com/repos/akhilaananthram/nupic.research/events","assignees_url":"https://api.github.com/repos/akhilaananthram/nupic.research/assignees{/user}","branches_url":"https://api.github.com/repos/akhilaananthram/nupic.research/branches{/branch}","tags_url":"https://api.github.com/repos/akhilaananthram/nupic.research/tags","blobs_url":"https://api.github.com/repos/akhilaananthram/nupic.research/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/akhilaananthram/nupic.research/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/akhilaananthram/nupic.research/git/refs{/sha}","trees_url":"https://api.github.com/repos/akhilaananthram/nupic.research/git/trees{/sha}","statuses_url":"https://api.github.com/repos/akhilaananthram/nupic.research/statuses/{sha}","languages_url":"https://api.github.com/repos/akhilaananthram/nupic.research/languages","stargazers_url":"https://api.github.com/repos/akhilaananthram/nupic.research/stargazers","contributors_url":"https://api.github.com/repos/akhilaananthram/nupic.research/contributors","subscribers_url":"https://api.github.com/repos/akhilaananthram/nupic.research/subscribers","subscription_url":"https://api.github.com/repos/akhilaananthram/nupic.research/subscription","commits_url":"https://api.github.com/repos/akhilaananthram/nupic.research/commits{/sha}","git_commits_url":"https://api.github.com/repos/akhilaananthram/nupic.research/git/commits{/sha}","comments_url":"https://api.github.com/repos/akhilaananthram/nupic.research/comments{/number}","issue_comment_url":"https://api.github.com/repos/akhilaananthram/nupic.research/issues/comments{/number}","contents_url":"https://api.github.com/repos/akhilaananthram/nupic.research/contents/{+path}","compare_url":"https://api.github.com/repos/akhilaananthram/nupic.research/compare/{base}...{head}","merges_url":"https://api.github.com/repos/akhilaananthram/nupic.research/merges","archive_url":"https://api.github.com/repos/akhilaananthram/nupic.research/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/akhilaananthram/nupic.research/downloads","issues_url":"https://api.github.com/repos/akhilaananthram/nupic.research/issues{/number}","pulls_url":"https://api.github.com/repos/akhilaananthram/nupic.research/pulls{/number}","milestones_url":"https://api.github.com/repos/akhilaananthram/nupic.research/milestones{/number}","notifications_url":"https://api.github.com/repos/akhilaananthram/nupic.research/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/akhilaananthram/nupic.research/labels{/name}","releases_url":"https://api.github.com/repos/akhilaananthram/nupic.research/releases{/id}","created_at":"2015-06-04T00:28:02Z","updated_at":"2015-06-04T00:28:03Z","pushed_at":"2015-06-12T17:35:13Z","git_url":"git://github.com/akhilaananthram/nupic.research.git","ssh_url":"git@github.com:akhilaananthram/nupic.research.git","clone_url":"https://github.com/akhilaananthram/nupic.research.git","svn_url":"https://github.com/akhilaananthram/nupic.research","homepage":null,"size":45129,"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":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"numenta:master","ref":"master","sha":"52724792c1233b46db8d2603bf694dbd31d33c33","user":{"login":"numenta","id":1039191,"avatar_url":"https://avatars.githubusercontent.com/u/1039191?v=3","gravatar_id":"","url":"https://api.github.com/users/numenta","html_url":"https://github.com/numenta","followers_url":"https://api.github.com/users/numenta/followers","following_url":"https://api.github.com/users/numenta/following{/other_user}","gists_url":"https://api.github.com/users/numenta/gists{/gist_id}","starred_url":"https://api.github.com/users/numenta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/numenta/subscriptions","organizations_url":"https://api.github.com/users/numenta/orgs","repos_url":"https://api.github.com/users/numenta/repos","events_url":"https://api.github.com/users/numenta/events{/privacy}","received_events_url":"https://api.github.com/users/numenta/received_events","type":"Organization","site_admin":false},"repo":{"id":23565243,"name":"nupic.research","full_name":"numenta/nupic.research","owner":{"login":"numenta","id":1039191,"avatar_url":"https://avatars.githubusercontent.com/u/1039191?v=3","gravatar_id":"","url":"https://api.github.com/users/numenta","html_url":"https://github.com/numenta","followers_url":"https://api.github.com/users/numenta/followers","following_url":"https://api.github.com/users/numenta/following{/other_user}","gists_url":"https://api.github.com/users/numenta/gists{/gist_id}","starred_url":"https://api.github.com/users/numenta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/numenta/subscriptions","organizations_url":"https://api.github.com/users/numenta/orgs","repos_url":"https://api.github.com/users/numenta/repos","events_url":"https://api.github.com/users/numenta/events{/privacy}","received_events_url":"https://api.github.com/users/numenta/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/numenta/nupic.research","description":"Experimental algorithms. Unsupported.","fork":false,"url":"https://api.github.com/repos/numenta/nupic.research","forks_url":"https://api.github.com/repos/numenta/nupic.research/forks","keys_url":"https://api.github.com/repos/numenta/nupic.research/keys{/key_id}","collaborators_url":"https://api.github.com/repos/numenta/nupic.research/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/numenta/nupic.research/teams","hooks_url":"https://api.github.com/repos/numenta/nupic.research/hooks","issue_events_url":"https://api.github.com/repos/numenta/nupic.research/issues/events{/number}","events_url":"https://api.github.com/repos/numenta/nupic.research/events","assignees_url":"https://api.github.com/repos/numenta/nupic.research/assignees{/user}","branches_url":"https://api.github.com/repos/numenta/nupic.research/branches{/branch}","tags_url":"https://api.github.com/repos/numenta/nupic.research/tags","blobs_url":"https://api.github.com/repos/numenta/nupic.research/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/numenta/nupic.research/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/numenta/nupic.research/git/refs{/sha}","trees_url":"https://api.github.com/repos/numenta/nupic.research/git/trees{/sha}","statuses_url":"https://api.github.com/repos/numenta/nupic.research/statuses/{sha}","languages_url":"https://api.github.com/repos/numenta/nupic.research/languages","stargazers_url":"https://api.github.com/repos/numenta/nupic.research/stargazers","contributors_url":"https://api.github.com/repos/numenta/nupic.research/contributors","subscribers_url":"https://api.github.com/repos/numenta/nupic.research/subscribers","subscription_url":"https://api.github.com/repos/numenta/nupic.research/subscription","commits_url":"https://api.github.com/repos/numenta/nupic.research/commits{/sha}","git_commits_url":"https://api.github.com/repos/numenta/nupic.research/git/commits{/sha}","comments_url":"https://api.github.com/repos/numenta/nupic.research/comments{/number}","issue_comment_url":"https://api.github.com/repos/numenta/nupic.research/issues/comments{/number}","contents_url":"https://api.github.com/repos/numenta/nupic.research/contents/{+path}","compare_url":"https://api.github.com/repos/numenta/nupic.research/compare/{base}...{head}","merges_url":"https://api.github.com/repos/numenta/nupic.research/merges","archive_url":"https://api.github.com/repos/numenta/nupic.research/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/numenta/nupic.research/downloads","issues_url":"https://api.github.com/repos/numenta/nupic.research/issues{/number}","pulls_url":"https://api.github.com/repos/numenta/nupic.research/pulls{/number}","milestones_url":"https://api.github.com/repos/numenta/nupic.research/milestones{/number}","notifications_url":"https://api.github.com/repos/numenta/nupic.research/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/numenta/nupic.research/labels{/name}","releases_url":"https://api.github.com/repos/numenta/nupic.research/releases{/id}","created_at":"2014-09-02T04:42:30Z","updated_at":"2015-06-09T17:48:44Z","pushed_at":"2015-06-12T17:35:13Z","git_url":"git://github.com/numenta/nupic.research.git","ssh_url":"git@github.com:numenta/nupic.research.git","clone_url":"https://github.com/numenta/nupic.research.git","svn_url":"https://github.com/numenta/nupic.research","homepage":null,"size":48824,"stargazers_count":39,"watchers_count":39,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":22,"mirror_url":null,"open_issues_count":22,"forks":22,"open_issues":22,"watchers":39,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/numenta/nupic.research/pulls/180"},"html":{"href":"https://github.com/numenta/nupic.research/pull/180"},"issue":{"href":"https://api.github.com/repos/numenta/nupic.research/issues/180"},"comments":{"href":"https://api.github.com/repos/numenta/nupic.research/issues/180/comments"},"review_comments":{"href":"https://api.github.com/repos/numenta/nupic.research/pulls/180/comments"},"review_comment":{"href":"https://api.github.com/repos/numenta/nupic.research/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/numenta/nupic.research/pulls/180/commits"},"statuses":{"href":"https://api.github.com/repos/numenta/nupic.research/statuses/7bae2646695d551382e5e07f40066a83402a013f"}}}}