{"action":"created","comment":{"url":"https://api.github.com/repos/numenta/nupic.research/pulls/comments/49787067","id":49787067,"diff_hunk":"@@ -0,0 +1,115 @@\n+# ----------------------------------------------------------------------\n+# Numenta Platform for Intelligent Computing (NuPIC)\n+# Copyright (C) 2016, 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 Affero 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 Affero Public License for more details.\n+#\n+# You should have received a copy of the GNU Affero 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+\n+class SimpleUnionPooler(object):\n+  \"\"\"\n+  Experimental Simple Union Pooler Python Implementation.\n+  The simple union pooler computes a union of the last N SDRs\n+  \"\"\"\n+\n+  def __init__(self,\n+               numInputs=2048,\n+               historyLength=10):\n+    \"\"\"\n+    Parameters:\n+    ----------------------------\n+    @param numInputs: The length of the input SDRs\n+    @param historyLength: The union window length. For a union of the last\n+    10 steps, use historyLength=10\n+    \"\"\"\n+\n+    self._historyLength = historyLength\n+    self._numInputs = numInputs\n+    self.reset()\n+\n+\n+  def reset(self):\n+    \"\"\"\n+    Reset Union Pooler, clear active cell history\n+    \"\"\"\n+    self._unionSDR = numpy.zeros(shape=(self._numInputs,))\n+    self._activeCellsHistory = []\n+\n+\n+  def updateHistory(self, activeCells):\n+    \"\"\"\n+    Computes one cycle of the Union Pooler algorithm. Return the union SDR\n+    Parameters:\n+    ----------------------------\n+    @param activeCells: A list that stores indices of active cells\n+    \"\"\"\n+    self._activeCellsHistory.append(activeCells)\n+    if len(self._activeCellsHistory) > self._historyLength:\n+      self._activeCellsHistory.pop(0)\n+\n+    self._unionSDR = numpy.zeros(shape=(self._numInputs,))\n+    for i in self._activeCellsHistory:\n+      self._unionSDR[i] = 1\n+\n+    return self._unionSDR\n+\n+\n+  def unionIntoArray(self, inputVector, outputVector):\n+    \"\"\"\n+    Create a union of the inputVector and copy the result into the outputVector\n+    Parameters:\n+    ----------------------------\n+    @param inputVector: The inputVector can be either a full numpy array\n+    containing 0's and 1's, or a list of non-zero entry indices\n+    @param outputVector: A numpy array that matches the length of the\n+    union pooler.\n+    \"\"\"\n+    if isinstance(inputVector, numpy.ndarray):\n+      if inputVector.size == self._numInputs:\n+        activeBits = numpy.where(inputVector)[0]\n+      else:\n+        raise ValueError(\n+          \"Input vector dimensions don't match. Expecting %s but got %s\" % (\n+            self._numInputs, inputVector.size))\n+    elif isinstance(inputVector, list):\n+      if max(inputVector) >= self._numInputs:\n+        raise ValueError(\n+          \"Non-zero entry indices exceed input dimension of union pooler. \"\n+          \"Expecting %s but got %s\" % (self._numInputs, max(inputVector)))\n+      else:\n+        activeBits = inputVector\n+    else:\n+      raise TypeError(\"Unsuported input types\")\n+\n+    if len(outputVector) != self._numInputs:\n+      raise ValueError(\n+        \"Output vector dimension does match dimension of union pooler \"\n+        \"Expecting %s but got %s\" % (self._numInputs, len(outputVector)))\n+\n+    unionSDR = self.updateHistory(activeBits)\n+\n+    for i in xrange(len(unionSDR)):\n+      outputVector[i] = unionSDR[i]","path":"htmresearch/algorithms/simple_union_pooler.py","position":107,"original_position":107,"commit_id":"980f6d23e839cf9eb7ab431ddcc6078b0579559f","original_commit_id":"980f6d23e839cf9eb7ab431ddcc6078b0579559f","user":{"login":"subutai","id":1268932,"avatar_url":"https://avatars.githubusercontent.com/u/1268932?v=3","gravatar_id":"","url":"https://api.github.com/users/subutai","html_url":"https://github.com/subutai","followers_url":"https://api.github.com/users/subutai/followers","following_url":"https://api.github.com/users/subutai/following{/other_user}","gists_url":"https://api.github.com/users/subutai/gists{/gist_id}","starred_url":"https://api.github.com/users/subutai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/subutai/subscriptions","organizations_url":"https://api.github.com/users/subutai/orgs","repos_url":"https://api.github.com/users/subutai/repos","events_url":"https://api.github.com/users/subutai/events{/privacy}","received_events_url":"https://api.github.com/users/subutai/received_events","type":"User","site_admin":false},"body":"I believe numpy.copyto(outputVector,unionSDR,casting=\"unsafe\") would be faster than doing this loop.","created_at":"2016-01-14T21:22:06Z","updated_at":"2016-01-14T21:22:06Z","html_url":"https://github.com/numenta/nupic.research/pull/410#discussion_r49787067","pull_request_url":"https://api.github.com/repos/numenta/nupic.research/pulls/410","_links":{"self":{"href":"https://api.github.com/repos/numenta/nupic.research/pulls/comments/49787067"},"html":{"href":"https://github.com/numenta/nupic.research/pull/410#discussion_r49787067"},"pull_request":{"href":"https://api.github.com/repos/numenta/nupic.research/pulls/410"}}},"pull_request":{"url":"https://api.github.com/repos/numenta/nupic.research/pulls/410","id":55587916,"html_url":"https://github.com/numenta/nupic.research/pull/410","diff_url":"https://github.com/numenta/nupic.research/pull/410.diff","patch_url":"https://github.com/numenta/nupic.research/pull/410.patch","issue_url":"https://api.github.com/repos/numenta/nupic.research/issues/410","number":410,"state":"open","locked":false,"title":"[RES-140] Simple union pooler Implementation","user":{"login":"ywcui1990","id":5067931,"avatar_url":"https://avatars.githubusercontent.com/u/5067931?v=3","gravatar_id":"","url":"https://api.github.com/users/ywcui1990","html_url":"https://github.com/ywcui1990","followers_url":"https://api.github.com/users/ywcui1990/followers","following_url":"https://api.github.com/users/ywcui1990/following{/other_user}","gists_url":"https://api.github.com/users/ywcui1990/gists{/gist_id}","starred_url":"https://api.github.com/users/ywcui1990/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ywcui1990/subscriptions","organizations_url":"https://api.github.com/users/ywcui1990/orgs","repos_url":"https://api.github.com/users/ywcui1990/repos","events_url":"https://api.github.com/users/ywcui1990/events{/privacy}","received_events_url":"https://api.github.com/users/ywcui1990/received_events","type":"User","site_admin":false},"body":"@subutai @BoltzmannBrain \r\n\r\n* Implement a simple union pooler that computes a union of the last N SDRs\r\n* Add test for simple union pooler","created_at":"2016-01-11T05:24:13Z","updated_at":"2016-01-14T21:22:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c0a24f728fded30784bdbcd9dfc49040f77b1ccc","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/numenta/nupic.research/pulls/410/commits","review_comments_url":"https://api.github.com/repos/numenta/nupic.research/pulls/410/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/410/comments","statuses_url":"https://api.github.com/repos/numenta/nupic.research/statuses/980f6d23e839cf9eb7ab431ddcc6078b0579559f","head":{"label":"ywcui1990:simple_union_pooler","ref":"simple_union_pooler","sha":"980f6d23e839cf9eb7ab431ddcc6078b0579559f","user":{"login":"ywcui1990","id":5067931,"avatar_url":"https://avatars.githubusercontent.com/u/5067931?v=3","gravatar_id":"","url":"https://api.github.com/users/ywcui1990","html_url":"https://github.com/ywcui1990","followers_url":"https://api.github.com/users/ywcui1990/followers","following_url":"https://api.github.com/users/ywcui1990/following{/other_user}","gists_url":"https://api.github.com/users/ywcui1990/gists{/gist_id}","starred_url":"https://api.github.com/users/ywcui1990/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ywcui1990/subscriptions","organizations_url":"https://api.github.com/users/ywcui1990/orgs","repos_url":"https://api.github.com/users/ywcui1990/repos","events_url":"https://api.github.com/users/ywcui1990/events{/privacy}","received_events_url":"https://api.github.com/users/ywcui1990/received_events","type":"User","site_admin":false},"repo":{"id":24243024,"name":"nupic.research","full_name":"ywcui1990/nupic.research","owner":{"login":"ywcui1990","id":5067931,"avatar_url":"https://avatars.githubusercontent.com/u/5067931?v=3","gravatar_id":"","url":"https://api.github.com/users/ywcui1990","html_url":"https://github.com/ywcui1990","followers_url":"https://api.github.com/users/ywcui1990/followers","following_url":"https://api.github.com/users/ywcui1990/following{/other_user}","gists_url":"https://api.github.com/users/ywcui1990/gists{/gist_id}","starred_url":"https://api.github.com/users/ywcui1990/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ywcui1990/subscriptions","organizations_url":"https://api.github.com/users/ywcui1990/orgs","repos_url":"https://api.github.com/users/ywcui1990/repos","events_url":"https://api.github.com/users/ywcui1990/events{/privacy}","received_events_url":"https://api.github.com/users/ywcui1990/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ywcui1990/nupic.research","description":"Experimental algorithms. Unsupported.","fork":true,"url":"https://api.github.com/repos/ywcui1990/nupic.research","forks_url":"https://api.github.com/repos/ywcui1990/nupic.research/forks","keys_url":"https://api.github.com/repos/ywcui1990/nupic.research/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ywcui1990/nupic.research/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ywcui1990/nupic.research/teams","hooks_url":"https://api.github.com/repos/ywcui1990/nupic.research/hooks","issue_events_url":"https://api.github.com/repos/ywcui1990/nupic.research/issues/events{/number}","events_url":"https://api.github.com/repos/ywcui1990/nupic.research/events","assignees_url":"https://api.github.com/repos/ywcui1990/nupic.research/assignees{/user}","branches_url":"https://api.github.com/repos/ywcui1990/nupic.research/branches{/branch}","tags_url":"https://api.github.com/repos/ywcui1990/nupic.research/tags","blobs_url":"https://api.github.com/repos/ywcui1990/nupic.research/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ywcui1990/nupic.research/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ywcui1990/nupic.research/git/refs{/sha}","trees_url":"https://api.github.com/repos/ywcui1990/nupic.research/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ywcui1990/nupic.research/statuses/{sha}","languages_url":"https://api.github.com/repos/ywcui1990/nupic.research/languages","stargazers_url":"https://api.github.com/repos/ywcui1990/nupic.research/stargazers","contributors_url":"https://api.github.com/repos/ywcui1990/nupic.research/contributors","subscribers_url":"https://api.github.com/repos/ywcui1990/nupic.research/subscribers","subscription_url":"https://api.github.com/repos/ywcui1990/nupic.research/subscription","commits_url":"https://api.github.com/repos/ywcui1990/nupic.research/commits{/sha}","git_commits_url":"https://api.github.com/repos/ywcui1990/nupic.research/git/commits{/sha}","comments_url":"https://api.github.com/repos/ywcui1990/nupic.research/comments{/number}","issue_comment_url":"https://api.github.com/repos/ywcui1990/nupic.research/issues/comments{/number}","contents_url":"https://api.github.com/repos/ywcui1990/nupic.research/contents/{+path}","compare_url":"https://api.github.com/repos/ywcui1990/nupic.research/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ywcui1990/nupic.research/merges","archive_url":"https://api.github.com/repos/ywcui1990/nupic.research/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ywcui1990/nupic.research/downloads","issues_url":"https://api.github.com/repos/ywcui1990/nupic.research/issues{/number}","pulls_url":"https://api.github.com/repos/ywcui1990/nupic.research/pulls{/number}","milestones_url":"https://api.github.com/repos/ywcui1990/nupic.research/milestones{/number}","notifications_url":"https://api.github.com/repos/ywcui1990/nupic.research/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ywcui1990/nupic.research/labels{/name}","releases_url":"https://api.github.com/repos/ywcui1990/nupic.research/releases{/id}","created_at":"2014-09-19T19:40:54Z","updated_at":"2016-01-13T07:38:15Z","pushed_at":"2016-01-14T09:01:07Z","git_url":"git://github.com/ywcui1990/nupic.research.git","ssh_url":"git@github.com:ywcui1990/nupic.research.git","clone_url":"https://github.com/ywcui1990/nupic.research.git","svn_url":"https://github.com/ywcui1990/nupic.research","homepage":null,"size":136173,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"3137a91423279642db0f979e406989c2889935e7","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":"2016-01-11T17:35:54Z","pushed_at":"2016-01-14T18:20:17Z","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":137079,"stargazers_count":61,"watchers_count":61,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":38,"mirror_url":null,"open_issues_count":36,"forks":38,"open_issues":36,"watchers":61,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/numenta/nupic.research/pulls/410"},"html":{"href":"https://github.com/numenta/nupic.research/pull/410"},"issue":{"href":"https://api.github.com/repos/numenta/nupic.research/issues/410"},"comments":{"href":"https://api.github.com/repos/numenta/nupic.research/issues/410/comments"},"review_comments":{"href":"https://api.github.com/repos/numenta/nupic.research/pulls/410/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/410/commits"},"statuses":{"href":"https://api.github.com/repos/numenta/nupic.research/statuses/980f6d23e839cf9eb7ab431ddcc6078b0579559f"}}}}