{"action":"created","comment":{"url":"https://api.github.com/repos/numenta/nupic/pulls/comments/27752092","id":27752092,"diff_hunk":"@@ -36,189 +40,226 @@ class CategoryEncoderTest(unittest.TestCase):\n \n \n   def testCategoryEncoder(self):\n-      verbosity = 0\n-\n-      print \"Testing CategoryEncoder...\",\n-      categories = [\"ES\", \"GB\", \"US\"]\n-\n+    verbosity = 0\n+\n+    print \"Testing CategoryEncoder...\",\n+    categories = [\"ES\", \"GB\", \"US\"]\n+\n+    # forced: is not recommended, but is used here for readability. see scalar.py\n+    e = CategoryEncoder(w=3, categoryList=categories, forced=True)\n+    output = e.encode(\"US\")\n+    self.assertTrue((output == numpy.array([0,0,0,0,0,0,0,0,0,1,1,1], dtype=defaultDtype)).all())\n+\n+    # Test reverse lookup\n+    decoded = e.decode(output)\n+    (fieldsDict, fieldNames) = decoded\n+    self.assertEqual(len(fieldsDict), 1)\n+    (ranges, desc) = fieldsDict.values()[0]\n+    self.assertTrue(len(ranges) == 1 and numpy.array_equal(ranges[0], [3,3]))\n+    print \"decodedToStr of\", ranges, \"=>\", e.decodedToStr(decoded)\n+\n+    # Test topdown compute\n+    for v in categories:\n+      output = e.encode(v)\n+      topDown = e.topDownCompute(output)\n+      self.assertEqual(topDown.value, v)\n+      self.assertEqual(topDown.scalar, e.getScalars(v)[0])\n+\n+      bucketIndices = e.getBucketIndices(v)\n+      print \"bucket index =>\", bucketIndices[0]\n+      topDown = e.getBucketInfo(bucketIndices)[0]\n+      self.assertEqual(topDown.value, v)\n+      self.assertEqual(topDown.scalar, e.getScalars(v)[0])\n+      self.assertTrue((topDown.encoding == output).all())\n+      self.assertEqual(topDown.value, e.getBucketValues()[bucketIndices[0]])\n+\n+\n+\n+    # ---------------------\n+    # unknown category\n+    output = e.encode(\"NA\")\n+    self.assertTrue((output == numpy.array([1,1,1,0,0,0,0,0,0,0,0,0], dtype=defaultDtype)).all())\n+\n+    # Test reverse lookup\n+    decoded = e.decode(output)\n+    (fieldsDict, fieldNames) = decoded\n+    self.assertEqual(len(fieldsDict), 1)\n+    (ranges, desc) = fieldsDict.values()[0]\n+    self.assertTrue(len(ranges) == 1 and numpy.array_equal(ranges[0], [0,0]))\n+    print \"decodedToStr of\", ranges, \"=>\", e.decodedToStr(decoded)\n+\n+    # Test topdown compute\n+    topDown = e.topDownCompute(output)\n+    self.assertEqual(topDown.value, \"<UNKNOWN>\")\n+    self.assertEqual(topDown.scalar, 0)\n+\n+\n+    # --------------------------------\n+    # ES\n+    output = e.encode(\"ES\")\n+    self.assertTrue((output == numpy.array([0,0,0,1,1,1,0,0,0,0,0,0], dtype=defaultDtype)).all())\n+\n+    # MISSING VALUE\n+    outputForMissing = e.encode(SENTINEL_VALUE_FOR_MISSING_DATA)\n+    self.assertEqual(sum(outputForMissing), 0)\n+\n+    # Test reverse lookup\n+    decoded = e.decode(output)\n+    (fieldsDict, fieldNames) = decoded\n+    self.assertEqual(len(fieldsDict), 1)\n+    (ranges, desc) = fieldsDict.values()[0]\n+    self.assertTrue(len(ranges) == 1 and numpy.array_equal(ranges[0], [1,1]))","path":"tests/unit/nupic/encoders/category_test.py","position":94,"original_position":94,"commit_id":"d4ec2f49709c6354dea954b1cf83c31b1baea3ac","original_commit_id":"d4ec2f49709c6354dea954b1cf83c31b1baea3ac","user":{"login":"scottpurdy","id":239726,"avatar_url":"https://avatars.githubusercontent.com/u/239726?v=3","gravatar_id":"","url":"https://api.github.com/users/scottpurdy","html_url":"https://github.com/scottpurdy","followers_url":"https://api.github.com/users/scottpurdy/followers","following_url":"https://api.github.com/users/scottpurdy/following{/other_user}","gists_url":"https://api.github.com/users/scottpurdy/gists{/gist_id}","starred_url":"https://api.github.com/users/scottpurdy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scottpurdy/subscriptions","organizations_url":"https://api.github.com/users/scottpurdy/orgs","repos_url":"https://api.github.com/users/scottpurdy/repos","events_url":"https://api.github.com/users/scottpurdy/events{/privacy}","received_events_url":"https://api.github.com/users/scottpurdy/received_events","type":"User","site_admin":false},"body":"I'd separate this into an `assertEqual(len(ranges), 1)` and a `self.assertTrue(numpy.array_equal(...`","created_at":"2015-04-03T20:03:41Z","updated_at":"2015-04-03T20:03:41Z","html_url":"https://github.com/numenta/nupic/pull/1975#discussion_r27752092","pull_request_url":"https://api.github.com/repos/numenta/nupic/pulls/1975","_links":{"self":{"href":"https://api.github.com/repos/numenta/nupic/pulls/comments/27752092"},"html":{"href":"https://github.com/numenta/nupic/pull/1975#discussion_r27752092"},"pull_request":{"href":"https://api.github.com/repos/numenta/nupic/pulls/1975"}}},"pull_request":{"url":"https://api.github.com/repos/numenta/nupic/pulls/1975","id":32346167,"html_url":"https://github.com/numenta/nupic/pull/1975","diff_url":"https://github.com/numenta/nupic/pull/1975.diff","patch_url":"https://github.com/numenta/nupic/pull/1975.patch","issue_url":"https://api.github.com/repos/numenta/nupic/issues/1975","number":1975,"state":"open","locked":false,"title":"CategoryEncoder capnproto implementation","user":{"login":"oxtopus","id":326528,"avatar_url":"https://avatars.githubusercontent.com/u/326528?v=3","gravatar_id":"","url":"https://api.github.com/users/oxtopus","html_url":"https://github.com/oxtopus","followers_url":"https://api.github.com/users/oxtopus/followers","following_url":"https://api.github.com/users/oxtopus/following{/other_user}","gists_url":"https://api.github.com/users/oxtopus/gists{/gist_id}","starred_url":"https://api.github.com/users/oxtopus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oxtopus/subscriptions","organizations_url":"https://api.github.com/users/oxtopus/orgs","repos_url":"https://api.github.com/users/oxtopus/repos","events_url":"https://api.github.com/users/oxtopus/events{/privacy}","received_events_url":"https://api.github.com/users/oxtopus/received_events","type":"User","site_admin":false},"body":"Builds off of #1973 and fixes #1964\r\n\r\ncc @scottpurdy ","created_at":"2015-03-31T17:35:26Z","updated_at":"2015-04-03T20:03:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9899c1915cd064ed967ad8bd8e6ec60629ea2985","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/numenta/nupic/pulls/1975/commits","review_comments_url":"https://api.github.com/repos/numenta/nupic/pulls/1975/comments","review_comment_url":"https://api.github.com/repos/numenta/nupic/pulls/comments{/number}","comments_url":"https://api.github.com/repos/numenta/nupic/issues/1975/comments","statuses_url":"https://api.github.com/repos/numenta/nupic/statuses/d4ec2f49709c6354dea954b1cf83c31b1baea3ac","head":{"label":"oxtopus:issue-1964-category-capnp","ref":"issue-1964-category-capnp","sha":"d4ec2f49709c6354dea954b1cf83c31b1baea3ac","user":{"login":"oxtopus","id":326528,"avatar_url":"https://avatars.githubusercontent.com/u/326528?v=3","gravatar_id":"","url":"https://api.github.com/users/oxtopus","html_url":"https://github.com/oxtopus","followers_url":"https://api.github.com/users/oxtopus/followers","following_url":"https://api.github.com/users/oxtopus/following{/other_user}","gists_url":"https://api.github.com/users/oxtopus/gists{/gist_id}","starred_url":"https://api.github.com/users/oxtopus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oxtopus/subscriptions","organizations_url":"https://api.github.com/users/oxtopus/orgs","repos_url":"https://api.github.com/users/oxtopus/repos","events_url":"https://api.github.com/users/oxtopus/events{/privacy}","received_events_url":"https://api.github.com/users/oxtopus/received_events","type":"User","site_admin":false},"repo":{"id":10374081,"name":"nupic","full_name":"oxtopus/nupic","owner":{"login":"oxtopus","id":326528,"avatar_url":"https://avatars.githubusercontent.com/u/326528?v=3","gravatar_id":"","url":"https://api.github.com/users/oxtopus","html_url":"https://github.com/oxtopus","followers_url":"https://api.github.com/users/oxtopus/followers","following_url":"https://api.github.com/users/oxtopus/following{/other_user}","gists_url":"https://api.github.com/users/oxtopus/gists{/gist_id}","starred_url":"https://api.github.com/users/oxtopus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oxtopus/subscriptions","organizations_url":"https://api.github.com/users/oxtopus/orgs","repos_url":"https://api.github.com/users/oxtopus/repos","events_url":"https://api.github.com/users/oxtopus/events{/privacy}","received_events_url":"https://api.github.com/users/oxtopus/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/oxtopus/nupic","description":"","fork":true,"url":"https://api.github.com/repos/oxtopus/nupic","forks_url":"https://api.github.com/repos/oxtopus/nupic/forks","keys_url":"https://api.github.com/repos/oxtopus/nupic/keys{/key_id}","collaborators_url":"https://api.github.com/repos/oxtopus/nupic/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/oxtopus/nupic/teams","hooks_url":"https://api.github.com/repos/oxtopus/nupic/hooks","issue_events_url":"https://api.github.com/repos/oxtopus/nupic/issues/events{/number}","events_url":"https://api.github.com/repos/oxtopus/nupic/events","assignees_url":"https://api.github.com/repos/oxtopus/nupic/assignees{/user}","branches_url":"https://api.github.com/repos/oxtopus/nupic/branches{/branch}","tags_url":"https://api.github.com/repos/oxtopus/nupic/tags","blobs_url":"https://api.github.com/repos/oxtopus/nupic/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/oxtopus/nupic/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/oxtopus/nupic/git/refs{/sha}","trees_url":"https://api.github.com/repos/oxtopus/nupic/git/trees{/sha}","statuses_url":"https://api.github.com/repos/oxtopus/nupic/statuses/{sha}","languages_url":"https://api.github.com/repos/oxtopus/nupic/languages","stargazers_url":"https://api.github.com/repos/oxtopus/nupic/stargazers","contributors_url":"https://api.github.com/repos/oxtopus/nupic/contributors","subscribers_url":"https://api.github.com/repos/oxtopus/nupic/subscribers","subscription_url":"https://api.github.com/repos/oxtopus/nupic/subscription","commits_url":"https://api.github.com/repos/oxtopus/nupic/commits{/sha}","git_commits_url":"https://api.github.com/repos/oxtopus/nupic/git/commits{/sha}","comments_url":"https://api.github.com/repos/oxtopus/nupic/comments{/number}","issue_comment_url":"https://api.github.com/repos/oxtopus/nupic/issues/comments{/number}","contents_url":"https://api.github.com/repos/oxtopus/nupic/contents/{+path}","compare_url":"https://api.github.com/repos/oxtopus/nupic/compare/{base}...{head}","merges_url":"https://api.github.com/repos/oxtopus/nupic/merges","archive_url":"https://api.github.com/repos/oxtopus/nupic/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/oxtopus/nupic/downloads","issues_url":"https://api.github.com/repos/oxtopus/nupic/issues{/number}","pulls_url":"https://api.github.com/repos/oxtopus/nupic/pulls{/number}","milestones_url":"https://api.github.com/repos/oxtopus/nupic/milestones{/number}","notifications_url":"https://api.github.com/repos/oxtopus/nupic/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/oxtopus/nupic/labels{/name}","releases_url":"https://api.github.com/repos/oxtopus/nupic/releases{/id}","created_at":"2013-05-30T02:50:19Z","updated_at":"2015-02-06T16:32:34Z","pushed_at":"2015-04-03T19:58:40Z","git_url":"git://github.com/oxtopus/nupic.git","ssh_url":"git@github.com:oxtopus/nupic.git","clone_url":"https://github.com/oxtopus/nupic.git","svn_url":"https://github.com/oxtopus/nupic","homepage":null,"size":198661,"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":"bfe0e5a9d7717030d415715fc2177828f2f468f4","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":9252533,"name":"nupic","full_name":"numenta/nupic","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","description":"Numenta Platform for Intelligent Computing: a brain-inspired machine intelligence platform, and biologically accurate neural network based on cortical learning algorithms.","fork":false,"url":"https://api.github.com/repos/numenta/nupic","forks_url":"https://api.github.com/repos/numenta/nupic/forks","keys_url":"https://api.github.com/repos/numenta/nupic/keys{/key_id}","collaborators_url":"https://api.github.com/repos/numenta/nupic/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/numenta/nupic/teams","hooks_url":"https://api.github.com/repos/numenta/nupic/hooks","issue_events_url":"https://api.github.com/repos/numenta/nupic/issues/events{/number}","events_url":"https://api.github.com/repos/numenta/nupic/events","assignees_url":"https://api.github.com/repos/numenta/nupic/assignees{/user}","branches_url":"https://api.github.com/repos/numenta/nupic/branches{/branch}","tags_url":"https://api.github.com/repos/numenta/nupic/tags","blobs_url":"https://api.github.com/repos/numenta/nupic/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/numenta/nupic/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/numenta/nupic/git/refs{/sha}","trees_url":"https://api.github.com/repos/numenta/nupic/git/trees{/sha}","statuses_url":"https://api.github.com/repos/numenta/nupic/statuses/{sha}","languages_url":"https://api.github.com/repos/numenta/nupic/languages","stargazers_url":"https://api.github.com/repos/numenta/nupic/stargazers","contributors_url":"https://api.github.com/repos/numenta/nupic/contributors","subscribers_url":"https://api.github.com/repos/numenta/nupic/subscribers","subscription_url":"https://api.github.com/repos/numenta/nupic/subscription","commits_url":"https://api.github.com/repos/numenta/nupic/commits{/sha}","git_commits_url":"https://api.github.com/repos/numenta/nupic/git/commits{/sha}","comments_url":"https://api.github.com/repos/numenta/nupic/comments{/number}","issue_comment_url":"https://api.github.com/repos/numenta/nupic/issues/comments{/number}","contents_url":"https://api.github.com/repos/numenta/nupic/contents/{+path}","compare_url":"https://api.github.com/repos/numenta/nupic/compare/{base}...{head}","merges_url":"https://api.github.com/repos/numenta/nupic/merges","archive_url":"https://api.github.com/repos/numenta/nupic/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/numenta/nupic/downloads","issues_url":"https://api.github.com/repos/numenta/nupic/issues{/number}","pulls_url":"https://api.github.com/repos/numenta/nupic/pulls{/number}","milestones_url":"https://api.github.com/repos/numenta/nupic/milestones{/number}","notifications_url":"https://api.github.com/repos/numenta/nupic/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/numenta/nupic/labels{/name}","releases_url":"https://api.github.com/repos/numenta/nupic/releases{/id}","created_at":"2013-04-05T23:14:27Z","updated_at":"2015-04-03T16:35:09Z","pushed_at":"2015-04-03T19:58:41Z","git_url":"git://github.com/numenta/nupic.git","ssh_url":"git@github.com:numenta/nupic.git","clone_url":"https://github.com/numenta/nupic.git","svn_url":"https://github.com/numenta/nupic","homepage":"http://numenta.org/","size":301738,"stargazers_count":2908,"watchers_count":2908,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":755,"mirror_url":null,"open_issues_count":347,"forks":755,"open_issues":347,"watchers":2908,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/numenta/nupic/pulls/1975"},"html":{"href":"https://github.com/numenta/nupic/pull/1975"},"issue":{"href":"https://api.github.com/repos/numenta/nupic/issues/1975"},"comments":{"href":"https://api.github.com/repos/numenta/nupic/issues/1975/comments"},"review_comments":{"href":"https://api.github.com/repos/numenta/nupic/pulls/1975/comments"},"review_comment":{"href":"https://api.github.com/repos/numenta/nupic/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/numenta/nupic/pulls/1975/commits"},"statuses":{"href":"https://api.github.com/repos/numenta/nupic/statuses/d4ec2f49709c6354dea954b1cf83c31b1baea3ac"}}}}