{"action":"created","comment":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/32723164","id":32723164,"diff_hunk":"@@ -0,0 +1,133 @@\n+# cython: cdivision=True\n+# cython: boundscheck=False\n+# cython: wraparound=False\n+\n+# Author: Mathieu Blondel, Tom Dupre la Tour for Cython version\n+# License: BSD 3 clause\n+\n+import numpy as np\n+cimport cython\n+cimport numpy as np\n+from libc.math cimport fabs, fmax, fmin\n+\n+\n+def _update_cdnmf_fast(np.ndarray[double, ndim=2, mode='c'] W,\n+                       np.ndarray[double, ndim=2, mode='c'] HHt,\n+                       np.ndarray[double, ndim=2, mode='c'] XHt,\n+                       int transpose_XHt):\n+\n+    cdef double violation = 0\n+    cdef int n_components = W.shape[1]\n+    cdef int n_length = W.shape[0]\n+    cdef double grad\n+    cdef double pg\n+    cdef double hess\n+    cdef int i\n+    cdef int t\n+    cdef int r\n+\n+    with nogil:\n+        for i in range(n_length):\n+            for t in range(n_components):\n+\n+                # gradient\n+                # grad = GH[t, i] where GH = np.dot(HHt, H) - XHt\n+                if transpose_XHt:\n+                    grad = - XHt[t, i]\n+                else:\n+                    grad = - XHt[i, t]\n+\n+                for r in range(n_components):\n+                    grad += HHt[t, r] * W[i, r]\n+\n+                # projected gradient\n+                pg = fmin(0, grad) if W[i, t] == 0 else grad\n+                violation += fabs(pg)\n+\n+                # Hessian\n+                hess = HHt[t, t]\n+\n+                if hess != 0:\n+                    W[i, t] = fmax(W[i, t] - grad / hess, 0)\n+                \n+    return violation\n+\n+\n+def _update_greedy_cdnmf_fast(np.ndarray[double, ndim=2, mode='c'] W,\n+                              np.ndarray[double, ndim=2, mode='c'] G,\n+                              np.ndarray[double, ndim=2, mode='c'] HHt,\n+                              int max_inner, double tol):\n+    cdef double violation = 0.\n+    cdef double pg\n+    cdef int n_length = W.shape[0]","path":"sklearn/decomposition/cdnmf_fast.pyx","position":62,"original_position":62,"commit_id":"76b4fa8a90e7f4ab6d0df4f746564c57ae91f0ae","original_commit_id":"76b4fa8a90e7f4ab6d0df4f746564c57ae91f0ae","user":{"login":"mblondel","id":233706,"avatar_url":"https://avatars.githubusercontent.com/u/233706?v=3","gravatar_id":"","url":"https://api.github.com/users/mblondel","html_url":"https://github.com/mblondel","followers_url":"https://api.github.com/users/mblondel/followers","following_url":"https://api.github.com/users/mblondel/following{/other_user}","gists_url":"https://api.github.com/users/mblondel/gists{/gist_id}","starred_url":"https://api.github.com/users/mblondel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mblondel/subscriptions","organizations_url":"https://api.github.com/users/mblondel/orgs","repos_url":"https://api.github.com/users/mblondel/repos","events_url":"https://api.github.com/users/mblondel/events{/privacy}","received_events_url":"https://api.github.com/users/mblondel/received_events","type":"User","site_admin":false},"body":"n_features?","created_at":"2015-06-18T12:18:00Z","updated_at":"2015-06-18T12:18:00Z","html_url":"https://github.com/scikit-learn/scikit-learn/pull/4852#discussion_r32723164","pull_request_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/4852","_links":{"self":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/32723164"},"html":{"href":"https://github.com/scikit-learn/scikit-learn/pull/4852#discussion_r32723164"},"pull_request":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/4852"}}},"pull_request":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/4852","id":37473716,"html_url":"https://github.com/scikit-learn/scikit-learn/pull/4852","diff_url":"https://github.com/scikit-learn/scikit-learn/pull/4852.diff","patch_url":"https://github.com/scikit-learn/scikit-learn/pull/4852.patch","issue_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/4852","number":4852,"state":"open","locked":false,"title":"[WIP] refactor NMF and add CD solver","user":{"login":"TomDLT","id":11065596,"avatar_url":"https://avatars.githubusercontent.com/u/11065596?v=3","gravatar_id":"","url":"https://api.github.com/users/TomDLT","html_url":"https://github.com/TomDLT","followers_url":"https://api.github.com/users/TomDLT/followers","following_url":"https://api.github.com/users/TomDLT/following{/other_user}","gists_url":"https://api.github.com/users/TomDLT/gists{/gist_id}","starred_url":"https://api.github.com/users/TomDLT/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TomDLT/subscriptions","organizations_url":"https://api.github.com/users/TomDLT/orgs","repos_url":"https://api.github.com/users/TomDLT/repos","events_url":"https://api.github.com/users/TomDLT/events{/privacy}","received_events_url":"https://api.github.com/users/TomDLT/received_events","type":"User","site_admin":false},"body":"This PR is a first part of what is discussed in #4811.\r\nIt includes:\r\n- refactor ProjectedGradientNMF into NMF, with a 'proj-grad' solver\r\n- include random initialization into `_initialize_nmf()`\r\n- add ElasticNet-like regularization (with parameters `alpha` and `l1_ratio`)\r\n- add a solver with coordinate descent (from @mblondel) with Cython for critical part\r\n- update some tests and bench_plot_nmf (which looks terrible btw)\r\n\r\nIn some future PR, I will:\r\n- include MM (cf [comment](https://github.com/scikit-learn/scikit-learn/issues/4811#issuecomment-110391396)) in order to include more loss functions (I-divergence and IS-divergence)\r\n- investigate more on initialization of NMF\r\n- ...\r\n\r\nPlease tell me what you think :)","created_at":"2015-06-11T15:08:32Z","updated_at":"2015-06-18T12:18:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c25cd1914b4af1395b0a6949da4feb9c8353049e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/4852/commits","review_comments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/4852/comments","review_comment_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments{/number}","comments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/4852/comments","statuses_url":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/76b4fa8a90e7f4ab6d0df4f746564c57ae91f0ae","head":{"label":"TomDLT:nmf","ref":"nmf","sha":"76b4fa8a90e7f4ab6d0df4f746564c57ae91f0ae","user":{"login":"TomDLT","id":11065596,"avatar_url":"https://avatars.githubusercontent.com/u/11065596?v=3","gravatar_id":"","url":"https://api.github.com/users/TomDLT","html_url":"https://github.com/TomDLT","followers_url":"https://api.github.com/users/TomDLT/followers","following_url":"https://api.github.com/users/TomDLT/following{/other_user}","gists_url":"https://api.github.com/users/TomDLT/gists{/gist_id}","starred_url":"https://api.github.com/users/TomDLT/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TomDLT/subscriptions","organizations_url":"https://api.github.com/users/TomDLT/orgs","repos_url":"https://api.github.com/users/TomDLT/repos","events_url":"https://api.github.com/users/TomDLT/events{/privacy}","received_events_url":"https://api.github.com/users/TomDLT/received_events","type":"User","site_admin":false},"repo":{"id":34376788,"name":"scikit-learn","full_name":"TomDLT/scikit-learn","owner":{"login":"TomDLT","id":11065596,"avatar_url":"https://avatars.githubusercontent.com/u/11065596?v=3","gravatar_id":"","url":"https://api.github.com/users/TomDLT","html_url":"https://github.com/TomDLT","followers_url":"https://api.github.com/users/TomDLT/followers","following_url":"https://api.github.com/users/TomDLT/following{/other_user}","gists_url":"https://api.github.com/users/TomDLT/gists{/gist_id}","starred_url":"https://api.github.com/users/TomDLT/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TomDLT/subscriptions","organizations_url":"https://api.github.com/users/TomDLT/orgs","repos_url":"https://api.github.com/users/TomDLT/repos","events_url":"https://api.github.com/users/TomDLT/events{/privacy}","received_events_url":"https://api.github.com/users/TomDLT/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/TomDLT/scikit-learn","description":"scikit-learn: machine learning in Python","fork":true,"url":"https://api.github.com/repos/TomDLT/scikit-learn","forks_url":"https://api.github.com/repos/TomDLT/scikit-learn/forks","keys_url":"https://api.github.com/repos/TomDLT/scikit-learn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/TomDLT/scikit-learn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/TomDLT/scikit-learn/teams","hooks_url":"https://api.github.com/repos/TomDLT/scikit-learn/hooks","issue_events_url":"https://api.github.com/repos/TomDLT/scikit-learn/issues/events{/number}","events_url":"https://api.github.com/repos/TomDLT/scikit-learn/events","assignees_url":"https://api.github.com/repos/TomDLT/scikit-learn/assignees{/user}","branches_url":"https://api.github.com/repos/TomDLT/scikit-learn/branches{/branch}","tags_url":"https://api.github.com/repos/TomDLT/scikit-learn/tags","blobs_url":"https://api.github.com/repos/TomDLT/scikit-learn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/TomDLT/scikit-learn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/TomDLT/scikit-learn/git/refs{/sha}","trees_url":"https://api.github.com/repos/TomDLT/scikit-learn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/TomDLT/scikit-learn/statuses/{sha}","languages_url":"https://api.github.com/repos/TomDLT/scikit-learn/languages","stargazers_url":"https://api.github.com/repos/TomDLT/scikit-learn/stargazers","contributors_url":"https://api.github.com/repos/TomDLT/scikit-learn/contributors","subscribers_url":"https://api.github.com/repos/TomDLT/scikit-learn/subscribers","subscription_url":"https://api.github.com/repos/TomDLT/scikit-learn/subscription","commits_url":"https://api.github.com/repos/TomDLT/scikit-learn/commits{/sha}","git_commits_url":"https://api.github.com/repos/TomDLT/scikit-learn/git/commits{/sha}","comments_url":"https://api.github.com/repos/TomDLT/scikit-learn/comments{/number}","issue_comment_url":"https://api.github.com/repos/TomDLT/scikit-learn/issues/comments{/number}","contents_url":"https://api.github.com/repos/TomDLT/scikit-learn/contents/{+path}","compare_url":"https://api.github.com/repos/TomDLT/scikit-learn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/TomDLT/scikit-learn/merges","archive_url":"https://api.github.com/repos/TomDLT/scikit-learn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/TomDLT/scikit-learn/downloads","issues_url":"https://api.github.com/repos/TomDLT/scikit-learn/issues{/number}","pulls_url":"https://api.github.com/repos/TomDLT/scikit-learn/pulls{/number}","milestones_url":"https://api.github.com/repos/TomDLT/scikit-learn/milestones{/number}","notifications_url":"https://api.github.com/repos/TomDLT/scikit-learn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/TomDLT/scikit-learn/labels{/name}","releases_url":"https://api.github.com/repos/TomDLT/scikit-learn/releases{/id}","created_at":"2015-04-22T07:53:08Z","updated_at":"2015-05-12T12:17:35Z","pushed_at":"2015-06-18T11:51:01Z","git_url":"git://github.com/TomDLT/scikit-learn.git","ssh_url":"git@github.com:TomDLT/scikit-learn.git","clone_url":"https://github.com/TomDLT/scikit-learn.git","svn_url":"https://github.com/TomDLT/scikit-learn","homepage":"http://scikit-learn.org","size":63757,"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":"scikit-learn:master","ref":"master","sha":"e8c276337c6de4648c5a74ccde062a6c054bca2c","user":{"login":"scikit-learn","id":365630,"avatar_url":"https://avatars.githubusercontent.com/u/365630?v=3","gravatar_id":"","url":"https://api.github.com/users/scikit-learn","html_url":"https://github.com/scikit-learn","followers_url":"https://api.github.com/users/scikit-learn/followers","following_url":"https://api.github.com/users/scikit-learn/following{/other_user}","gists_url":"https://api.github.com/users/scikit-learn/gists{/gist_id}","starred_url":"https://api.github.com/users/scikit-learn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scikit-learn/subscriptions","organizations_url":"https://api.github.com/users/scikit-learn/orgs","repos_url":"https://api.github.com/users/scikit-learn/repos","events_url":"https://api.github.com/users/scikit-learn/events{/privacy}","received_events_url":"https://api.github.com/users/scikit-learn/received_events","type":"Organization","site_admin":false},"repo":{"id":843222,"name":"scikit-learn","full_name":"scikit-learn/scikit-learn","owner":{"login":"scikit-learn","id":365630,"avatar_url":"https://avatars.githubusercontent.com/u/365630?v=3","gravatar_id":"","url":"https://api.github.com/users/scikit-learn","html_url":"https://github.com/scikit-learn","followers_url":"https://api.github.com/users/scikit-learn/followers","following_url":"https://api.github.com/users/scikit-learn/following{/other_user}","gists_url":"https://api.github.com/users/scikit-learn/gists{/gist_id}","starred_url":"https://api.github.com/users/scikit-learn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scikit-learn/subscriptions","organizations_url":"https://api.github.com/users/scikit-learn/orgs","repos_url":"https://api.github.com/users/scikit-learn/repos","events_url":"https://api.github.com/users/scikit-learn/events{/privacy}","received_events_url":"https://api.github.com/users/scikit-learn/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/scikit-learn/scikit-learn","description":"scikit-learn: machine learning in Python","fork":false,"url":"https://api.github.com/repos/scikit-learn/scikit-learn","forks_url":"https://api.github.com/repos/scikit-learn/scikit-learn/forks","keys_url":"https://api.github.com/repos/scikit-learn/scikit-learn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/scikit-learn/scikit-learn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/scikit-learn/scikit-learn/teams","hooks_url":"https://api.github.com/repos/scikit-learn/scikit-learn/hooks","issue_events_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/events{/number}","events_url":"https://api.github.com/repos/scikit-learn/scikit-learn/events","assignees_url":"https://api.github.com/repos/scikit-learn/scikit-learn/assignees{/user}","branches_url":"https://api.github.com/repos/scikit-learn/scikit-learn/branches{/branch}","tags_url":"https://api.github.com/repos/scikit-learn/scikit-learn/tags","blobs_url":"https://api.github.com/repos/scikit-learn/scikit-learn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/scikit-learn/scikit-learn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/scikit-learn/scikit-learn/git/refs{/sha}","trees_url":"https://api.github.com/repos/scikit-learn/scikit-learn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/{sha}","languages_url":"https://api.github.com/repos/scikit-learn/scikit-learn/languages","stargazers_url":"https://api.github.com/repos/scikit-learn/scikit-learn/stargazers","contributors_url":"https://api.github.com/repos/scikit-learn/scikit-learn/contributors","subscribers_url":"https://api.github.com/repos/scikit-learn/scikit-learn/subscribers","subscription_url":"https://api.github.com/repos/scikit-learn/scikit-learn/subscription","commits_url":"https://api.github.com/repos/scikit-learn/scikit-learn/commits{/sha}","git_commits_url":"https://api.github.com/repos/scikit-learn/scikit-learn/git/commits{/sha}","comments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/comments{/number}","issue_comment_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/comments{/number}","contents_url":"https://api.github.com/repos/scikit-learn/scikit-learn/contents/{+path}","compare_url":"https://api.github.com/repos/scikit-learn/scikit-learn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/scikit-learn/scikit-learn/merges","archive_url":"https://api.github.com/repos/scikit-learn/scikit-learn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/scikit-learn/scikit-learn/downloads","issues_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues{/number}","pulls_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls{/number}","milestones_url":"https://api.github.com/repos/scikit-learn/scikit-learn/milestones{/number}","notifications_url":"https://api.github.com/repos/scikit-learn/scikit-learn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/scikit-learn/scikit-learn/labels{/name}","releases_url":"https://api.github.com/repos/scikit-learn/scikit-learn/releases{/id}","created_at":"2010-08-17T09:43:38Z","updated_at":"2015-06-18T03:14:26Z","pushed_at":"2015-06-18T11:51:03Z","git_url":"git://github.com/scikit-learn/scikit-learn.git","ssh_url":"git@github.com:scikit-learn/scikit-learn.git","clone_url":"https://github.com/scikit-learn/scikit-learn.git","svn_url":"https://github.com/scikit-learn/scikit-learn","homepage":"http://scikit-learn.org","size":123263,"stargazers_count":6436,"watchers_count":6436,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3856,"mirror_url":null,"open_issues_count":676,"forks":3856,"open_issues":676,"watchers":6436,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/4852"},"html":{"href":"https://github.com/scikit-learn/scikit-learn/pull/4852"},"issue":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/4852"},"comments":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/4852/comments"},"review_comments":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/4852/comments"},"review_comment":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/4852/commits"},"statuses":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/76b4fa8a90e7f4ab6d0df4f746564c57ae91f0ae"}}}}