{"action":"created","comment":{"url":"https://api.github.com/repos/IntelPNI/brainiak/pulls/comments/79326410","id":79326410,"diff_hunk":"@@ -100,3 +102,127 @@ def fast_inv(a):\n     except np.linalg.linalg.LinAlgError:\n         logging.exception('Error from np.linalg.solve')\n         raise\n+\n+\n+def cov2corr(cov):\n+    \"\"\"Calculate the correlation matrix based on a\n+        covariance matrix\n+\n+    Parameters\n+    ----------\n+\n+    cov: 2D array\n+\n+    Returns\n+    -------\n+\n+    corr: 2D array\n+        correlation converted from the covarince matrix\n+\n+\n+    \"\"\"\n+    assert cov.ndim == 2, 'covariance matrix should be 2D array'\n+    inv_sd = 1 / np.sqrt(np.diag(cov))\n+    corr = cov * np.outer(inv_sd, inv_sd)\n+    return corr\n+\n+\n+class read_design:\n+    \"\"\" A class which has the ability of reading in design matrix in .1D file,\n+        generated by AFNI's 3dDeconvolve.\n+    \"\"\"\n+    def __init__(self, fname=None, include_orth=False, include_pols=False):\n+        if fname is None:\n+            # fname is the name of the file to read in the design matrix\n+            self.design = np.zeros([0, 0])\n+            self.n_col = 0\n+            # number of columns (conditions) in the design matrix\n+            self.column_types = np.ones(0)\n+            self.n_basis = 0\n+            self.n_stim = 0\n+            self.n_orth = 0\n+            self.StimLabels = []\n+        else:\n+            isAFNI = re.match(r'.+[.](1D|1d|txt)$', fname)\n+            # We assume all AFNI 1D files have extension of 1D or 1d or txt\n+            if isAFNI:\n+                self.readAFNI(fname=fname)\n+\n+        self.include_orth = include_orth\n+        self.include_pols = include_pols\n+        self.cols_used = np.where(self.column_types == 1)[0]\n+        if self.include_orth:\n+            self.cols_used = np.sort(\n+                np.append(self.cols_used, np.where(self.column_types == 0)[0]))\n+        if self.include_pols:\n+            self.cols_used = np.sort(np.append(\n+                self.cols_used, np.where(self.column_types == -1)[0]))\n+        self.design_used = self.design[:, self.cols_used]\n+        if not self.include_pols:\n+            # baseline is not included, then we add a column of all 1's\n+            self.design_used = np.insert(self.design_used, 0, 1, axis=1)\n+        self.n_TR = np.size(self.design_used, axis=0)\n+\n+    def readAFNI(self, fname):\n+        # Read design file written by AFNI\n+        self.n_basis = 0\n+        self.n_stim = 0\n+        self.n_orth = 0\n+        self.StimLabels = []\n+        self.design = np.loadtxt(fname, ndmin=2)\n+        with open(fname) as f:\n+            all_text = f.read()\n+\n+        find_n_column = re.compile(","path":"brainiak/utils/utils.py","position":106,"original_position":106,"commit_id":"890dc152ead814345bab889ae684ab5b1302ae5a","original_commit_id":"890dc152ead814345bab889ae684ab5b1302ae5a","user":{"login":"lcnature","id":7763789,"avatar_url":"https://avatars.githubusercontent.com/u/7763789?v=3","gravatar_id":"","url":"https://api.github.com/users/lcnature","html_url":"https://github.com/lcnature","followers_url":"https://api.github.com/users/lcnature/followers","following_url":"https://api.github.com/users/lcnature/following{/other_user}","gists_url":"https://api.github.com/users/lcnature/gists{/gist_id}","starred_url":"https://api.github.com/users/lcnature/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lcnature/subscriptions","organizations_url":"https://api.github.com/users/lcnature/orgs","repos_url":"https://api.github.com/users/lcnature/repos","events_url":"https://api.github.com/users/lcnature/events{/privacy}","received_events_url":"https://api.github.com/users/lcnature/received_events","type":"User","site_admin":false},"body":"Actually I realized that there is a checking a few lines below, for whether the number of conditions read from the header matches the number of columns.","created_at":"2016-09-19T04:14:33Z","updated_at":"2016-09-19T04:14:33Z","html_url":"https://github.com/IntelPNI/brainiak/pull/98#discussion_r79326410","pull_request_url":"https://api.github.com/repos/IntelPNI/brainiak/pulls/98","_links":{"self":{"href":"https://api.github.com/repos/IntelPNI/brainiak/pulls/comments/79326410"},"html":{"href":"https://github.com/IntelPNI/brainiak/pull/98#discussion_r79326410"},"pull_request":{"href":"https://api.github.com/repos/IntelPNI/brainiak/pulls/98"}}},"pull_request":{"url":"https://api.github.com/repos/IntelPNI/brainiak/pulls/98","id":84392653,"html_url":"https://github.com/IntelPNI/brainiak/pull/98","diff_url":"https://github.com/IntelPNI/brainiak/pull/98.diff","patch_url":"https://github.com/IntelPNI/brainiak/pull/98.patch","issue_url":"https://api.github.com/repos/IntelPNI/brainiak/issues/98","number":98,"state":"open","locked":false,"title":"Add Bayesian RSA to the package (reprsimil)","user":{"login":"lcnature","id":7763789,"avatar_url":"https://avatars.githubusercontent.com/u/7763789?v=3","gravatar_id":"","url":"https://api.github.com/users/lcnature","html_url":"https://github.com/lcnature","followers_url":"https://api.github.com/users/lcnature/followers","following_url":"https://api.github.com/users/lcnature/following{/other_user}","gists_url":"https://api.github.com/users/lcnature/gists{/gist_id}","starred_url":"https://api.github.com/users/lcnature/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lcnature/subscriptions","organizations_url":"https://api.github.com/users/lcnature/orgs","repos_url":"https://api.github.com/users/lcnature/repos","events_url":"https://api.github.com/users/lcnature/events{/privacy}","received_events_url":"https://api.github.com/users/lcnature/received_events","type":"User","site_admin":false},"body":"Bayesian RSA stands for Bayesian representational similarity analysis.\r\nThe code should be functional.\r\nPlanned updates for the upcoming weeks:\r\n(1) add an example as a python notebook\r\n(2) upload supplementary file including the derivation of the gradient of log likelihood\r\n(3) capability of modeling the spatial correlation of noise","created_at":"2016-09-07T23:43:25Z","updated_at":"2016-09-19T04:14:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c1cf772f78eebe4a8d55972e154b38d5402e46db","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/IntelPNI/brainiak/pulls/98/commits","review_comments_url":"https://api.github.com/repos/IntelPNI/brainiak/pulls/98/comments","review_comment_url":"https://api.github.com/repos/IntelPNI/brainiak/pulls/comments{/number}","comments_url":"https://api.github.com/repos/IntelPNI/brainiak/issues/98/comments","statuses_url":"https://api.github.com/repos/IntelPNI/brainiak/statuses/890dc152ead814345bab889ae684ab5b1302ae5a","head":{"label":"lcnature:add_brsa","ref":"add_brsa","sha":"890dc152ead814345bab889ae684ab5b1302ae5a","user":{"login":"lcnature","id":7763789,"avatar_url":"https://avatars.githubusercontent.com/u/7763789?v=3","gravatar_id":"","url":"https://api.github.com/users/lcnature","html_url":"https://github.com/lcnature","followers_url":"https://api.github.com/users/lcnature/followers","following_url":"https://api.github.com/users/lcnature/following{/other_user}","gists_url":"https://api.github.com/users/lcnature/gists{/gist_id}","starred_url":"https://api.github.com/users/lcnature/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lcnature/subscriptions","organizations_url":"https://api.github.com/users/lcnature/orgs","repos_url":"https://api.github.com/users/lcnature/repos","events_url":"https://api.github.com/users/lcnature/events{/privacy}","received_events_url":"https://api.github.com/users/lcnature/received_events","type":"User","site_admin":false},"repo":{"id":67227187,"name":"brainiak","full_name":"lcnature/brainiak","owner":{"login":"lcnature","id":7763789,"avatar_url":"https://avatars.githubusercontent.com/u/7763789?v=3","gravatar_id":"","url":"https://api.github.com/users/lcnature","html_url":"https://github.com/lcnature","followers_url":"https://api.github.com/users/lcnature/followers","following_url":"https://api.github.com/users/lcnature/following{/other_user}","gists_url":"https://api.github.com/users/lcnature/gists{/gist_id}","starred_url":"https://api.github.com/users/lcnature/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lcnature/subscriptions","organizations_url":"https://api.github.com/users/lcnature/orgs","repos_url":"https://api.github.com/users/lcnature/repos","events_url":"https://api.github.com/users/lcnature/events{/privacy}","received_events_url":"https://api.github.com/users/lcnature/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/lcnature/brainiak","description":"Brain Imaging Analysis Kit","fork":true,"url":"https://api.github.com/repos/lcnature/brainiak","forks_url":"https://api.github.com/repos/lcnature/brainiak/forks","keys_url":"https://api.github.com/repos/lcnature/brainiak/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lcnature/brainiak/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lcnature/brainiak/teams","hooks_url":"https://api.github.com/repos/lcnature/brainiak/hooks","issue_events_url":"https://api.github.com/repos/lcnature/brainiak/issues/events{/number}","events_url":"https://api.github.com/repos/lcnature/brainiak/events","assignees_url":"https://api.github.com/repos/lcnature/brainiak/assignees{/user}","branches_url":"https://api.github.com/repos/lcnature/brainiak/branches{/branch}","tags_url":"https://api.github.com/repos/lcnature/brainiak/tags","blobs_url":"https://api.github.com/repos/lcnature/brainiak/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lcnature/brainiak/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lcnature/brainiak/git/refs{/sha}","trees_url":"https://api.github.com/repos/lcnature/brainiak/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lcnature/brainiak/statuses/{sha}","languages_url":"https://api.github.com/repos/lcnature/brainiak/languages","stargazers_url":"https://api.github.com/repos/lcnature/brainiak/stargazers","contributors_url":"https://api.github.com/repos/lcnature/brainiak/contributors","subscribers_url":"https://api.github.com/repos/lcnature/brainiak/subscribers","subscription_url":"https://api.github.com/repos/lcnature/brainiak/subscription","commits_url":"https://api.github.com/repos/lcnature/brainiak/commits{/sha}","git_commits_url":"https://api.github.com/repos/lcnature/brainiak/git/commits{/sha}","comments_url":"https://api.github.com/repos/lcnature/brainiak/comments{/number}","issue_comment_url":"https://api.github.com/repos/lcnature/brainiak/issues/comments{/number}","contents_url":"https://api.github.com/repos/lcnature/brainiak/contents/{+path}","compare_url":"https://api.github.com/repos/lcnature/brainiak/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lcnature/brainiak/merges","archive_url":"https://api.github.com/repos/lcnature/brainiak/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lcnature/brainiak/downloads","issues_url":"https://api.github.com/repos/lcnature/brainiak/issues{/number}","pulls_url":"https://api.github.com/repos/lcnature/brainiak/pulls{/number}","milestones_url":"https://api.github.com/repos/lcnature/brainiak/milestones{/number}","notifications_url":"https://api.github.com/repos/lcnature/brainiak/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lcnature/brainiak/labels{/name}","releases_url":"https://api.github.com/repos/lcnature/brainiak/releases{/id}","deployments_url":"https://api.github.com/repos/lcnature/brainiak/deployments","created_at":"2016-09-02T14:00:49Z","updated_at":"2016-09-02T14:00:50Z","pushed_at":"2016-09-16T00:26:05Z","git_url":"git://github.com/lcnature/brainiak.git","ssh_url":"git@github.com:lcnature/brainiak.git","clone_url":"https://github.com/lcnature/brainiak.git","svn_url":"https://github.com/lcnature/brainiak","homepage":"","size":250,"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":"IntelPNI:master","ref":"master","sha":"97b734ad651c5785cfe618fe9f1ff58b5baa5326","user":{"login":"IntelPNI","id":10767488,"avatar_url":"https://avatars.githubusercontent.com/u/10767488?v=3","gravatar_id":"","url":"https://api.github.com/users/IntelPNI","html_url":"https://github.com/IntelPNI","followers_url":"https://api.github.com/users/IntelPNI/followers","following_url":"https://api.github.com/users/IntelPNI/following{/other_user}","gists_url":"https://api.github.com/users/IntelPNI/gists{/gist_id}","starred_url":"https://api.github.com/users/IntelPNI/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IntelPNI/subscriptions","organizations_url":"https://api.github.com/users/IntelPNI/orgs","repos_url":"https://api.github.com/users/IntelPNI/repos","events_url":"https://api.github.com/users/IntelPNI/events{/privacy}","received_events_url":"https://api.github.com/users/IntelPNI/received_events","type":"Organization","site_admin":false},"repo":{"id":51334498,"name":"brainiak","full_name":"IntelPNI/brainiak","owner":{"login":"IntelPNI","id":10767488,"avatar_url":"https://avatars.githubusercontent.com/u/10767488?v=3","gravatar_id":"","url":"https://api.github.com/users/IntelPNI","html_url":"https://github.com/IntelPNI","followers_url":"https://api.github.com/users/IntelPNI/followers","following_url":"https://api.github.com/users/IntelPNI/following{/other_user}","gists_url":"https://api.github.com/users/IntelPNI/gists{/gist_id}","starred_url":"https://api.github.com/users/IntelPNI/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IntelPNI/subscriptions","organizations_url":"https://api.github.com/users/IntelPNI/orgs","repos_url":"https://api.github.com/users/IntelPNI/repos","events_url":"https://api.github.com/users/IntelPNI/events{/privacy}","received_events_url":"https://api.github.com/users/IntelPNI/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/IntelPNI/brainiak","description":"Brain Imaging Analysis Kit","fork":false,"url":"https://api.github.com/repos/IntelPNI/brainiak","forks_url":"https://api.github.com/repos/IntelPNI/brainiak/forks","keys_url":"https://api.github.com/repos/IntelPNI/brainiak/keys{/key_id}","collaborators_url":"https://api.github.com/repos/IntelPNI/brainiak/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/IntelPNI/brainiak/teams","hooks_url":"https://api.github.com/repos/IntelPNI/brainiak/hooks","issue_events_url":"https://api.github.com/repos/IntelPNI/brainiak/issues/events{/number}","events_url":"https://api.github.com/repos/IntelPNI/brainiak/events","assignees_url":"https://api.github.com/repos/IntelPNI/brainiak/assignees{/user}","branches_url":"https://api.github.com/repos/IntelPNI/brainiak/branches{/branch}","tags_url":"https://api.github.com/repos/IntelPNI/brainiak/tags","blobs_url":"https://api.github.com/repos/IntelPNI/brainiak/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/IntelPNI/brainiak/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/IntelPNI/brainiak/git/refs{/sha}","trees_url":"https://api.github.com/repos/IntelPNI/brainiak/git/trees{/sha}","statuses_url":"https://api.github.com/repos/IntelPNI/brainiak/statuses/{sha}","languages_url":"https://api.github.com/repos/IntelPNI/brainiak/languages","stargazers_url":"https://api.github.com/repos/IntelPNI/brainiak/stargazers","contributors_url":"https://api.github.com/repos/IntelPNI/brainiak/contributors","subscribers_url":"https://api.github.com/repos/IntelPNI/brainiak/subscribers","subscription_url":"https://api.github.com/repos/IntelPNI/brainiak/subscription","commits_url":"https://api.github.com/repos/IntelPNI/brainiak/commits{/sha}","git_commits_url":"https://api.github.com/repos/IntelPNI/brainiak/git/commits{/sha}","comments_url":"https://api.github.com/repos/IntelPNI/brainiak/comments{/number}","issue_comment_url":"https://api.github.com/repos/IntelPNI/brainiak/issues/comments{/number}","contents_url":"https://api.github.com/repos/IntelPNI/brainiak/contents/{+path}","compare_url":"https://api.github.com/repos/IntelPNI/brainiak/compare/{base}...{head}","merges_url":"https://api.github.com/repos/IntelPNI/brainiak/merges","archive_url":"https://api.github.com/repos/IntelPNI/brainiak/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/IntelPNI/brainiak/downloads","issues_url":"https://api.github.com/repos/IntelPNI/brainiak/issues{/number}","pulls_url":"https://api.github.com/repos/IntelPNI/brainiak/pulls{/number}","milestones_url":"https://api.github.com/repos/IntelPNI/brainiak/milestones{/number}","notifications_url":"https://api.github.com/repos/IntelPNI/brainiak/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/IntelPNI/brainiak/labels{/name}","releases_url":"https://api.github.com/repos/IntelPNI/brainiak/releases{/id}","deployments_url":"https://api.github.com/repos/IntelPNI/brainiak/deployments","created_at":"2016-02-08T23:19:27Z","updated_at":"2016-08-29T18:32:02Z","pushed_at":"2016-09-17T05:04:18Z","git_url":"git://github.com/IntelPNI/brainiak.git","ssh_url":"git@github.com:IntelPNI/brainiak.git","clone_url":"https://github.com/IntelPNI/brainiak.git","svn_url":"https://github.com/IntelPNI/brainiak","homepage":"","size":458,"stargazers_count":8,"watchers_count":8,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":23,"mirror_url":null,"open_issues_count":25,"forks":23,"open_issues":25,"watchers":8,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/IntelPNI/brainiak/pulls/98"},"html":{"href":"https://github.com/IntelPNI/brainiak/pull/98"},"issue":{"href":"https://api.github.com/repos/IntelPNI/brainiak/issues/98"},"comments":{"href":"https://api.github.com/repos/IntelPNI/brainiak/issues/98/comments"},"review_comments":{"href":"https://api.github.com/repos/IntelPNI/brainiak/pulls/98/comments"},"review_comment":{"href":"https://api.github.com/repos/IntelPNI/brainiak/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/IntelPNI/brainiak/pulls/98/commits"},"statuses":{"href":"https://api.github.com/repos/IntelPNI/brainiak/statuses/890dc152ead814345bab889ae684ab5b1302ae5a"}}}}
{"actor":{"display_login":"lcnature"}}