{"action":"created","comment":{"url":"https://api.github.com/repos/GPflow/GPflow/pulls/comments/187943886","pull_request_review_id":119822222,"id":187943886,"diff_hunk":"@@ -0,0 +1,150 @@\n+# Copyright 2018 GPflow authors\n+#\n+# Licensed under the Apache License, Version 2.0 (the \"License\");\n+# you may not use this file except in compliance with the License.\n+# You may obtain a copy of the License at\n+#\n+# http://www.apache.org/licenses/LICENSE-2.0\n+#\n+# Unless required by applicable law or agreed to in writing, software\n+# distributed under the License is distributed on an \"AS IS\" BASIS,\n+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+# See the License for the specific language governing permissions and\n+# limitations under the License.\n+\n+import tensorflow as tf\n+\n+from .kernels import Mok, SharedIndependentMok, SeparateIndependentMok, SeparateMixedMok\n+from ..features import InducingPoints, InducingFeature, Kuu, Kuf\n+from ..dispatch import dispatch\n+from .. import settings\n+\n+float_type = settings.float_type\n+\n+class Mof(InducingFeature):\n+    \"\"\"\n+    Class used to indicate that we are dealing with\n+    features that are used for multiple outputs.\n+    \"\"\"\n+    pass\n+\n+\n+class SharedIndependentMof(Mof):\n+    \"\"\"\n+    Same feature is used for each output.\n+    \"\"\"\n+    def __init__(self, feat):\n+        Mof.__init__(self)\n+        self.feat = feat\n+\n+    def __len__(self):\n+        return len(self.feat)\n+\n+\n+class SeparateIndependentMof(Mof):\n+    \"\"\"\n+    A different feature is used for each output.\n+    Note: each feature should have the same number of points, M.\n+    \"\"\"\n+    def __init__(self, feat_list):\n+        Mof.__init__(self)\n+        self.feat_list = feat_list\n+\n+    def __len__(self):\n+        return len(self.feat_list[0])\n+\n+\n+class MixedKernelSharedMof(SharedIndependentMof):\n+    \"\"\"\n+    This Mof is used in combination with the `SeparateMixedMok`.\n+    Using this feature with the `SeparateMixedMok` leads to the most efficient code.\n+    \"\"\"\n+    pass\n+\n+\n+# ---------------------------------------------------------------------\n+################################ Kuf ##################################\n+# ---------------------------------------------------------------------\n+\n+@dispatch(InducingPoints, Mok, object)\n+def Kuf(feat, kern, Xnew):\n+    return kern.K(feat.Z, Xnew, full_cov_output=True)  #  M x P x N x P\n+\n+\n+@dispatch(SharedIndependentMof, SharedIndependentMok, object)\n+def Kuf(feat, kern, Xnew):\n+    return Kuf(feat.feat, kern.kern, Xnew)  # M x N\n+\n+\n+@dispatch(SeparateIndependentMof, SharedIndependentMok, object)\n+def Kuf(feat, kern, Xnew):\n+    return tf.stack([Kuf(f, kern.kern, Xnew) for f in feat.feat_list], axis=0)  # L x M x N\n+\n+\n+@dispatch(SharedIndependentMof, SeparateIndependentMok, object)\n+def Kuf(feat, kern, Xnew):\n+    return tf.stack([Kuf(feat.feat, k, Xnew) for k in kern.kern_list], axis=0)  # L x M x N","path":"gpflow/multioutput/features.py","position":86,"original_position":86,"commit_id":"30530529e0442b2c43c03a02046afee6a06e1623","original_commit_id":"30530529e0442b2c43c03a02046afee6a06e1623","user":{"login":"dlqudwns","id":16287662,"avatar_url":"https://avatars3.githubusercontent.com/u/16287662?v=4","gravatar_id":"","url":"https://api.github.com/users/dlqudwns","html_url":"https://github.com/dlqudwns","followers_url":"https://api.github.com/users/dlqudwns/followers","following_url":"https://api.github.com/users/dlqudwns/following{/other_user}","gists_url":"https://api.github.com/users/dlqudwns/gists{/gist_id}","starred_url":"https://api.github.com/users/dlqudwns/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dlqudwns/subscriptions","organizations_url":"https://api.github.com/users/dlqudwns/orgs","repos_url":"https://api.github.com/users/dlqudwns/repos","events_url":"https://api.github.com/users/dlqudwns/events{/privacy}","received_events_url":"https://api.github.com/users/dlqudwns/received_events","type":"User","site_admin":false},"body":"It seems that in master branch Combination kernel is no longer using kern_list and this makes error.","created_at":"2018-05-14T13:01:42Z","updated_at":"2018-05-14T13:01:42Z","html_url":"https://github.com/GPflow/GPflow/pull/724#discussion_r187943886","pull_request_url":"https://api.github.com/repos/GPflow/GPflow/pulls/724","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/GPflow/GPflow/pulls/comments/187943886"},"html":{"href":"https://github.com/GPflow/GPflow/pull/724#discussion_r187943886"},"pull_request":{"href":"https://api.github.com/repos/GPflow/GPflow/pulls/724"}}},"pull_request":{"url":"https://api.github.com/repos/GPflow/GPflow/pulls/724","id":182221373,"html_url":"https://github.com/GPflow/GPflow/pull/724","diff_url":"https://github.com/GPflow/GPflow/pull/724.diff","patch_url":"https://github.com/GPflow/GPflow/pull/724.patch","issue_url":"https://api.github.com/repos/GPflow/GPflow/issues/724","number":724,"state":"open","locked":false,"title":"Multi-output conditionals","user":{"login":"vdutor","id":13780846,"avatar_url":"https://avatars2.githubusercontent.com/u/13780846?v=4","gravatar_id":"","url":"https://api.github.com/users/vdutor","html_url":"https://github.com/vdutor","followers_url":"https://api.github.com/users/vdutor/followers","following_url":"https://api.github.com/users/vdutor/following{/other_user}","gists_url":"https://api.github.com/users/vdutor/gists{/gist_id}","starred_url":"https://api.github.com/users/vdutor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vdutor/subscriptions","organizations_url":"https://api.github.com/users/vdutor/orgs","repos_url":"https://api.github.com/users/vdutor/repos","events_url":"https://api.github.com/users/vdutor/events{/privacy}","received_events_url":"https://api.github.com/users/vdutor/received_events","type":"User","site_admin":false},"body":"Hi,\r\n\r\nThis PR implements a new framework for efficiently calculating (correlated) multi-output conditionals. Previously GPflow treated multi-dimensional outputs completely independent. This PR makes it now possible to deal with correlation between the outputs. We achieve this by using a \"multiple-dispatch\" `conditional` that uses different code paths depending on which type of correlation or structure the model encodes. A user can specify this type of correlation by using specific multi-output kernels and features. The multiple-dispatch `conditional` also allows a user to easily define his/her own `conditional` function. \r\n\r\nIt is important to note that this PR is completely backward compatible. Even more, if a user is not interested in the new multi-output features he/she can safely ignore the entire `multioutput` module.\r\n \r\n### Most important additions:\r\n\r\n1) Introduction of MultiOutputFeatures (`Mof`) and MultiOutputKernels (`Mok`).\r\nThese are used to specify a particular setup of multi-output correlation.\r\n\r\n2) Multiple-dispatch for `conditional`. This allows GPflow to select the most efficient conditional code depending on your choice of `Mof` and `Mok`.\r\n\r\n3) Multiple-dispatch for `Kuu` and `Kuf`. Previously `Kuu(.)` and `Kuf(.)` were member functions of the `feature` class. This became cumbersome as the calculation of `Kuu` and `Kuf` also depends on the kernel used. In line with `conditional` we now also use multiple-dispatch to calculate `Kuu` and `Kuf` for a particular combination of `Mok` and `Mof`.  \r\n\r\n4) The actual maths to efficiently calculate the output-correlated conditional (credits to @markvdw  ) \r\n\r\n5) `sample_conditional` Function that makes sure that the most efficient code is used to get a sample from the conditional distribution.\r\n\r\n6) Minor: we updated a couple of models to use the new multi-output conditional.\r\n\r\n## Minimal Example\r\n\r\n- We created an extended notebook to illustrate the use of the new multi-output framework. Please have a look at `notebooks/multioutput.ipynb`, it contains a couple of informative UML-diagrams and tables.\r\n- The unit tests `tests/test_multioutput.py` should also explain the concept.\r\n\r\nThis snippet shows how you can define a SVGP model that uses a different kernel for each output.\r\n```python\r\nimport gpflow.multioutput.kernels as mk\r\nimport gpflow.multioutput.features as mf\r\n\r\nM, D = 20, 1\r\nX, Y = data()  # N x D, N x P\r\n\r\nkern_list = [RBF(D) + Linear(D) for _ in range(P)]\r\nkernel = mk.SeparateIndependentMok(kern_list)\r\nfeature = mf.SharedIndependentMof(gpf.features.InducingPoints(X[:M,...].copy()))\r\nm = SVGP(X, Y, kernel, gpf.likelihoods.Gaussian(), feat=feature)\r\n```\r\nNote that nothing changes, except that we use a different kernel and feature.\r\n\r\nThis work is done in collaboration with @markvdw  @st-- -- @vincentadam87  @stefanosele ","created_at":"2018-04-17T16:19:34Z","updated_at":"2018-05-14T13:01:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f3f46045c9a80c5d6d42478207b9891807ce4c93","assignee":null,"assignees":[],"requested_reviewers":[{"login":"awav","id":24483645,"avatar_url":"https://avatars0.githubusercontent.com/u/24483645?v=4","gravatar_id":"","url":"https://api.github.com/users/awav","html_url":"https://github.com/awav","followers_url":"https://api.github.com/users/awav/followers","following_url":"https://api.github.com/users/awav/following{/other_user}","gists_url":"https://api.github.com/users/awav/gists{/gist_id}","starred_url":"https://api.github.com/users/awav/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/awav/subscriptions","organizations_url":"https://api.github.com/users/awav/orgs","repos_url":"https://api.github.com/users/awav/repos","events_url":"https://api.github.com/users/awav/events{/privacy}","received_events_url":"https://api.github.com/users/awav/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[{"id":311281379,"url":"https://api.github.com/repos/GPflow/GPflow/labels/enhancement","name":"enhancement","color":"84b6eb","default":true},{"id":894490474,"url":"https://api.github.com/repos/GPflow/GPflow/labels/feature","name":"feature","color":"483591","default":false},{"id":894489160,"url":"https://api.github.com/repos/GPflow/GPflow/labels/in%20review","name":"in review","color":"e280e5","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/GPflow/GPflow/pulls/724/commits","review_comments_url":"https://api.github.com/repos/GPflow/GPflow/pulls/724/comments","review_comment_url":"https://api.github.com/repos/GPflow/GPflow/pulls/comments{/number}","comments_url":"https://api.github.com/repos/GPflow/GPflow/issues/724/comments","statuses_url":"https://api.github.com/repos/GPflow/GPflow/statuses/30530529e0442b2c43c03a02046afee6a06e1623","head":{"label":"GPflow:multidispatch_featureconditionals","ref":"multidispatch_featureconditionals","sha":"30530529e0442b2c43c03a02046afee6a06e1623","user":{"login":"GPflow","id":16667412,"avatar_url":"https://avatars2.githubusercontent.com/u/16667412?v=4","gravatar_id":"","url":"https://api.github.com/users/GPflow","html_url":"https://github.com/GPflow","followers_url":"https://api.github.com/users/GPflow/followers","following_url":"https://api.github.com/users/GPflow/following{/other_user}","gists_url":"https://api.github.com/users/GPflow/gists{/gist_id}","starred_url":"https://api.github.com/users/GPflow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GPflow/subscriptions","organizations_url":"https://api.github.com/users/GPflow/orgs","repos_url":"https://api.github.com/users/GPflow/repos","events_url":"https://api.github.com/users/GPflow/events{/privacy}","received_events_url":"https://api.github.com/users/GPflow/received_events","type":"Organization","site_admin":false},"repo":{"id":49643229,"name":"GPflow","full_name":"GPflow/GPflow","owner":{"login":"GPflow","id":16667412,"avatar_url":"https://avatars2.githubusercontent.com/u/16667412?v=4","gravatar_id":"","url":"https://api.github.com/users/GPflow","html_url":"https://github.com/GPflow","followers_url":"https://api.github.com/users/GPflow/followers","following_url":"https://api.github.com/users/GPflow/following{/other_user}","gists_url":"https://api.github.com/users/GPflow/gists{/gist_id}","starred_url":"https://api.github.com/users/GPflow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GPflow/subscriptions","organizations_url":"https://api.github.com/users/GPflow/orgs","repos_url":"https://api.github.com/users/GPflow/repos","events_url":"https://api.github.com/users/GPflow/events{/privacy}","received_events_url":"https://api.github.com/users/GPflow/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/GPflow/GPflow","description":"Gaussian processes in TensorFlow","fork":false,"url":"https://api.github.com/repos/GPflow/GPflow","forks_url":"https://api.github.com/repos/GPflow/GPflow/forks","keys_url":"https://api.github.com/repos/GPflow/GPflow/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GPflow/GPflow/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GPflow/GPflow/teams","hooks_url":"https://api.github.com/repos/GPflow/GPflow/hooks","issue_events_url":"https://api.github.com/repos/GPflow/GPflow/issues/events{/number}","events_url":"https://api.github.com/repos/GPflow/GPflow/events","assignees_url":"https://api.github.com/repos/GPflow/GPflow/assignees{/user}","branches_url":"https://api.github.com/repos/GPflow/GPflow/branches{/branch}","tags_url":"https://api.github.com/repos/GPflow/GPflow/tags","blobs_url":"https://api.github.com/repos/GPflow/GPflow/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GPflow/GPflow/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GPflow/GPflow/git/refs{/sha}","trees_url":"https://api.github.com/repos/GPflow/GPflow/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GPflow/GPflow/statuses/{sha}","languages_url":"https://api.github.com/repos/GPflow/GPflow/languages","stargazers_url":"https://api.github.com/repos/GPflow/GPflow/stargazers","contributors_url":"https://api.github.com/repos/GPflow/GPflow/contributors","subscribers_url":"https://api.github.com/repos/GPflow/GPflow/subscribers","subscription_url":"https://api.github.com/repos/GPflow/GPflow/subscription","commits_url":"https://api.github.com/repos/GPflow/GPflow/commits{/sha}","git_commits_url":"https://api.github.com/repos/GPflow/GPflow/git/commits{/sha}","comments_url":"https://api.github.com/repos/GPflow/GPflow/comments{/number}","issue_comment_url":"https://api.github.com/repos/GPflow/GPflow/issues/comments{/number}","contents_url":"https://api.github.com/repos/GPflow/GPflow/contents/{+path}","compare_url":"https://api.github.com/repos/GPflow/GPflow/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GPflow/GPflow/merges","archive_url":"https://api.github.com/repos/GPflow/GPflow/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GPflow/GPflow/downloads","issues_url":"https://api.github.com/repos/GPflow/GPflow/issues{/number}","pulls_url":"https://api.github.com/repos/GPflow/GPflow/pulls{/number}","milestones_url":"https://api.github.com/repos/GPflow/GPflow/milestones{/number}","notifications_url":"https://api.github.com/repos/GPflow/GPflow/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GPflow/GPflow/labels{/name}","releases_url":"https://api.github.com/repos/GPflow/GPflow/releases{/id}","deployments_url":"https://api.github.com/repos/GPflow/GPflow/deployments","created_at":"2016-01-14T11:29:24Z","updated_at":"2018-05-13T11:28:24Z","pushed_at":"2018-05-11T11:04:33Z","git_url":"git://github.com/GPflow/GPflow.git","ssh_url":"git@github.com:GPflow/GPflow.git","clone_url":"https://github.com/GPflow/GPflow.git","svn_url":"https://github.com/GPflow/GPflow","homepage":"","size":28652,"stargazers_count":650,"watchers_count":650,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":188,"mirror_url":null,"archived":false,"open_issues_count":44,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":188,"open_issues":44,"watchers":650,"default_branch":"master"}},"base":{"label":"GPflow:master","ref":"master","sha":"bac97289f9c3194f13729eb6b8531b4c6afcaec8","user":{"login":"GPflow","id":16667412,"avatar_url":"https://avatars2.githubusercontent.com/u/16667412?v=4","gravatar_id":"","url":"https://api.github.com/users/GPflow","html_url":"https://github.com/GPflow","followers_url":"https://api.github.com/users/GPflow/followers","following_url":"https://api.github.com/users/GPflow/following{/other_user}","gists_url":"https://api.github.com/users/GPflow/gists{/gist_id}","starred_url":"https://api.github.com/users/GPflow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GPflow/subscriptions","organizations_url":"https://api.github.com/users/GPflow/orgs","repos_url":"https://api.github.com/users/GPflow/repos","events_url":"https://api.github.com/users/GPflow/events{/privacy}","received_events_url":"https://api.github.com/users/GPflow/received_events","type":"Organization","site_admin":false},"repo":{"id":49643229,"name":"GPflow","full_name":"GPflow/GPflow","owner":{"login":"GPflow","id":16667412,"avatar_url":"https://avatars2.githubusercontent.com/u/16667412?v=4","gravatar_id":"","url":"https://api.github.com/users/GPflow","html_url":"https://github.com/GPflow","followers_url":"https://api.github.com/users/GPflow/followers","following_url":"https://api.github.com/users/GPflow/following{/other_user}","gists_url":"https://api.github.com/users/GPflow/gists{/gist_id}","starred_url":"https://api.github.com/users/GPflow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GPflow/subscriptions","organizations_url":"https://api.github.com/users/GPflow/orgs","repos_url":"https://api.github.com/users/GPflow/repos","events_url":"https://api.github.com/users/GPflow/events{/privacy}","received_events_url":"https://api.github.com/users/GPflow/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/GPflow/GPflow","description":"Gaussian processes in TensorFlow","fork":false,"url":"https://api.github.com/repos/GPflow/GPflow","forks_url":"https://api.github.com/repos/GPflow/GPflow/forks","keys_url":"https://api.github.com/repos/GPflow/GPflow/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GPflow/GPflow/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GPflow/GPflow/teams","hooks_url":"https://api.github.com/repos/GPflow/GPflow/hooks","issue_events_url":"https://api.github.com/repos/GPflow/GPflow/issues/events{/number}","events_url":"https://api.github.com/repos/GPflow/GPflow/events","assignees_url":"https://api.github.com/repos/GPflow/GPflow/assignees{/user}","branches_url":"https://api.github.com/repos/GPflow/GPflow/branches{/branch}","tags_url":"https://api.github.com/repos/GPflow/GPflow/tags","blobs_url":"https://api.github.com/repos/GPflow/GPflow/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GPflow/GPflow/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GPflow/GPflow/git/refs{/sha}","trees_url":"https://api.github.com/repos/GPflow/GPflow/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GPflow/GPflow/statuses/{sha}","languages_url":"https://api.github.com/repos/GPflow/GPflow/languages","stargazers_url":"https://api.github.com/repos/GPflow/GPflow/stargazers","contributors_url":"https://api.github.com/repos/GPflow/GPflow/contributors","subscribers_url":"https://api.github.com/repos/GPflow/GPflow/subscribers","subscription_url":"https://api.github.com/repos/GPflow/GPflow/subscription","commits_url":"https://api.github.com/repos/GPflow/GPflow/commits{/sha}","git_commits_url":"https://api.github.com/repos/GPflow/GPflow/git/commits{/sha}","comments_url":"https://api.github.com/repos/GPflow/GPflow/comments{/number}","issue_comment_url":"https://api.github.com/repos/GPflow/GPflow/issues/comments{/number}","contents_url":"https://api.github.com/repos/GPflow/GPflow/contents/{+path}","compare_url":"https://api.github.com/repos/GPflow/GPflow/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GPflow/GPflow/merges","archive_url":"https://api.github.com/repos/GPflow/GPflow/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GPflow/GPflow/downloads","issues_url":"https://api.github.com/repos/GPflow/GPflow/issues{/number}","pulls_url":"https://api.github.com/repos/GPflow/GPflow/pulls{/number}","milestones_url":"https://api.github.com/repos/GPflow/GPflow/milestones{/number}","notifications_url":"https://api.github.com/repos/GPflow/GPflow/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GPflow/GPflow/labels{/name}","releases_url":"https://api.github.com/repos/GPflow/GPflow/releases{/id}","deployments_url":"https://api.github.com/repos/GPflow/GPflow/deployments","created_at":"2016-01-14T11:29:24Z","updated_at":"2018-05-13T11:28:24Z","pushed_at":"2018-05-11T11:04:33Z","git_url":"git://github.com/GPflow/GPflow.git","ssh_url":"git@github.com:GPflow/GPflow.git","clone_url":"https://github.com/GPflow/GPflow.git","svn_url":"https://github.com/GPflow/GPflow","homepage":"","size":28652,"stargazers_count":650,"watchers_count":650,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":188,"mirror_url":null,"archived":false,"open_issues_count":44,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":188,"open_issues":44,"watchers":650,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/GPflow/GPflow/pulls/724"},"html":{"href":"https://github.com/GPflow/GPflow/pull/724"},"issue":{"href":"https://api.github.com/repos/GPflow/GPflow/issues/724"},"comments":{"href":"https://api.github.com/repos/GPflow/GPflow/issues/724/comments"},"review_comments":{"href":"https://api.github.com/repos/GPflow/GPflow/pulls/724/comments"},"review_comment":{"href":"https://api.github.com/repos/GPflow/GPflow/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/GPflow/GPflow/pulls/724/commits"},"statuses":{"href":"https://api.github.com/repos/GPflow/GPflow/statuses/30530529e0442b2c43c03a02046afee6a06e1623"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"dlqudwns"}}