GitHub PullRequestReviewCommentEvent at 2014-11-21 00:57:46
Repository: dipy
Actor: stefanv
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/nipy/dipy/pulls/comments/20690806","id":20690806,"diff_hunk":"@@ -0,0 +1,322 @@\n+\"\"\"\n+This is an implementation of the sparse fascicle model described in\n+[Rokem2014]_.\n+\n+\n+.. [Rokem2014] Ariel Rokem, Jason D. Yeatman, Franco Pestilli, Kendrick\n+   N. Kay, Aviv Mezer, Stefan van der Walt, Brian A. Wandell\n+   (2014). Evaluating the accuracy of diffusion MRI models in white\n+   matter. http://arxiv.org/abs/1411.0721\n+\n+\"\"\"\n+import warnings\n+\n+import numpy as np\n+from dipy.utils.optpkg import optional_package\n+import dipy.core.geometry as geo\n+import dipy.core.gradients as grad\n+import dipy.core.optimize as opt\n+import dipy.sims.voxel as sims\n+import dipy.reconst.dti as dti\n+import dipy.data as dpd\n+from dipy.reconst.base import ReconstModel, ReconstFit\n+from dipy.reconst.cache import Cache\n+from dipy.core.onetime import auto_attr\n+\n+lm, has_sklearn, _ = optional_package('sklearn.linear_model')\n+\n+# If sklearn is unavailable, we can fall back on nnls (but we also warn the\n+# user that we are about to do that):\n+if not has_sklearn:\n+    w = \"sklearn is not available, you can use 'nnls' method to fit\"\n+    w += \" the SparseFascicleModel\"\n+    warnings.warn(w)\n+\n+\n+def sfm_design_matrix(gtab, sphere, response, mode='sig'):\n+    \"\"\"\n+    Construct the SFM design matrix\n+\n+    Parameters\n+    ----------\n+    gtab : GradientTable or Sphere\n+        Sets the rows of the matrix, if the mode is 'sig', this should be a\n+        GradientTable. If mode is 'odf' this should be a Sphere\n+\n+    sphere : Sphere\n+        Sets the columns of the matrix\n+\n+    response : list of 3 elements\n+        The eigenvalues of a tensor which will serve as a kernel function\n+\n+    mode : str\n+        'sig' : for a signal design matrix. 'odf' for an odf convolution matrix\n+\n+    Returns\n+    -------\n+    mat : ndarray\n+        A matrix either for deconvolution with the signal, or for reconvolution\n+        to form an ODF\n+    \"\"\"\n+    # Each column of the matrix is the signal in each measurement, as\n+    # predicted by a \"canonical\", symmetrical tensor rotated towards this\n+    # vertex of the sphere:\n+    canonical_tensor = np.array([[response[0], 0, 0],\n+                                     [0, response[1], 0],\n+                                     [0, 0, response[2]]])\n+\n+    if mode == 'sig':\n+        mat_gtab = grad.gradient_table(gtab.bvals[~gtab.b0s_mask],\n+                                       gtab.bvecs[~gtab.b0s_mask])\n+        # Preallocate:\n+        mat = np.empty((np.sum(~gtab.b0s_mask),\n+                        sphere.vertices.shape[0]))\n+    elif mode == 'odf':\n+        mat = np.empty((gtab.x.shape[0], sphere.vertices.shape[0]))\n+\n+    # Calculate column-wise:\n+    for ii, this_dir in enumerate(sphere.vertices):\n+        # Rotate the canonical tensor towards this vertex and calculate the\n+        # signal you would have gotten in the direction\n+        rot_matrix = geo.vec2vec_rotmat(np.array([1,0,0]), this_dir)\n+        this_tensor = np.dot(rot_matrix, canonical_tensor)\n+        evals, evecs = dti.decompose_tensor(this_tensor)\n+        if mode == 'sig':\n+            sig = sims.single_tensor(mat_gtab, evals=response, evecs=evecs)\n+            mat[:, ii] = sig - np.mean(sig)\n+        elif mode == 'odf':\n+            odf = sims.single_tensor_odf(gtab.vertices,\n+                                         evals=response, evecs=evecs)\n+            mat[:, ii] = odf\n+    return mat\n+\n+\n+\n+class SparseFascicleModel(ReconstModel, Cache):\n+    def __init__(self, gtab, sphere=None, response=[0.0015, 0.0005, 0.0005],\n+                 solver='ElasticNet', l1_ratio=0.5, alpha=0.001):\n+        \"\"\"\n+        Initialize a Sparse Fascicle Model\n+\n+        Parameters\n+        ----------\n+        gtab : GradienTable class instance","path":"dipy/reconst/sfm.py","position":103,"original_position":103,"commit_id":"8e150dd3fff1b9fa052a9e7b4ab337ccc39ecb17","original_commit_id":"8e150dd3fff1b9fa052a9e7b4ab337ccc39ecb17","user":{"login":"stefanv","id":45071,"avatar_url":"https://avatars.githubusercontent.com/u/45071?v=3","gravatar_id":"","url":"https://api.github.com/users/stefanv","html_url":"https://github.com/stefanv","followers_url":"https://api.github.com/users/stefanv/followers","following_url":"https://api.github.com/users/stefanv/following{/other_user}","gists_url":"https://api.github.com/users/stefanv/gists{/gist_id}","starred_url":"https://api.github.com/users/stefanv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stefanv/subscriptions","organizations_url":"https://api.github.com/users/stefanv/orgs","repos_url":"https://api.github.com/users/stefanv/repos","events_url":"https://api.github.com/users/stefanv/events{/privacy}","received_events_url":"https://api.github.com/users/stefanv/received_events","type":"User","site_admin":false},"body":"typo","created_at":"2014-11-21T00:57:46Z","updated_at":"2014-11-21T00:57:46Z","html_url":"https://github.com/nipy/dipy/pull/460#discussion_r20690806","pull_request_url":"https://api.github.com/repos/nipy/dipy/pulls/460","_links":{"self":{"href":"https://api.github.com/repos/nipy/dipy/pulls/comments/20690806"},"html":{"href":"https://github.com/nipy/dipy/pull/460#discussion_r20690806"},"pull_request":{"href":"https://api.github.com/repos/nipy/dipy/pulls/460"}}},"pull_request":{"url":"https://api.github.com/repos/nipy/dipy/pulls/460","id":24253002,"html_url":"https://github.com/nipy/dipy/pull/460","diff_url":"https://github.com/nipy/dipy/pull/460.diff","patch_url":"https://github.com/nipy/dipy/pull/460.patch","issue_url":"https://api.github.com/repos/nipy/dipy/issues/460","number":460,"state":"open","locked":false,"title":"Sparse Fascicle Model","user":{"login":"arokem","id":118582,"avatar_url":"https://avatars.githubusercontent.com/u/118582?v=3","gravatar_id":"","url":"https://api.github.com/users/arokem","html_url":"https://github.com/arokem","followers_url":"https://api.github.com/users/arokem/followers","following_url":"https://api.github.com/users/arokem/following{/other_user}","gists_url":"https://api.github.com/users/arokem/gists{/gist_id}","starred_url":"https://api.github.com/users/arokem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arokem/subscriptions","organizations_url":"https://api.github.com/users/arokem/orgs","repos_url":"https://api.github.com/users/arokem/repos","events_url":"https://api.github.com/users/arokem/events{/privacy}","received_events_url":"https://api.github.com/users/arokem/received_events","type":"User","site_admin":false},"body":"This is a start on an implementation of the model we describe here: \r\n\r\nhttp://arxiv.org/abs/1411.0721\r\n\r\nThe main current issue with this is that this will have a local dependency on scikit-learn, because it uses ElasticNet for the fit. How do people feel about that? ","created_at":"2014-11-11T21:53:31Z","updated_at":"2014-11-21T00:57:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"07931385bbc8690450b5cf2bb0ef9d8f32872487","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/nipy/dipy/pulls/460/commits","review_comments_url":"https://api.github.com/repos/nipy/dipy/pulls/460/comments","review_comment_url":"https://api.github.com/repos/nipy/dipy/pulls/comments/{number}","comments_url":"https://api.github.com/repos/nipy/dipy/issues/460/comments","statuses_url":"https://api.github.com/repos/nipy/dipy/statuses/8e150dd3fff1b9fa052a9e7b4ab337ccc39ecb17","head":{"label":"arokem:sparse-fascicle","ref":"sparse-fascicle","sha":"8e150dd3fff1b9fa052a9e7b4ab337ccc39ecb17","user":{"login":"arokem","id":118582,"avatar_url":"https://avatars.githubusercontent.com/u/118582?v=3","gravatar_id":"","url":"https://api.github.com/users/arokem","html_url":"https://github.com/arokem","followers_url":"https://api.github.com/users/arokem/followers","following_url":"https://api.github.com/users/arokem/following{/other_user}","gists_url":"https://api.github.com/users/arokem/gists{/gist_id}","starred_url":"https://api.github.com/users/arokem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arokem/subscriptions","organizations_url":"https://api.github.com/users/arokem/orgs","repos_url":"https://api.github.com/users/arokem/repos","events_url":"https://api.github.com/users/arokem/events{/privacy}","received_events_url":"https://api.github.com/users/arokem/received_events","type":"User","site_admin":false},"repo":{"id":2484790,"name":"dipy","full_name":"arokem/dipy","owner":{"login":"arokem","id":118582,"avatar_url":"https://avatars.githubusercontent.com/u/118582?v=3","gravatar_id":"","url":"https://api.github.com/users/arokem","html_url":"https://github.com/arokem","followers_url":"https://api.github.com/users/arokem/followers","following_url":"https://api.github.com/users/arokem/following{/other_user}","gists_url":"https://api.github.com/users/arokem/gists{/gist_id}","starred_url":"https://api.github.com/users/arokem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arokem/subscriptions","organizations_url":"https://api.github.com/users/arokem/orgs","repos_url":"https://api.github.com/users/arokem/repos","events_url":"https://api.github.com/users/arokem/events{/privacy}","received_events_url":"https://api.github.com/users/arokem/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/arokem/dipy","description":"Diffusion MR Imaging in Python","fork":true,"url":"https://api.github.com/repos/arokem/dipy","forks_url":"https://api.github.com/repos/arokem/dipy/forks","keys_url":"https://api.github.com/repos/arokem/dipy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/arokem/dipy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/arokem/dipy/teams","hooks_url":"https://api.github.com/repos/arokem/dipy/hooks","issue_events_url":"https://api.github.com/repos/arokem/dipy/issues/events{/number}","events_url":"https://api.github.com/repos/arokem/dipy/events","assignees_url":"https://api.github.com/repos/arokem/dipy/assignees{/user}","branches_url":"https://api.github.com/repos/arokem/dipy/branches{/branch}","tags_url":"https://api.github.com/repos/arokem/dipy/tags","blobs_url":"https://api.github.com/repos/arokem/dipy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/arokem/dipy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/arokem/dipy/git/refs{/sha}","trees_url":"https://api.github.com/repos/arokem/dipy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/arokem/dipy/statuses/{sha}","languages_url":"https://api.github.com/repos/arokem/dipy/languages","stargazers_url":"https://api.github.com/repos/arokem/dipy/stargazers","contributors_url":"https://api.github.com/repos/arokem/dipy/contributors","subscribers_url":"https://api.github.com/repos/arokem/dipy/subscribers","subscription_url":"https://api.github.com/repos/arokem/dipy/subscription","commits_url":"https://api.github.com/repos/arokem/dipy/commits{/sha}","git_commits_url":"https://api.github.com/repos/arokem/dipy/git/commits{/sha}","comments_url":"https://api.github.com/repos/arokem/dipy/comments{/number}","issue_comment_url":"https://api.github.com/repos/arokem/dipy/issues/comments/{number}","contents_url":"https://api.github.com/repos/arokem/dipy/contents/{+path}","compare_url":"https://api.github.com/repos/arokem/dipy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/arokem/dipy/merges","archive_url":"https://api.github.com/repos/arokem/dipy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/arokem/dipy/downloads","issues_url":"https://api.github.com/repos/arokem/dipy/issues{/number}","pulls_url":"https://api.github.com/repos/arokem/dipy/pulls{/number}","milestones_url":"https://api.github.com/repos/arokem/dipy/milestones{/number}","notifications_url":"https://api.github.com/repos/arokem/dipy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/arokem/dipy/labels{/name}","releases_url":"https://api.github.com/repos/arokem/dipy/releases{/id}","created_at":"2011-09-29T20:43:30Z","updated_at":"2014-11-17T21:02:02Z","pushed_at":"2014-11-20T01:27:15Z","git_url":"git://github.com/arokem/dipy.git","ssh_url":"git@github.com:arokem/dipy.git","clone_url":"https://github.com/arokem/dipy.git","svn_url":"https://github.com/arokem/dipy","homepage":"http://dipy.org","size":16944,"stargazers_count":2,"watchers_count":2,"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":2,"default_branch":"master"}},"base":{"label":"nipy:master","ref":"master","sha":"ed6838d6fb4ce0ed1f926d11390f1d4e6dc8a7f0","user":{"login":"nipy","id":233707,"avatar_url":"https://avatars.githubusercontent.com/u/233707?v=3","gravatar_id":"","url":"https://api.github.com/users/nipy","html_url":"https://github.com/nipy","followers_url":"https://api.github.com/users/nipy/followers","following_url":"https://api.github.com/users/nipy/following{/other_user}","gists_url":"https://api.github.com/users/nipy/gists{/gist_id}","starred_url":"https://api.github.com/users/nipy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nipy/subscriptions","organizations_url":"https://api.github.com/users/nipy/orgs","repos_url":"https://api.github.com/users/nipy/repos","events_url":"https://api.github.com/users/nipy/events{/privacy}","received_events_url":"https://api.github.com/users/nipy/received_events","type":"Organization","site_admin":false},"repo":{"id":505209,"name":"dipy","full_name":"nipy/dipy","owner":{"login":"nipy","id":233707,"avatar_url":"https://avatars.githubusercontent.com/u/233707?v=3","gravatar_id":"","url":"https://api.github.com/users/nipy","html_url":"https://github.com/nipy","followers_url":"https://api.github.com/users/nipy/followers","following_url":"https://api.github.com/users/nipy/following{/other_user}","gists_url":"https://api.github.com/users/nipy/gists{/gist_id}","starred_url":"https://api.github.com/users/nipy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nipy/subscriptions","organizations_url":"https://api.github.com/users/nipy/orgs","repos_url":"https://api.github.com/users/nipy/repos","events_url":"https://api.github.com/users/nipy/events{/privacy}","received_events_url":"https://api.github.com/users/nipy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nipy/dipy","description":"Diffusion MR Imaging in Python","fork":false,"url":"https://api.github.com/repos/nipy/dipy","forks_url":"https://api.github.com/repos/nipy/dipy/forks","keys_url":"https://api.github.com/repos/nipy/dipy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nipy/dipy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nipy/dipy/teams","hooks_url":"https://api.github.com/repos/nipy/dipy/hooks","issue_events_url":"https://api.github.com/repos/nipy/dipy/issues/events{/number}","events_url":"https://api.github.com/repos/nipy/dipy/events","assignees_url":"https://api.github.com/repos/nipy/dipy/assignees{/user}","branches_url":"https://api.github.com/repos/nipy/dipy/branches{/branch}","tags_url":"https://api.github.com/repos/nipy/dipy/tags","blobs_url":"https://api.github.com/repos/nipy/dipy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nipy/dipy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nipy/dipy/git/refs{/sha}","trees_url":"https://api.github.com/repos/nipy/dipy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nipy/dipy/statuses/{sha}","languages_url":"https://api.github.com/repos/nipy/dipy/languages","stargazers_url":"https://api.github.com/repos/nipy/dipy/stargazers","contributors_url":"https://api.github.com/repos/nipy/dipy/contributors","subscribers_url":"https://api.github.com/repos/nipy/dipy/subscribers","subscription_url":"https://api.github.com/repos/nipy/dipy/subscription","commits_url":"https://api.github.com/repos/nipy/dipy/commits{/sha}","git_commits_url":"https://api.github.com/repos/nipy/dipy/git/commits{/sha}","comments_url":"https://api.github.com/repos/nipy/dipy/comments{/number}","issue_comment_url":"https://api.github.com/repos/nipy/dipy/issues/comments/{number}","contents_url":"https://api.github.com/repos/nipy/dipy/contents/{+path}","compare_url":"https://api.github.com/repos/nipy/dipy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nipy/dipy/merges","archive_url":"https://api.github.com/repos/nipy/dipy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nipy/dipy/downloads","issues_url":"https://api.github.com/repos/nipy/dipy/issues{/number}","pulls_url":"https://api.github.com/repos/nipy/dipy/pulls{/number}","milestones_url":"https://api.github.com/repos/nipy/dipy/milestones{/number}","notifications_url":"https://api.github.com/repos/nipy/dipy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nipy/dipy/labels{/name}","releases_url":"https://api.github.com/repos/nipy/dipy/releases{/id}","created_at":"2010-02-06T11:43:08Z","updated_at":"2014-11-19T19:06:56Z","pushed_at":"2014-11-19T19:06:56Z","git_url":"git://github.com/nipy/dipy.git","ssh_url":"git@github.com:nipy/dipy.git","clone_url":"https://github.com/nipy/dipy.git","svn_url":"https://github.com/nipy/dipy","homepage":"http://dipy.org","size":19747,"stargazers_count":48,"watchers_count":48,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":69,"mirror_url":null,"open_issues_count":61,"forks":69,"open_issues":61,"watchers":48,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nipy/dipy/pulls/460"},"html":{"href":"https://github.com/nipy/dipy/pull/460"},"issue":{"href":"https://api.github.com/repos/nipy/dipy/issues/460"},"comments":{"href":"https://api.github.com/repos/nipy/dipy/issues/460/comments"},"review_comments":{"href":"https://api.github.com/repos/nipy/dipy/pulls/460/comments"},"review_comment":{"href":"https://api.github.com/repos/nipy/dipy/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/nipy/dipy/pulls/460/commits"},"statuses":{"href":"https://api.github.com/repos/nipy/dipy/statuses/8e150dd3fff1b9fa052a9e7b4ab337ccc39ecb17"}}}}