# GPs: sum of independent Kernels

**URL:** <https://discourse.julialang.org/t/gps-sum-of-independent-kernels/98542>\
**Category:** Probabilistic Programming\
**Tags:** gaussian-process, kernel\
**Created:** [May 9, 2023, 11:12am UTC](https://discourse.julialang.org/t/gps-sum-of-independent-kernels/98542 "2023-05-09T11:12:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![martincornejo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/martincornejo/32/13436_2.png) [@martincornejo](https://discourse.julialang.org/u/martincornejo)\
**Post date:** [May 9, 2023, 11:12am UTC](https://discourse.julialang.org/t/gps-sum-of-independent-kernels/98542/1 "2023-05-09T11:12:24Z")

</div>

The documentation of `KernelFunctions.jl` specifies many [building blocks](https://juliagaussianprocesses.github.io/KernelFunctions.jl/stable/kernels/#Composite-Kernels) to define composite Kernels. But I can’t find a way to build a sum of independent Kernels, something similar to the `KernelTensorProduct` but with addition instead of multiplication:

For inputs x = (x\_1,\dots,x\_n) and x' = (x\_1',\dots,x\_n'), the independent sum of kernels k\_1, \dots, k\_n is defined as:

k(x, x'; k\_1, \dots k\_n) = \sum\_{i=1}^n k\_i(x\_i, x\_i')

For similar kernels I think one could use an `ARDTransform`, but if the kernels are different it is as far as I know not possibel. Is there a smart way to do this? Or is this functionality not yet supported?

---

<div class="post-metadata">

**Author:** ![theogf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/theogf/32/1987_2.png) [@theogf](https://discourse.julialang.org/u/theogf)\
**Post date:** [May 9, 2023, 11:29am UTC](https://discourse.julialang.org/t/gps-sum-of-independent-kernels/98542/2 "2023-05-09T11:29:22Z")

</div>

Hey,

It’s true right now there is no way to build that. It generally seems like a good idea though! Could you open an issue on the repo?

If you need a temporary fix, you can use each kernel with a `SelectTransform` and make a sum of them.  
So something like this:

```julia
sum(kernels[i] ∘ SelectTransform([i]) for i in 1:ndims) 

```

---

<div class="post-metadata">

**Author:** ![martincornejo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/martincornejo/32/13436_2.png) [@martincornejo](https://discourse.julialang.org/u/martincornejo)\
**Post date:** [May 10, 2023, 8:00am UTC](https://discourse.julialang.org/t/gps-sum-of-independent-kernels/98542/3 "2023-05-10T08:00:58Z")

</div>

Issue: [Sum of independent kernels · Issue #506 · JuliaGaussianProcesses/KernelFunctions.jl · GitHub](https://github.com/JuliaGaussianProcesses/KernelFunctions.jl/issues/506)
