{"action":"created","comment":{"url":"https://api.github.com/repos/greenelab/hetmech/pulls/comments/192758711","pull_request_review_id":125595599,"id":192758711,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5Mjc1ODcxMQ==","diff_hunk":"@@ -152,6 +152,80 @@ def dwwc(graph, metapath, damping=0.5, dense_threshold=0, dtype=numpy.float64):\n     return row_names, cols, dwwc_matrix\n \n \n+@path_count_cache(metric='dwwc')\n+def dwwc_recursive(graph, metapath, damping=0.5, dense_threshold=0, dtype=numpy.float64):\n+    \"\"\"\n+    Recursive DWWC implementation to take better advantage of caching.\n+    \"\"\"\n+    rows, cols, adj_mat = hetmech.matrix.metaedge_to_adjacency_matrix(\n+        graph, metapath[0], dense_threshold=dense_threshold, dtype=dtype)\n+    adj_mat = _degree_weight(adj_mat, damping, dtype=dtype)\n+    if len(metapath) > 1:\n+        _, cols, dwwc_next = dwwc_recursive(graph, metapath[1:], damping=damping,\n+                                            dense_threshold=dense_threshold, dtype=dtype)\n+        dwwc_matrix = adj_mat @ dwwc_next\n+    else:\n+        dwwc_matrix = adj_mat\n+    dwwc_matrix = sparsify_or_densify(dwwc_matrix, dense_threshold)\n+    return rows, cols, dwwc_matrix\n+\n+\n+def _multi_dot(metapath, order, i, j, graph, damping, dense_threshold, dtype):\n+    \"\"\"\n+    Perform matrix multiplication with the given order. Modified from\n+    numpy.linalg.linalg._multi_dot (https://git.io/vh31f) which is released\n+    under a 3-Clause BSD License (https://git.io/vhCDC).\n+    \"\"\"\n+    if i == j:\n+        _, _, adj_mat = metaedge_to_adjacency_matrix(\n+            graph, metapath[i], dense_threshold=dense_threshold, dtype=dtype)\n+        adj_mat = _degree_weight(adj_mat, damping=damping)\n+        return adj_mat\n+    return _multi_dot(metapath, order, i, order[i, j], graph, damping, dense_threshold, dtype) \\\n+        @ _multi_dot(metapath, order, order[i, j] + 1, j, graph, damping, dense_threshold, dtype)\n+\n+\n+def _dimensions_to_ordering(dimensions):\n+    # Find optimal matrix chain ordering. See https://git.io/vh38o\n+    n = len(dimensions) - 1\n+    m = numpy.zeros((n, n), dtype=numpy.double)\n+    ordering = numpy.empty((n, n), dtype=numpy.intp)\n+    for l in range(1, n):\n+        for i in range(n - l):\n+            j = i + l\n+            m[i, j] = numpy.inf\n+            for k in range(i, j):\n+                q = m[i, k] + m[k + 1, j] + dimensions[i] * dimensions[k + 1] * dimensions[j + 1]\n+                if q < m[i, j]:\n+                    m[i, j] = q\n+                    ordering[i, j] = k\n+    return ordering\n+\n+\n+@path_count_cache(metric='dwwc')\n+def dwwc_chain(graph, metapath, damping=0.5, dense_threshold=0, dtype=numpy.float64):\n+    \"\"\"\n+    Uses optimal matrix chain multiplication as in numpy.multi_dot, but allows\n+    for sparse matrices. See original source, numpy.linalg: https://git.io/vh38o","path":"hetmech/degree_weight.py","position":58,"original_position":58,"commit_id":"f5ac52f7649f944a44f85e015a52f03f64290018","original_commit_id":"f5ac52f7649f944a44f85e015a52f03f64290018","user":{"login":"dhimmel","id":1117703,"node_id":"MDQ6VXNlcjExMTc3MDM=","avatar_url":"https://avatars1.githubusercontent.com/u/1117703?v=4","gravatar_id":"","url":"https://api.github.com/users/dhimmel","html_url":"https://github.com/dhimmel","followers_url":"https://api.github.com/users/dhimmel/followers","following_url":"https://api.github.com/users/dhimmel/following{/other_user}","gists_url":"https://api.github.com/users/dhimmel/gists{/gist_id}","starred_url":"https://api.github.com/users/dhimmel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dhimmel/subscriptions","organizations_url":"https://api.github.com/users/dhimmel/orgs","repos_url":"https://api.github.com/users/dhimmel/repos","events_url":"https://api.github.com/users/dhimmel/events{/privacy}","received_events_url":"https://api.github.com/users/dhimmel/received_events","type":"User","site_admin":false},"body":"Must also mention license of original here.","created_at":"2018-06-04T14:24:56Z","updated_at":"2018-06-04T14:24:56Z","html_url":"https://github.com/greenelab/hetmech/pull/112#discussion_r192758711","pull_request_url":"https://api.github.com/repos/greenelab/hetmech/pulls/112","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/greenelab/hetmech/pulls/comments/192758711"},"html":{"href":"https://github.com/greenelab/hetmech/pull/112#discussion_r192758711"},"pull_request":{"href":"https://api.github.com/repos/greenelab/hetmech/pulls/112"}}},"pull_request":{"url":"https://api.github.com/repos/greenelab/hetmech/pulls/112","id":191249256,"node_id":"MDExOlB1bGxSZXF1ZXN0MTkxMjQ5MjU2","html_url":"https://github.com/greenelab/hetmech/pull/112","diff_url":"https://github.com/greenelab/hetmech/pull/112.diff","patch_url":"https://github.com/greenelab/hetmech/pull/112.patch","issue_url":"https://api.github.com/repos/greenelab/hetmech/issues/112","number":112,"state":"open","locked":false,"title":"DWWC recursive and chain-ordering","user":{"login":"zietzm","id":7230303,"node_id":"MDQ6VXNlcjcyMzAzMDM=","avatar_url":"https://avatars1.githubusercontent.com/u/7230303?v=4","gravatar_id":"","url":"https://api.github.com/users/zietzm","html_url":"https://github.com/zietzm","followers_url":"https://api.github.com/users/zietzm/followers","following_url":"https://api.github.com/users/zietzm/following{/other_user}","gists_url":"https://api.github.com/users/zietzm/gists{/gist_id}","starred_url":"https://api.github.com/users/zietzm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zietzm/subscriptions","organizations_url":"https://api.github.com/users/zietzm/orgs","repos_url":"https://api.github.com/users/zietzm/repos","events_url":"https://api.github.com/users/zietzm/events{/privacy}","received_events_url":"https://api.github.com/users/zietzm/received_events","type":"User","site_admin":false},"body":"References #53 \r\n\r\nAdd two new functions for computing DWWC. The notebook shows that both chain ordering and recursion with caching are a good bit faster than our standard implementation. Note that in the notebook, I performed the computations having `dwwc_recursive` cache using the cacher metric `dwpc`. This was to make sure that `dwwc` was not simply calling the cached result of the recursive function, but to include the actual times we would expect when using caching.\r\n\r\nOver the Rephetio metapaths, the two new methods took this many seconds (old method for comparison) in sparse format.\r\n\r\n| DWWC method | Time for all Rephetio (s) |\r\n|-------------|---------------------------|\r\n| original    | 219.110172                |\r\n| recursive   | 93.744713                 |\r\n| chain       | 70.896228                 |","created_at":"2018-05-29T19:39:24Z","updated_at":"2018-06-04T14:24:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7e116ba34e9fc12ad7e7ff3afbc3a95557bbf70e","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/greenelab/hetmech/pulls/112/commits","review_comments_url":"https://api.github.com/repos/greenelab/hetmech/pulls/112/comments","review_comment_url":"https://api.github.com/repos/greenelab/hetmech/pulls/comments{/number}","comments_url":"https://api.github.com/repos/greenelab/hetmech/issues/112/comments","statuses_url":"https://api.github.com/repos/greenelab/hetmech/statuses/f5ac52f7649f944a44f85e015a52f03f64290018","head":{"label":"zietzm:dwwc-recursive","ref":"dwwc-recursive","sha":"f5ac52f7649f944a44f85e015a52f03f64290018","user":{"login":"zietzm","id":7230303,"node_id":"MDQ6VXNlcjcyMzAzMDM=","avatar_url":"https://avatars1.githubusercontent.com/u/7230303?v=4","gravatar_id":"","url":"https://api.github.com/users/zietzm","html_url":"https://github.com/zietzm","followers_url":"https://api.github.com/users/zietzm/followers","following_url":"https://api.github.com/users/zietzm/following{/other_user}","gists_url":"https://api.github.com/users/zietzm/gists{/gist_id}","starred_url":"https://api.github.com/users/zietzm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zietzm/subscriptions","organizations_url":"https://api.github.com/users/zietzm/orgs","repos_url":"https://api.github.com/users/zietzm/repos","events_url":"https://api.github.com/users/zietzm/events{/privacy}","received_events_url":"https://api.github.com/users/zietzm/received_events","type":"User","site_admin":false},"repo":{"id":88914097,"node_id":"MDEwOlJlcG9zaXRvcnk4ODkxNDA5Nw==","name":"hetmech","full_name":"zietzm/hetmech","owner":{"login":"zietzm","id":7230303,"node_id":"MDQ6VXNlcjcyMzAzMDM=","avatar_url":"https://avatars1.githubusercontent.com/u/7230303?v=4","gravatar_id":"","url":"https://api.github.com/users/zietzm","html_url":"https://github.com/zietzm","followers_url":"https://api.github.com/users/zietzm/followers","following_url":"https://api.github.com/users/zietzm/following{/other_user}","gists_url":"https://api.github.com/users/zietzm/gists{/gist_id}","starred_url":"https://api.github.com/users/zietzm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zietzm/subscriptions","organizations_url":"https://api.github.com/users/zietzm/orgs","repos_url":"https://api.github.com/users/zietzm/repos","events_url":"https://api.github.com/users/zietzm/events{/privacy}","received_events_url":"https://api.github.com/users/zietzm/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/zietzm/hetmech","description":"Greene Lab/Theory In Practice collaboration on identifying mechanisms using hetnets","fork":true,"url":"https://api.github.com/repos/zietzm/hetmech","forks_url":"https://api.github.com/repos/zietzm/hetmech/forks","keys_url":"https://api.github.com/repos/zietzm/hetmech/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zietzm/hetmech/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zietzm/hetmech/teams","hooks_url":"https://api.github.com/repos/zietzm/hetmech/hooks","issue_events_url":"https://api.github.com/repos/zietzm/hetmech/issues/events{/number}","events_url":"https://api.github.com/repos/zietzm/hetmech/events","assignees_url":"https://api.github.com/repos/zietzm/hetmech/assignees{/user}","branches_url":"https://api.github.com/repos/zietzm/hetmech/branches{/branch}","tags_url":"https://api.github.com/repos/zietzm/hetmech/tags","blobs_url":"https://api.github.com/repos/zietzm/hetmech/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zietzm/hetmech/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zietzm/hetmech/git/refs{/sha}","trees_url":"https://api.github.com/repos/zietzm/hetmech/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zietzm/hetmech/statuses/{sha}","languages_url":"https://api.github.com/repos/zietzm/hetmech/languages","stargazers_url":"https://api.github.com/repos/zietzm/hetmech/stargazers","contributors_url":"https://api.github.com/repos/zietzm/hetmech/contributors","subscribers_url":"https://api.github.com/repos/zietzm/hetmech/subscribers","subscription_url":"https://api.github.com/repos/zietzm/hetmech/subscription","commits_url":"https://api.github.com/repos/zietzm/hetmech/commits{/sha}","git_commits_url":"https://api.github.com/repos/zietzm/hetmech/git/commits{/sha}","comments_url":"https://api.github.com/repos/zietzm/hetmech/comments{/number}","issue_comment_url":"https://api.github.com/repos/zietzm/hetmech/issues/comments{/number}","contents_url":"https://api.github.com/repos/zietzm/hetmech/contents/{+path}","compare_url":"https://api.github.com/repos/zietzm/hetmech/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zietzm/hetmech/merges","archive_url":"https://api.github.com/repos/zietzm/hetmech/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zietzm/hetmech/downloads","issues_url":"https://api.github.com/repos/zietzm/hetmech/issues{/number}","pulls_url":"https://api.github.com/repos/zietzm/hetmech/pulls{/number}","milestones_url":"https://api.github.com/repos/zietzm/hetmech/milestones{/number}","notifications_url":"https://api.github.com/repos/zietzm/hetmech/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zietzm/hetmech/labels{/name}","releases_url":"https://api.github.com/repos/zietzm/hetmech/releases{/id}","deployments_url":"https://api.github.com/repos/zietzm/hetmech/deployments","created_at":"2017-04-20T21:59:28Z","updated_at":"2018-05-25T18:20:00Z","pushed_at":"2018-06-04T13:24:57Z","git_url":"git://github.com/zietzm/hetmech.git","ssh_url":"git@github.com:zietzm/hetmech.git","clone_url":"https://github.com/zietzm/hetmech.git","svn_url":"https://github.com/zietzm/hetmech","homepage":"","size":11173,"stargazers_count":0,"watchers_count":0,"language":"Jupyter Notebook","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"greenelab:master","ref":"master","sha":"20badcdaa04099fdd258d38ad7a7660b56e949a6","user":{"login":"greenelab","id":9607754,"node_id":"MDEyOk9yZ2FuaXphdGlvbjk2MDc3NTQ=","avatar_url":"https://avatars1.githubusercontent.com/u/9607754?v=4","gravatar_id":"","url":"https://api.github.com/users/greenelab","html_url":"https://github.com/greenelab","followers_url":"https://api.github.com/users/greenelab/followers","following_url":"https://api.github.com/users/greenelab/following{/other_user}","gists_url":"https://api.github.com/users/greenelab/gists{/gist_id}","starred_url":"https://api.github.com/users/greenelab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/greenelab/subscriptions","organizations_url":"https://api.github.com/users/greenelab/orgs","repos_url":"https://api.github.com/users/greenelab/repos","events_url":"https://api.github.com/users/greenelab/events{/privacy}","received_events_url":"https://api.github.com/users/greenelab/received_events","type":"Organization","site_admin":false},"repo":{"id":63903430,"node_id":"MDEwOlJlcG9zaXRvcnk2MzkwMzQzMA==","name":"hetmech","full_name":"greenelab/hetmech","owner":{"login":"greenelab","id":9607754,"node_id":"MDEyOk9yZ2FuaXphdGlvbjk2MDc3NTQ=","avatar_url":"https://avatars1.githubusercontent.com/u/9607754?v=4","gravatar_id":"","url":"https://api.github.com/users/greenelab","html_url":"https://github.com/greenelab","followers_url":"https://api.github.com/users/greenelab/followers","following_url":"https://api.github.com/users/greenelab/following{/other_user}","gists_url":"https://api.github.com/users/greenelab/gists{/gist_id}","starred_url":"https://api.github.com/users/greenelab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/greenelab/subscriptions","organizations_url":"https://api.github.com/users/greenelab/orgs","repos_url":"https://api.github.com/users/greenelab/repos","events_url":"https://api.github.com/users/greenelab/events{/privacy}","received_events_url":"https://api.github.com/users/greenelab/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/greenelab/hetmech","description":"A search engine for hetnets. Matrix implementations of path-count-based measures","fork":false,"url":"https://api.github.com/repos/greenelab/hetmech","forks_url":"https://api.github.com/repos/greenelab/hetmech/forks","keys_url":"https://api.github.com/repos/greenelab/hetmech/keys{/key_id}","collaborators_url":"https://api.github.com/repos/greenelab/hetmech/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/greenelab/hetmech/teams","hooks_url":"https://api.github.com/repos/greenelab/hetmech/hooks","issue_events_url":"https://api.github.com/repos/greenelab/hetmech/issues/events{/number}","events_url":"https://api.github.com/repos/greenelab/hetmech/events","assignees_url":"https://api.github.com/repos/greenelab/hetmech/assignees{/user}","branches_url":"https://api.github.com/repos/greenelab/hetmech/branches{/branch}","tags_url":"https://api.github.com/repos/greenelab/hetmech/tags","blobs_url":"https://api.github.com/repos/greenelab/hetmech/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/greenelab/hetmech/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/greenelab/hetmech/git/refs{/sha}","trees_url":"https://api.github.com/repos/greenelab/hetmech/git/trees{/sha}","statuses_url":"https://api.github.com/repos/greenelab/hetmech/statuses/{sha}","languages_url":"https://api.github.com/repos/greenelab/hetmech/languages","stargazers_url":"https://api.github.com/repos/greenelab/hetmech/stargazers","contributors_url":"https://api.github.com/repos/greenelab/hetmech/contributors","subscribers_url":"https://api.github.com/repos/greenelab/hetmech/subscribers","subscription_url":"https://api.github.com/repos/greenelab/hetmech/subscription","commits_url":"https://api.github.com/repos/greenelab/hetmech/commits{/sha}","git_commits_url":"https://api.github.com/repos/greenelab/hetmech/git/commits{/sha}","comments_url":"https://api.github.com/repos/greenelab/hetmech/comments{/number}","issue_comment_url":"https://api.github.com/repos/greenelab/hetmech/issues/comments{/number}","contents_url":"https://api.github.com/repos/greenelab/hetmech/contents/{+path}","compare_url":"https://api.github.com/repos/greenelab/hetmech/compare/{base}...{head}","merges_url":"https://api.github.com/repos/greenelab/hetmech/merges","archive_url":"https://api.github.com/repos/greenelab/hetmech/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/greenelab/hetmech/downloads","issues_url":"https://api.github.com/repos/greenelab/hetmech/issues{/number}","pulls_url":"https://api.github.com/repos/greenelab/hetmech/pulls{/number}","milestones_url":"https://api.github.com/repos/greenelab/hetmech/milestones{/number}","notifications_url":"https://api.github.com/repos/greenelab/hetmech/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/greenelab/hetmech/labels{/name}","releases_url":"https://api.github.com/repos/greenelab/hetmech/releases{/id}","deployments_url":"https://api.github.com/repos/greenelab/hetmech/deployments","created_at":"2016-07-21T21:25:53Z","updated_at":"2018-05-25T19:27:53Z","pushed_at":"2018-06-04T13:24:58Z","git_url":"git://github.com/greenelab/hetmech.git","ssh_url":"git@github.com:greenelab/hetmech.git","clone_url":"https://github.com/greenelab/hetmech.git","svn_url":"https://github.com/greenelab/hetmech","homepage":"","size":10478,"stargazers_count":6,"watchers_count":6,"language":"Jupyter Notebook","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"archived":false,"open_issues_count":7,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":5,"open_issues":7,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/greenelab/hetmech/pulls/112"},"html":{"href":"https://github.com/greenelab/hetmech/pull/112"},"issue":{"href":"https://api.github.com/repos/greenelab/hetmech/issues/112"},"comments":{"href":"https://api.github.com/repos/greenelab/hetmech/issues/112/comments"},"review_comments":{"href":"https://api.github.com/repos/greenelab/hetmech/pulls/112/comments"},"review_comment":{"href":"https://api.github.com/repos/greenelab/hetmech/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/greenelab/hetmech/pulls/112/commits"},"statuses":{"href":"https://api.github.com/repos/greenelab/hetmech/statuses/f5ac52f7649f944a44f85e015a52f03f64290018"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"dhimmel"}}