{"action":"created","comment":{"url":"https://api.github.com/repos/lisa-lab/pylearn2/pulls/comments/26047520","id":26047520,"diff_hunk":"@@ -194,66 +194,124 @@ def test_rgb_yuv():\n     assert isfinite(result)\n \n \n-def test_zca():\n-    \"\"\"\n-    Confirm that ZCA.inv_P_ is the correct inverse of ZCA.P_.\n-    There's a lot else about the ZCA class that could be tested here.\n-    \"\"\"\n-\n-    rng = np.random.RandomState([1, 2, 3])\n-    X = as_floatX(rng.randn(15, 10))\n-    preprocessor = ZCA()\n-    preprocessor.fit(X)\n-\n-    def is_identity(matrix):\n-        identity = np.identity(matrix.shape[0], theano.config.floatX)\n-        abs_difference = np.abs(identity - matrix)\n-        return (abs_difference < .0001).all()\n-\n-    assert preprocessor.P_.shape == (X.shape[1], X.shape[1])\n-    assert not is_identity(preprocessor.P_)\n-    assert is_identity(np.dot(preprocessor.P_, preprocessor.inv_P_))\n+class testZCA:\n \n+    def setup(self):\n+        \"\"\"\n+        We use a small predefined 8x5 matrix for\n+        which we know the ZCA transform.\n+        \"\"\"\n+        self.X = np.array([[-10.0, 3.0, 19.0, 9.0, -15.0],\n+                          [7.0, 26.0, 26.0, 26.0, -3.0],\n+                          [17.0, -17.0, -37.0, -36.0, -11.0],\n+                          [19.0, 15.0, -2.0, 5.0, 9.0],\n+                          [-3.0, -8.0, -35.0, -25.0, -8.0],\n+                          [-18.0, 3.0, 4.0, 15.0, 14.0],\n+                          [5.0, -4.0, -5.0, -7.0, -11.0],\n+                          [23.0, 22.0, 15.0, 20.0, 12.0]])\n+        self.dataset = DenseDesignMatrix(X=as_floatX(self.X),\n+                                         y=as_floatX(np.ones((8, 1))))\n+        self.num_components = self.dataset.get_design_matrix().shape[1] - 1\n \n-def test_zca_inverse():\n-    \"\"\"\n-    Calculates the inverse of X with numpy.linalg.inv if inv_P_ is not stored\n-    \"\"\"\n-\n-    def test(store_inverse):\n-        rng = np.random.RandomState([1, 2, 3])\n-        X = as_floatX(rng.randn(15, 10))\n-        preprocessed_X = copy.copy(X)\n-        preprocessor = ZCA(store_inverse=store_inverse)\n+    def is_almost_equal(self, A, B, epsilon=1e-4):\n+        abs_difference = np.abs(A - B)\n+        return (abs_difference < epsilon).all()\n \n-        dataset = DenseDesignMatrix(X=preprocessed_X,\n+    def get_preprocessed_data(self, preprocessor):\n+        X = copy.copy(self.X)\n+        dataset = DenseDesignMatrix(X=X,\n                                     preprocessor=preprocessor,\n                                     fit_preprocessor=True)\n+        return dataset.get_design_matrix()\n \n-        preprocessed_X = dataset.get_design_matrix()\n+    def test_zca(self):\n+        \"\"\"\n+        Confirm that ZCA.inv_P_ is the correct inverse of ZCA.P_.\n+        There's a lot else about the ZCA class that could be tested here.\n+        \"\"\"\n+        preprocessor = ZCA()\n+        preprocessor.fit(self.X)\n+\n+        identity = np.identity(self.X.shape[1], theano.config.floatX)\n+        # Check some basics of transformation matrix\n+        assert preprocessor.P_.shape == (self.X.shape[1], self.X.shape[1])\n+        assert self.is_almost_equal(np.dot(preprocessor.P_,\n+                                           preprocessor.inv_P_), identity)\n+\n+        preprocessor = ZCA(filter_bias=0.0)\n+        preprocessed_X = self.get_preprocessed_data(preprocessor)\n+\n+        #Check if preprocessed data matrix is white\n+        assert self.is_almost_equal(np.cov(preprocessed_X.transpose(),\n+                                           bias=1), identity)\n+\n+        #Check if we obtain correct solution","path":"pylearn2/datasets/tests/test_preprocessing.py","position":86,"original_position":86,"commit_id":"bb4729d8137e1b173e18a4bf1aede6a102a698af","original_commit_id":"bb4729d8137e1b173e18a4bf1aede6a102a698af","user":{"login":"dwf","id":60206,"avatar_url":"https://avatars.githubusercontent.com/u/60206?v=3","gravatar_id":"","url":"https://api.github.com/users/dwf","html_url":"https://github.com/dwf","followers_url":"https://api.github.com/users/dwf/followers","following_url":"https://api.github.com/users/dwf/following{/other_user}","gists_url":"https://api.github.com/users/dwf/gists{/gist_id}","starred_url":"https://api.github.com/users/dwf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dwf/subscriptions","organizations_url":"https://api.github.com/users/dwf/orgs","repos_url":"https://api.github.com/users/dwf/repos","events_url":"https://api.github.com/users/dwf/events{/privacy}","received_events_url":"https://api.github.com/users/dwf/received_events","type":"User","site_admin":false},"body":"Lines 244 and 248 here are causing the build to fail (style guide says \"#\" has to have a space after it.)","created_at":"2015-03-09T15:52:23Z","updated_at":"2015-03-09T15:52:23Z","html_url":"https://github.com/lisa-lab/pylearn2/pull/1422#discussion_r26047520","pull_request_url":"https://api.github.com/repos/lisa-lab/pylearn2/pulls/1422","_links":{"self":{"href":"https://api.github.com/repos/lisa-lab/pylearn2/pulls/comments/26047520"},"html":{"href":"https://github.com/lisa-lab/pylearn2/pull/1422#discussion_r26047520"},"pull_request":{"href":"https://api.github.com/repos/lisa-lab/pylearn2/pulls/1422"}}},"pull_request":{"url":"https://api.github.com/repos/lisa-lab/pylearn2/pulls/1422","id":30333199,"html_url":"https://github.com/lisa-lab/pylearn2/pull/1422","diff_url":"https://github.com/lisa-lab/pylearn2/pull/1422.diff","patch_url":"https://github.com/lisa-lab/pylearn2/pull/1422.patch","issue_url":"https://api.github.com/repos/lisa-lab/pylearn2/issues/1422","number":1422,"state":"open","locked":false,"title":"Fixed ZCA n_components, and added tests","user":{"login":"harmdevries89","id":8825215,"avatar_url":"https://avatars.githubusercontent.com/u/8825215?v=3","gravatar_id":"","url":"https://api.github.com/users/harmdevries89","html_url":"https://github.com/harmdevries89","followers_url":"https://api.github.com/users/harmdevries89/followers","following_url":"https://api.github.com/users/harmdevries89/following{/other_user}","gists_url":"https://api.github.com/users/harmdevries89/gists{/gist_id}","starred_url":"https://api.github.com/users/harmdevries89/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/harmdevries89/subscriptions","organizations_url":"https://api.github.com/users/harmdevries89/orgs","repos_url":"https://api.github.com/users/harmdevries89/repos","events_url":"https://api.github.com/users/harmdevries89/events{/privacy}","received_events_url":"https://api.github.com/users/harmdevries89/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-03-02T23:47:34Z","updated_at":"2015-03-09T15:52:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b6249a347d69bfd68eed237a0eff15a4dc8b5f7c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/lisa-lab/pylearn2/pulls/1422/commits","review_comments_url":"https://api.github.com/repos/lisa-lab/pylearn2/pulls/1422/comments","review_comment_url":"https://api.github.com/repos/lisa-lab/pylearn2/pulls/comments{/number}","comments_url":"https://api.github.com/repos/lisa-lab/pylearn2/issues/1422/comments","statuses_url":"https://api.github.com/repos/lisa-lab/pylearn2/statuses/bb4729d8137e1b173e18a4bf1aede6a102a698af","head":{"label":"harmdevries89:zca","ref":"zca","sha":"bb4729d8137e1b173e18a4bf1aede6a102a698af","user":{"login":"harmdevries89","id":8825215,"avatar_url":"https://avatars.githubusercontent.com/u/8825215?v=3","gravatar_id":"","url":"https://api.github.com/users/harmdevries89","html_url":"https://github.com/harmdevries89","followers_url":"https://api.github.com/users/harmdevries89/followers","following_url":"https://api.github.com/users/harmdevries89/following{/other_user}","gists_url":"https://api.github.com/users/harmdevries89/gists{/gist_id}","starred_url":"https://api.github.com/users/harmdevries89/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/harmdevries89/subscriptions","organizations_url":"https://api.github.com/users/harmdevries89/orgs","repos_url":"https://api.github.com/users/harmdevries89/repos","events_url":"https://api.github.com/users/harmdevries89/events{/privacy}","received_events_url":"https://api.github.com/users/harmdevries89/received_events","type":"User","site_admin":false},"repo":{"id":25374117,"name":"pylearn2","full_name":"harmdevries89/pylearn2","owner":{"login":"harmdevries89","id":8825215,"avatar_url":"https://avatars.githubusercontent.com/u/8825215?v=3","gravatar_id":"","url":"https://api.github.com/users/harmdevries89","html_url":"https://github.com/harmdevries89","followers_url":"https://api.github.com/users/harmdevries89/followers","following_url":"https://api.github.com/users/harmdevries89/following{/other_user}","gists_url":"https://api.github.com/users/harmdevries89/gists{/gist_id}","starred_url":"https://api.github.com/users/harmdevries89/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/harmdevries89/subscriptions","organizations_url":"https://api.github.com/users/harmdevries89/orgs","repos_url":"https://api.github.com/users/harmdevries89/repos","events_url":"https://api.github.com/users/harmdevries89/events{/privacy}","received_events_url":"https://api.github.com/users/harmdevries89/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/harmdevries89/pylearn2","description":"A Machine Learning library based on Theano","fork":true,"url":"https://api.github.com/repos/harmdevries89/pylearn2","forks_url":"https://api.github.com/repos/harmdevries89/pylearn2/forks","keys_url":"https://api.github.com/repos/harmdevries89/pylearn2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/harmdevries89/pylearn2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/harmdevries89/pylearn2/teams","hooks_url":"https://api.github.com/repos/harmdevries89/pylearn2/hooks","issue_events_url":"https://api.github.com/repos/harmdevries89/pylearn2/issues/events{/number}","events_url":"https://api.github.com/repos/harmdevries89/pylearn2/events","assignees_url":"https://api.github.com/repos/harmdevries89/pylearn2/assignees{/user}","branches_url":"https://api.github.com/repos/harmdevries89/pylearn2/branches{/branch}","tags_url":"https://api.github.com/repos/harmdevries89/pylearn2/tags","blobs_url":"https://api.github.com/repos/harmdevries89/pylearn2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/harmdevries89/pylearn2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/harmdevries89/pylearn2/git/refs{/sha}","trees_url":"https://api.github.com/repos/harmdevries89/pylearn2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/harmdevries89/pylearn2/statuses/{sha}","languages_url":"https://api.github.com/repos/harmdevries89/pylearn2/languages","stargazers_url":"https://api.github.com/repos/harmdevries89/pylearn2/stargazers","contributors_url":"https://api.github.com/repos/harmdevries89/pylearn2/contributors","subscribers_url":"https://api.github.com/repos/harmdevries89/pylearn2/subscribers","subscription_url":"https://api.github.com/repos/harmdevries89/pylearn2/subscription","commits_url":"https://api.github.com/repos/harmdevries89/pylearn2/commits{/sha}","git_commits_url":"https://api.github.com/repos/harmdevries89/pylearn2/git/commits{/sha}","comments_url":"https://api.github.com/repos/harmdevries89/pylearn2/comments{/number}","issue_comment_url":"https://api.github.com/repos/harmdevries89/pylearn2/issues/comments{/number}","contents_url":"https://api.github.com/repos/harmdevries89/pylearn2/contents/{+path}","compare_url":"https://api.github.com/repos/harmdevries89/pylearn2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/harmdevries89/pylearn2/merges","archive_url":"https://api.github.com/repos/harmdevries89/pylearn2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/harmdevries89/pylearn2/downloads","issues_url":"https://api.github.com/repos/harmdevries89/pylearn2/issues{/number}","pulls_url":"https://api.github.com/repos/harmdevries89/pylearn2/pulls{/number}","milestones_url":"https://api.github.com/repos/harmdevries89/pylearn2/milestones{/number}","notifications_url":"https://api.github.com/repos/harmdevries89/pylearn2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/harmdevries89/pylearn2/labels{/name}","releases_url":"https://api.github.com/repos/harmdevries89/pylearn2/releases{/id}","created_at":"2014-10-17T19:39:53Z","updated_at":"2014-10-17T18:48:10Z","pushed_at":"2015-03-03T13:37:18Z","git_url":"git://github.com/harmdevries89/pylearn2.git","ssh_url":"git@github.com:harmdevries89/pylearn2.git","clone_url":"https://github.com/harmdevries89/pylearn2.git","svn_url":"https://github.com/harmdevries89/pylearn2","homepage":"","size":12023,"stargazers_count":0,"watchers_count":0,"language":null,"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":"lisa-lab:master","ref":"master","sha":"468b372f294aab36114fb26d4c2f7f495a10cb13","user":{"login":"lisa-lab","id":178109,"avatar_url":"https://avatars.githubusercontent.com/u/178109?v=3","gravatar_id":"","url":"https://api.github.com/users/lisa-lab","html_url":"https://github.com/lisa-lab","followers_url":"https://api.github.com/users/lisa-lab/followers","following_url":"https://api.github.com/users/lisa-lab/following{/other_user}","gists_url":"https://api.github.com/users/lisa-lab/gists{/gist_id}","starred_url":"https://api.github.com/users/lisa-lab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lisa-lab/subscriptions","organizations_url":"https://api.github.com/users/lisa-lab/orgs","repos_url":"https://api.github.com/users/lisa-lab/repos","events_url":"https://api.github.com/users/lisa-lab/events{/privacy}","received_events_url":"https://api.github.com/users/lisa-lab/received_events","type":"Organization","site_admin":false},"repo":{"id":1103054,"name":"pylearn2","full_name":"lisa-lab/pylearn2","owner":{"login":"lisa-lab","id":178109,"avatar_url":"https://avatars.githubusercontent.com/u/178109?v=3","gravatar_id":"","url":"https://api.github.com/users/lisa-lab","html_url":"https://github.com/lisa-lab","followers_url":"https://api.github.com/users/lisa-lab/followers","following_url":"https://api.github.com/users/lisa-lab/following{/other_user}","gists_url":"https://api.github.com/users/lisa-lab/gists{/gist_id}","starred_url":"https://api.github.com/users/lisa-lab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lisa-lab/subscriptions","organizations_url":"https://api.github.com/users/lisa-lab/orgs","repos_url":"https://api.github.com/users/lisa-lab/repos","events_url":"https://api.github.com/users/lisa-lab/events{/privacy}","received_events_url":"https://api.github.com/users/lisa-lab/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/lisa-lab/pylearn2","description":"A Machine Learning library based on Theano","fork":false,"url":"https://api.github.com/repos/lisa-lab/pylearn2","forks_url":"https://api.github.com/repos/lisa-lab/pylearn2/forks","keys_url":"https://api.github.com/repos/lisa-lab/pylearn2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lisa-lab/pylearn2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lisa-lab/pylearn2/teams","hooks_url":"https://api.github.com/repos/lisa-lab/pylearn2/hooks","issue_events_url":"https://api.github.com/repos/lisa-lab/pylearn2/issues/events{/number}","events_url":"https://api.github.com/repos/lisa-lab/pylearn2/events","assignees_url":"https://api.github.com/repos/lisa-lab/pylearn2/assignees{/user}","branches_url":"https://api.github.com/repos/lisa-lab/pylearn2/branches{/branch}","tags_url":"https://api.github.com/repos/lisa-lab/pylearn2/tags","blobs_url":"https://api.github.com/repos/lisa-lab/pylearn2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lisa-lab/pylearn2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lisa-lab/pylearn2/git/refs{/sha}","trees_url":"https://api.github.com/repos/lisa-lab/pylearn2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lisa-lab/pylearn2/statuses/{sha}","languages_url":"https://api.github.com/repos/lisa-lab/pylearn2/languages","stargazers_url":"https://api.github.com/repos/lisa-lab/pylearn2/stargazers","contributors_url":"https://api.github.com/repos/lisa-lab/pylearn2/contributors","subscribers_url":"https://api.github.com/repos/lisa-lab/pylearn2/subscribers","subscription_url":"https://api.github.com/repos/lisa-lab/pylearn2/subscription","commits_url":"https://api.github.com/repos/lisa-lab/pylearn2/commits{/sha}","git_commits_url":"https://api.github.com/repos/lisa-lab/pylearn2/git/commits{/sha}","comments_url":"https://api.github.com/repos/lisa-lab/pylearn2/comments{/number}","issue_comment_url":"https://api.github.com/repos/lisa-lab/pylearn2/issues/comments{/number}","contents_url":"https://api.github.com/repos/lisa-lab/pylearn2/contents/{+path}","compare_url":"https://api.github.com/repos/lisa-lab/pylearn2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lisa-lab/pylearn2/merges","archive_url":"https://api.github.com/repos/lisa-lab/pylearn2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lisa-lab/pylearn2/downloads","issues_url":"https://api.github.com/repos/lisa-lab/pylearn2/issues{/number}","pulls_url":"https://api.github.com/repos/lisa-lab/pylearn2/pulls{/number}","milestones_url":"https://api.github.com/repos/lisa-lab/pylearn2/milestones{/number}","notifications_url":"https://api.github.com/repos/lisa-lab/pylearn2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lisa-lab/pylearn2/labels{/name}","releases_url":"https://api.github.com/repos/lisa-lab/pylearn2/releases{/id}","created_at":"2010-11-22T18:00:50Z","updated_at":"2015-03-09T15:23:25Z","pushed_at":"2015-03-04T18:43:48Z","git_url":"git://github.com/lisa-lab/pylearn2.git","ssh_url":"git@github.com:lisa-lab/pylearn2.git","clone_url":"https://github.com/lisa-lab/pylearn2.git","svn_url":"https://github.com/lisa-lab/pylearn2","homepage":"","size":690921,"stargazers_count":1294,"watchers_count":1294,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":525,"mirror_url":null,"open_issues_count":175,"forks":525,"open_issues":175,"watchers":1294,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/lisa-lab/pylearn2/pulls/1422"},"html":{"href":"https://github.com/lisa-lab/pylearn2/pull/1422"},"issue":{"href":"https://api.github.com/repos/lisa-lab/pylearn2/issues/1422"},"comments":{"href":"https://api.github.com/repos/lisa-lab/pylearn2/issues/1422/comments"},"review_comments":{"href":"https://api.github.com/repos/lisa-lab/pylearn2/pulls/1422/comments"},"review_comment":{"href":"https://api.github.com/repos/lisa-lab/pylearn2/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/lisa-lab/pylearn2/pulls/1422/commits"},"statuses":{"href":"https://api.github.com/repos/lisa-lab/pylearn2/statuses/bb4729d8137e1b173e18a4bf1aede6a102a698af"}}}}