{"action":"created","comment":{"url":"https://api.github.com/repos/mvdoc/reprclust/pulls/comments/33977495","id":33977495,"diff_hunk":"@@ -0,0 +1,212 @@\n+# -*- coding: utf-8 -*-\n+### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##\n+#\n+#   See COPYING file distributed along with the module for the\n+#   copyright and license terms.\n+#\n+### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##\n+\"\"\"\n+Module to compute stability estimates of clustering solutions using a method\n+inspired by Lange et al. (2004), and Yeo et al. (2011). The procedure\n+cross-validates across subjects in the following way: the datasets are divided\n+into training and test set; clustering is performed on the training set, and\n+the solution is predicted on the test set. Then, the clustering solution is\n+computed on the test set, and this is compared to the predicted one using the\n+Adjusted Rand Index, the Adjusted Mutual Information, and the Instability Score\n+(Lange et. al, 2004) as metrics. Clustering solutions are swept from k=2 to a\n+maximum k defined by the user.\n+\n+At the moment the following clustering algorithms are implemented:\n+    - k-means\n+    - Gaussian Mixture Models\n+    - Ward Clustering (structured and unstructured)\n+    - complete linkage with correlation distance\n+\n+References:\n+-----------\n+Lange, T., Roth, V., Braun, M. and Buhmann J. (2004)\n+\"Stability-based validation of clustering solutions.\"\n+Neural computation 16, no. 6 (2004): 1299-1323.\n+\n+Thomas Yeo, B. T., Krienen, F. M., Sepulcre, J., Sabuncu, M. R., Lashkari, D.,\n+Hollinshead, M., et al. (2011).\n+\"The organization of the human cerebral cortex estimated by intrinsic\n+functional connectivity.\"\n+Journal of Neurophysiology, 106(3), 1125–1165. doi:10.1152/jn.00338.2011\n+\"\"\"\n+import copy\n+\n+from joblib import Parallel, delayed\n+\n+import numpy as np\n+\n+from reprclust.cluster_methods import ClusterMethod\n+from reprclust.cluster_metrics import ari, ami\n+\n+# this must be outside the class to allow parallelization\n+def _run_fold(self, train, test):\n+    \"\"\"Run reproducibility algorithm on one fold for all the ks\"\"\"\n+    # initialize methods\n+    cm_train = self._cluster_method\n+    # copy the method for the testing part too\n+    # XXX: am I killing myself with all these copies?\n+    cm_test = copy.deepcopy(cm_train)\n+\n+    # XXX: this should change depending on the type of data\n+    # link clustering method to data\n+    data_train = [self._data[tr_idx] for tr_idx in train]\n+    data_test = [self._data[te_idx] for te_idx in test]\n+\n+    if self._stack:\n+        data_train = np.vstack(data_train)\n+        data_test = np.vstack(data_train)\n+    else:\n+        data_train = np.mean(np.dstack(data_train), axis=-1)\n+        data_test = np.mean(np.dstack(data_test), axis=-1)\n+\n+    cm_train(data_train)\n+    cm_test(data_test)\n+\n+    # allocate storing dictionary\n+    result_fold = {}\n+    for metric in self._cluster_metrics:\n+        result_fold[metric.__name__] = \\\n+            np.vstack((self._ks, np.zeros(len(self._ks))))\n+        if self._ground_truth is not None:\n+            result_fold[metric.__name__ + '_gt'] = \\\n+                np.vstack((self._ks, np.zeros(len(self._ks))))\n+\n+    # Step 1. Clustering on training/test set and prediction\n+    for k in self._ks:\n+        # cluster on training set\n+        cm_train.cluster(k)","path":"reprclust/reproducibility.py","position":82,"original_position":82,"commit_id":"af91c6b0082214854d86243163ce83cbe244c472","original_commit_id":"af91c6b0082214854d86243163ce83cbe244c472","user":{"login":"mvdoc","id":6150554,"avatar_url":"https://avatars.githubusercontent.com/u/6150554?v=3","gravatar_id":"","url":"https://api.github.com/users/mvdoc","html_url":"https://github.com/mvdoc","followers_url":"https://api.github.com/users/mvdoc/followers","following_url":"https://api.github.com/users/mvdoc/following{/other_user}","gists_url":"https://api.github.com/users/mvdoc/gists{/gist_id}","starred_url":"https://api.github.com/users/mvdoc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mvdoc/subscriptions","organizations_url":"https://api.github.com/users/mvdoc/orgs","repos_url":"https://api.github.com/users/mvdoc/repos","events_url":"https://api.github.com/users/mvdoc/events{/privacy}","received_events_url":"https://api.github.com/users/mvdoc/received_events","type":"User","site_admin":false},"body":"add option `fully_train` for cases like hierarchical clustering, which will be ignored by other methods","created_at":"2015-07-06T20:20:32Z","updated_at":"2015-07-06T20:20:32Z","html_url":"https://github.com/mvdoc/reprclust/pull/4#discussion_r33977495","pull_request_url":"https://api.github.com/repos/mvdoc/reprclust/pulls/4","_links":{"self":{"href":"https://api.github.com/repos/mvdoc/reprclust/pulls/comments/33977495"},"html":{"href":"https://github.com/mvdoc/reprclust/pull/4#discussion_r33977495"},"pull_request":{"href":"https://api.github.com/repos/mvdoc/reprclust/pulls/4"}}},"pull_request":{"url":"https://api.github.com/repos/mvdoc/reprclust/pulls/4","id":38703563,"html_url":"https://github.com/mvdoc/reprclust/pull/4","diff_url":"https://github.com/mvdoc/reprclust/pull/4.diff","patch_url":"https://github.com/mvdoc/reprclust/pull/4.patch","issue_url":"https://api.github.com/repos/mvdoc/reprclust/issues/4","number":4,"state":"open","locked":false,"title":"Refactor everything into a class [NOT READY YET]","user":{"login":"mvdoc","id":6150554,"avatar_url":"https://avatars.githubusercontent.com/u/6150554?v=3","gravatar_id":"","url":"https://api.github.com/users/mvdoc","html_url":"https://github.com/mvdoc","followers_url":"https://api.github.com/users/mvdoc/followers","following_url":"https://api.github.com/users/mvdoc/following{/other_user}","gists_url":"https://api.github.com/users/mvdoc/gists{/gist_id}","starred_url":"https://api.github.com/users/mvdoc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mvdoc/subscriptions","organizations_url":"https://api.github.com/users/mvdoc/orgs","repos_url":"https://api.github.com/users/mvdoc/repos","events_url":"https://api.github.com/users/mvdoc/events{/privacy}","received_events_url":"https://api.github.com/users/mvdoc/received_events","type":"User","site_admin":false},"body":"I started refactoring everything into a class, still working on it -- not ready yet to merge.\r\n\r\nPlease have a look and let me know if you spot something terrible that needs to change. I ported most of the tests.","created_at":"2015-06-27T04:10:31Z","updated_at":"2015-07-06T20:20:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"15f59f7457155edfafabe701e71b2ad66e874354","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mvdoc/reprclust/pulls/4/commits","review_comments_url":"https://api.github.com/repos/mvdoc/reprclust/pulls/4/comments","review_comment_url":"https://api.github.com/repos/mvdoc/reprclust/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mvdoc/reprclust/issues/4/comments","statuses_url":"https://api.github.com/repos/mvdoc/reprclust/statuses/af91c6b0082214854d86243163ce83cbe244c472","head":{"label":"mvdoc:refactor","ref":"refactor","sha":"af91c6b0082214854d86243163ce83cbe244c472","user":{"login":"mvdoc","id":6150554,"avatar_url":"https://avatars.githubusercontent.com/u/6150554?v=3","gravatar_id":"","url":"https://api.github.com/users/mvdoc","html_url":"https://github.com/mvdoc","followers_url":"https://api.github.com/users/mvdoc/followers","following_url":"https://api.github.com/users/mvdoc/following{/other_user}","gists_url":"https://api.github.com/users/mvdoc/gists{/gist_id}","starred_url":"https://api.github.com/users/mvdoc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mvdoc/subscriptions","organizations_url":"https://api.github.com/users/mvdoc/orgs","repos_url":"https://api.github.com/users/mvdoc/repos","events_url":"https://api.github.com/users/mvdoc/events{/privacy}","received_events_url":"https://api.github.com/users/mvdoc/received_events","type":"User","site_admin":false},"repo":{"id":36743195,"name":"reprclust","full_name":"mvdoc/reprclust","owner":{"login":"mvdoc","id":6150554,"avatar_url":"https://avatars.githubusercontent.com/u/6150554?v=3","gravatar_id":"","url":"https://api.github.com/users/mvdoc","html_url":"https://github.com/mvdoc","followers_url":"https://api.github.com/users/mvdoc/followers","following_url":"https://api.github.com/users/mvdoc/following{/other_user}","gists_url":"https://api.github.com/users/mvdoc/gists{/gist_id}","starred_url":"https://api.github.com/users/mvdoc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mvdoc/subscriptions","organizations_url":"https://api.github.com/users/mvdoc/orgs","repos_url":"https://api.github.com/users/mvdoc/repos","events_url":"https://api.github.com/users/mvdoc/events{/privacy}","received_events_url":"https://api.github.com/users/mvdoc/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mvdoc/reprclust","description":"Clustering on representational similarities of fMRI data","fork":false,"url":"https://api.github.com/repos/mvdoc/reprclust","forks_url":"https://api.github.com/repos/mvdoc/reprclust/forks","keys_url":"https://api.github.com/repos/mvdoc/reprclust/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mvdoc/reprclust/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mvdoc/reprclust/teams","hooks_url":"https://api.github.com/repos/mvdoc/reprclust/hooks","issue_events_url":"https://api.github.com/repos/mvdoc/reprclust/issues/events{/number}","events_url":"https://api.github.com/repos/mvdoc/reprclust/events","assignees_url":"https://api.github.com/repos/mvdoc/reprclust/assignees{/user}","branches_url":"https://api.github.com/repos/mvdoc/reprclust/branches{/branch}","tags_url":"https://api.github.com/repos/mvdoc/reprclust/tags","blobs_url":"https://api.github.com/repos/mvdoc/reprclust/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mvdoc/reprclust/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mvdoc/reprclust/git/refs{/sha}","trees_url":"https://api.github.com/repos/mvdoc/reprclust/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mvdoc/reprclust/statuses/{sha}","languages_url":"https://api.github.com/repos/mvdoc/reprclust/languages","stargazers_url":"https://api.github.com/repos/mvdoc/reprclust/stargazers","contributors_url":"https://api.github.com/repos/mvdoc/reprclust/contributors","subscribers_url":"https://api.github.com/repos/mvdoc/reprclust/subscribers","subscription_url":"https://api.github.com/repos/mvdoc/reprclust/subscription","commits_url":"https://api.github.com/repos/mvdoc/reprclust/commits{/sha}","git_commits_url":"https://api.github.com/repos/mvdoc/reprclust/git/commits{/sha}","comments_url":"https://api.github.com/repos/mvdoc/reprclust/comments{/number}","issue_comment_url":"https://api.github.com/repos/mvdoc/reprclust/issues/comments{/number}","contents_url":"https://api.github.com/repos/mvdoc/reprclust/contents/{+path}","compare_url":"https://api.github.com/repos/mvdoc/reprclust/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mvdoc/reprclust/merges","archive_url":"https://api.github.com/repos/mvdoc/reprclust/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mvdoc/reprclust/downloads","issues_url":"https://api.github.com/repos/mvdoc/reprclust/issues{/number}","pulls_url":"https://api.github.com/repos/mvdoc/reprclust/pulls{/number}","milestones_url":"https://api.github.com/repos/mvdoc/reprclust/milestones{/number}","notifications_url":"https://api.github.com/repos/mvdoc/reprclust/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mvdoc/reprclust/labels{/name}","releases_url":"https://api.github.com/repos/mvdoc/reprclust/releases{/id}","created_at":"2015-06-02T15:36:59Z","updated_at":"2015-06-19T11:20:57Z","pushed_at":"2015-06-27T05:07:02Z","git_url":"git://github.com/mvdoc/reprclust.git","ssh_url":"git@github.com:mvdoc/reprclust.git","clone_url":"https://github.com/mvdoc/reprclust.git","svn_url":"https://github.com/mvdoc/reprclust","homepage":null,"size":779,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":1,"default_branch":"master"}},"base":{"label":"mvdoc:master","ref":"master","sha":"0599b01040ef75cd453effd46902001d8ad69e75","user":{"login":"mvdoc","id":6150554,"avatar_url":"https://avatars.githubusercontent.com/u/6150554?v=3","gravatar_id":"","url":"https://api.github.com/users/mvdoc","html_url":"https://github.com/mvdoc","followers_url":"https://api.github.com/users/mvdoc/followers","following_url":"https://api.github.com/users/mvdoc/following{/other_user}","gists_url":"https://api.github.com/users/mvdoc/gists{/gist_id}","starred_url":"https://api.github.com/users/mvdoc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mvdoc/subscriptions","organizations_url":"https://api.github.com/users/mvdoc/orgs","repos_url":"https://api.github.com/users/mvdoc/repos","events_url":"https://api.github.com/users/mvdoc/events{/privacy}","received_events_url":"https://api.github.com/users/mvdoc/received_events","type":"User","site_admin":false},"repo":{"id":36743195,"name":"reprclust","full_name":"mvdoc/reprclust","owner":{"login":"mvdoc","id":6150554,"avatar_url":"https://avatars.githubusercontent.com/u/6150554?v=3","gravatar_id":"","url":"https://api.github.com/users/mvdoc","html_url":"https://github.com/mvdoc","followers_url":"https://api.github.com/users/mvdoc/followers","following_url":"https://api.github.com/users/mvdoc/following{/other_user}","gists_url":"https://api.github.com/users/mvdoc/gists{/gist_id}","starred_url":"https://api.github.com/users/mvdoc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mvdoc/subscriptions","organizations_url":"https://api.github.com/users/mvdoc/orgs","repos_url":"https://api.github.com/users/mvdoc/repos","events_url":"https://api.github.com/users/mvdoc/events{/privacy}","received_events_url":"https://api.github.com/users/mvdoc/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mvdoc/reprclust","description":"Clustering on representational similarities of fMRI data","fork":false,"url":"https://api.github.com/repos/mvdoc/reprclust","forks_url":"https://api.github.com/repos/mvdoc/reprclust/forks","keys_url":"https://api.github.com/repos/mvdoc/reprclust/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mvdoc/reprclust/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mvdoc/reprclust/teams","hooks_url":"https://api.github.com/repos/mvdoc/reprclust/hooks","issue_events_url":"https://api.github.com/repos/mvdoc/reprclust/issues/events{/number}","events_url":"https://api.github.com/repos/mvdoc/reprclust/events","assignees_url":"https://api.github.com/repos/mvdoc/reprclust/assignees{/user}","branches_url":"https://api.github.com/repos/mvdoc/reprclust/branches{/branch}","tags_url":"https://api.github.com/repos/mvdoc/reprclust/tags","blobs_url":"https://api.github.com/repos/mvdoc/reprclust/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mvdoc/reprclust/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mvdoc/reprclust/git/refs{/sha}","trees_url":"https://api.github.com/repos/mvdoc/reprclust/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mvdoc/reprclust/statuses/{sha}","languages_url":"https://api.github.com/repos/mvdoc/reprclust/languages","stargazers_url":"https://api.github.com/repos/mvdoc/reprclust/stargazers","contributors_url":"https://api.github.com/repos/mvdoc/reprclust/contributors","subscribers_url":"https://api.github.com/repos/mvdoc/reprclust/subscribers","subscription_url":"https://api.github.com/repos/mvdoc/reprclust/subscription","commits_url":"https://api.github.com/repos/mvdoc/reprclust/commits{/sha}","git_commits_url":"https://api.github.com/repos/mvdoc/reprclust/git/commits{/sha}","comments_url":"https://api.github.com/repos/mvdoc/reprclust/comments{/number}","issue_comment_url":"https://api.github.com/repos/mvdoc/reprclust/issues/comments{/number}","contents_url":"https://api.github.com/repos/mvdoc/reprclust/contents/{+path}","compare_url":"https://api.github.com/repos/mvdoc/reprclust/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mvdoc/reprclust/merges","archive_url":"https://api.github.com/repos/mvdoc/reprclust/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mvdoc/reprclust/downloads","issues_url":"https://api.github.com/repos/mvdoc/reprclust/issues{/number}","pulls_url":"https://api.github.com/repos/mvdoc/reprclust/pulls{/number}","milestones_url":"https://api.github.com/repos/mvdoc/reprclust/milestones{/number}","notifications_url":"https://api.github.com/repos/mvdoc/reprclust/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mvdoc/reprclust/labels{/name}","releases_url":"https://api.github.com/repos/mvdoc/reprclust/releases{/id}","created_at":"2015-06-02T15:36:59Z","updated_at":"2015-06-19T11:20:57Z","pushed_at":"2015-06-27T05:07:02Z","git_url":"git://github.com/mvdoc/reprclust.git","ssh_url":"git@github.com:mvdoc/reprclust.git","clone_url":"https://github.com/mvdoc/reprclust.git","svn_url":"https://github.com/mvdoc/reprclust","homepage":null,"size":779,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mvdoc/reprclust/pulls/4"},"html":{"href":"https://github.com/mvdoc/reprclust/pull/4"},"issue":{"href":"https://api.github.com/repos/mvdoc/reprclust/issues/4"},"comments":{"href":"https://api.github.com/repos/mvdoc/reprclust/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/mvdoc/reprclust/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/mvdoc/reprclust/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mvdoc/reprclust/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/mvdoc/reprclust/statuses/af91c6b0082214854d86243163ce83cbe244c472"}}}}