diff --git a/tensorflow_probability/python/experimental/psd_kernels/BUILD b/tensorflow_probability/python/experimental/psd_kernels/BUILD index 3c4ff761d4..753d119e67 100644 --- a/tensorflow_probability/python/experimental/psd_kernels/BUILD +++ b/tensorflow_probability/python/experimental/psd_kernels/BUILD @@ -32,10 +32,45 @@ multi_substrate_py_library( name = "psd_kernels", srcs = ["__init__.py"], deps = [ + ":additive_kernel", ":multitask_kernel", ], ) +multi_substrate_py_library( + name = "additive_kernel", + srcs = ["additive_kernel.py"], + deps = [ + # tensorflow dep, + "//tensorflow_probability/python/internal:distribution_util", + "//tensorflow_probability/python/internal:parameter_properties", + "//tensorflow_probability/python/internal:prefer_static", + "//tensorflow_probability/python/internal:tensor_util", + "//tensorflow_probability/python/math/psd_kernels:exponentiated_quadratic", + "//tensorflow_probability/python/math/psd_kernels:feature_transformed", + "//tensorflow_probability/python/math/psd_kernels:matern", + "//tensorflow_probability/python/math/psd_kernels:positive_semidefinite_kernel", + "//tensorflow_probability/python/math/psd_kernels/internal:util", + ], +) + +multi_substrate_py_test( + name = "additive_kernel_test", + size = "medium", + srcs = ["additive_kernel_test.py"], + jax_tags = ["notap"], + numpy_tags = ["notap"], + shard_count = 4, + tags = ["tf1-broken"], + deps = [ + # absl/testing:parameterized dep, + # numpy dep, + # tensorflow dep, + "//tensorflow_probability", + "//tensorflow_probability/python/internal:test_util", + ], +) + multi_substrate_py_library( name = "multitask_kernel", srcs = ["multitask_kernel.py"], diff --git a/tensorflow_probability/python/experimental/psd_kernels/__init__.py b/tensorflow_probability/python/experimental/psd_kernels/__init__.py index eb76e3b76c..b31a27415f 100644 --- a/tensorflow_probability/python/experimental/psd_kernels/__init__.py +++ b/tensorflow_probability/python/experimental/psd_kernels/__init__.py @@ -18,6 +18,7 @@ from __future__ import division from __future__ import print_function +from tensorflow_probability.python.experimental.psd_kernels.additive_kernel import AdditiveKernel from tensorflow_probability.python.experimental.psd_kernels.multitask_kernel import Independent from tensorflow_probability.python.experimental.psd_kernels.multitask_kernel import MultiTaskKernel from tensorflow_probability.python.experimental.psd_kernels.multitask_kernel import Separable @@ -25,6 +26,7 @@ _allowed_symbols = [ + 'AdditiveKernel', 'Independent', 'MultiTaskKernel', 'Separable', diff --git a/tensorflow_probability/python/experimental/psd_kernels/additive_kernel.py b/tensorflow_probability/python/experimental/psd_kernels/additive_kernel.py new file mode 100644 index 0000000000..8e60bb5055 --- /dev/null +++ b/tensorflow_probability/python/experimental/psd_kernels/additive_kernel.py @@ -0,0 +1,215 @@ +# Copyright 2021 The TensorFlow Probability Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +"""Additive kernel.""" + +import tensorflow.compat.v2 as tf + +from tensorflow_probability.python.internal import dtype_util +from tensorflow_probability.python.internal import parameter_properties +from tensorflow_probability.python.internal import prefer_static as ps +from tensorflow_probability.python.internal import tensor_util +from tensorflow_probability.python.math.psd_kernels import positive_semidefinite_kernel as psd_kernel +from tensorflow_probability.python.math.psd_kernels.internal import util + + +__all__ = [ + 'AdditiveKernel', +] + + +class AdditiveKernel(psd_kernel.AutoCompositeTensorPsdKernel): + """Additive Kernel. + + This kernel has the following form + ```none + k(x, y) = sum k_add_i(x, y) + k_add_n(x, y) = a_n**2 sum_{1<=i1