# Multidimensional Sparse GP

**URL:** <https://discourse.pymc.io/t/multidimensional-sparse-gp/7125>\
**Category:** Questions\
**Tags:** theano\
**Created:** [March 31, 2021, 1:59pm UTC](https://discourse.pymc.io/t/multidimensional-sparse-gp/7125 "2021-03-31T13:59:47Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![BlueMan66](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/blueman66/32/2924_2.png) [@BlueMan66](https://discourse.pymc.io/u/BlueMan66)\
**Post date:** [March 31, 2021, 1:59pm UTC](https://discourse.pymc.io/t/multidimensional-sparse-gp/7125/1 "2021-03-31T13:59:47Z")

</div>

Hey! I’m trying to implement a multidimensional sparse GP but I’m unsure about the syntax for passing arguments to the marginal likelihood function. I’ve managed the following:

` with pm.Model() as model:

```
        ℓ = pm.HalfNormal('ℓ', sigma=5)

        lenght_scale_x = pm.HalfNormal('lenght_scale x', sigma=5)

        lenght_scale_c = pm.HalfNormal('lenght_scale c', sigma=5)

        η = pm.HalfCauchy("η", beta=5)

        cov = η**2 * \

            pm.gp.cov.Exponential(1, ls=lenght_scale_c) * \

            pm.gp.cov.Periodic(1, period=ℓ, ls=lenght_scale_x)

        σ = pm.HalfNormal("σ", sigma=0.1)

        gp = pm.gp.MarginalSparse(cov_func = cov, approx="FITC")

        # Inducing points for the sparse aproximation

        Xu = pm.Uniform("Xu",lower = 0, upper = X_1.max(),

                        shape=(10,))

        C_u = pm.Uniform("C_u",lower = 1e-8, upper = c.max(),

                shape=(10,))

        input_u = tt.concatenate([Xu, C_u], axis = 1)

        y_ = gp.marginal_likelihood("y", X=input_1, Xu=input_u, y=f_true, noise=σ)`

```

Which gives the following error:  
`ValueError: Join argument "axis" is out of range (given input dimensions)`  
I’ve tried transposing the arrays entering input\_u and transposing input\_u but it doesn’t seem to work that way.  
Also, is the cov function correctly defined? I started this using a kronecker covariance and thought it would be usefull to define the cov func this way when trying to implement the sparse approximation.  
Any help would be highly appreciated!

---

<div class="post-metadata">

**Author:** ![ckrapu](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/ckrapu/32/1366_2.png) [@ckrapu](https://discourse.pymc.io/u/ckrapu)\
**Post date:** [April 1, 2021, 4:28am UTC](https://discourse.pymc.io/t/multidimensional-sparse-gp/7125/2 "2021-04-01T04:28:58Z")

</div>

Could you describe your desired model a little more? At first glance, it looks like your covariance functions don’t have the `active_dims` argument specified. It appears to me that you desire to have an exponential kernel over the first dimension and a periodic kernel over the second dimension. Is that right?

Also, if you could supply some data, real or simulated so that we could run your example, that would be really helpful!

---

<div class="post-metadata">

**Author:** ![BlueMan66](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/blueman66/32/2924_2.png) [@BlueMan66](https://discourse.pymc.io/u/BlueMan66)\
**Post date:** [April 1, 2021, 10:57pm UTC](https://discourse.pymc.io/t/multidimensional-sparse-gp/7125/3 "2021-04-01T22:57:57Z")

</div>

Thanks for the reply! I’m trying to calibrate a FEM model for the Euler-Bernoulli Equation using the framework by Kennedy & O’Hagan [(The paper in question)](https://www.asc.ohio-state.edu/statistics/comp_exp/jour.club/KennedyOHagan.pdf). The first step of the process is to obtain the parameters of a GP of the computer model with it’s dimensions being time and various physical parameters. Here I’m only trying to use the viscous dampening parameter as an extra dimension.  
Since this problem is bound to scale pourly when increasing the number of dimensions being used I wanted to implement some of the methods used for improving scalling like the sparse approximation.  
In the uploaded file is a reproduction of what I want to achieve with the model (using a dummy equation to generate model data)  
[KOH\_Example.py](https://discourse.pymc.io/uploads/short-url/lXXw5AYRDDBduFbnSLZh0kPl2Rv.py) (2.8 KB)  
Thanks again!!

---

<div class="post-metadata">

**Author:** ![BlueMan66](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/blueman66/32/2924_2.png) [@BlueMan66](https://discourse.pymc.io/u/BlueMan66)\
**Post date:** [April 2, 2021, 10:58pm UTC](https://discourse.pymc.io/t/multidimensional-sparse-gp/7125/4 "2021-04-02T22:58:15Z")

</div>

Bump cause of urgency! 🙃

---

<div class="post-metadata">

**Author:** ![ckrapu](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/ckrapu/32/1366_2.png) [@ckrapu](https://discourse.pymc.io/u/ckrapu)\
**Post date:** [April 4, 2021, 5:18pm UTC](https://discourse.pymc.io/t/multidimensional-sparse-gp/7125/5 "2021-04-04T17:18:15Z")

</div>

I’ve never seen a model with latent inducing points before. Is that something that can be handled in PyMC3? @bwengals

---

<div class="post-metadata">

**Author:** ![bwengals](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/bwengals/32/1237_2.png) [@bwengals](https://discourse.pymc.io/u/bwengals)\
**Post date:** [April 8, 2021, 4:42pm UTC](https://discourse.pymc.io/t/multidimensional-sparse-gp/7125/6 "2021-04-08T16:42:51Z")

</div>

Not sure if this is the underlying problem, but I tried adding the concatenate to KOH\_example.py

```auto
    input_1 = [X_1.reshape(-1, 1), c.reshape(-1, 1)]
    input_1 = np.concatenate(input_1, axis=1)

```

and the model sampled after that without errors (not sure if the traces are OK). Does this help?

---

<div class="post-metadata">

**Author:** ![BlueMan66](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/blueman66/32/2924_2.png) [@BlueMan66](https://discourse.pymc.io/u/BlueMan66)\
**Post date:** [April 8, 2021, 5:34pm UTC](https://discourse.pymc.io/t/multidimensional-sparse-gp/7125/7 "2021-04-08T17:34:47Z")

</div>

Yes!! This Helps, Thanks!!!

---

<div class="post-metadata">

**Author:** ![bwengals](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/bwengals/32/1237_2.png) [@bwengals](https://discourse.pymc.io/u/bwengals)\
**Post date:** [April 8, 2021, 10:13pm UTC](https://discourse.pymc.io/t/multidimensional-sparse-gp/7125/8 "2021-04-08T22:13:04Z")

</div>

Yep you could, the code won’t break. Not sure if it would work well though, there may be a reason it’s not common

---

<div class="post-metadata">

**Author:** ![BlueMan66](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/blueman66/32/2924_2.png) [@BlueMan66](https://discourse.pymc.io/u/BlueMan66)\
**Post date:** [April 9, 2021, 1:02am UTC](https://discourse.pymc.io/t/multidimensional-sparse-gp/7125/9 "2021-04-09T01:02:56Z")

</div>

Just to confirm if I instead want to use the kmeans algorithm I must specify a Xu object for each dimension and then concatenate both using Theano?

---

<div class="post-metadata">

**Author:** ![bwengals](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/bwengals/32/1237_2.png) [@bwengals](https://discourse.pymc.io/u/bwengals)\
**Post date:** [April 9, 2021, 7:03pm UTC](https://discourse.pymc.io/t/multidimensional-sparse-gp/7125/10 "2021-04-09T19:03:38Z")

</div>

Yep that would work. I’d definitely try Kmeans here. You won’t need to split by dimension though, Kmeans will work just fine across Xu (barring curse of dimensionality type problems).
