# Multidimensional input using Gaussian Process

**URL:** <https://discourse.pymc.io/t/multidimensional-input-using-gaussian-process/128>\
**Category:** Questions\
**Created:** [June 28, 2017, 1:24am UTC](https://discourse.pymc.io/t/multidimensional-input-using-gaussian-process/128 "2017-06-28T01:24:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![paddyhoran](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/paddyhoran/32/326_2.png) [@paddyhoran](https://discourse.pymc.io/u/paddyhoran)\
**Post date:** [June 28, 2017, 1:24am UTC](https://discourse.pymc.io/t/multidimensional-input-using-gaussian-process/128/1 "2017-06-28T01:24:55Z")

</div>

Hi All,

I’m new to pymc3 and I may be making a stupid mistake but I am trying to build a Gaussian Process Regression model and feed in a 2d input. I have adapted my example from [here](https://blog.dominodatalab.com/fitting-gaussian-process-models-python/):

I have used PCA to preprocess my input and built the following model:

```
number_of_pcs = 2

with pm.Model() as model:

    z = pm.Gamma('z', 1, 1, shape=number_of_pcs)
    nu = pm.Gamma('nu', 1, 1, shape=number_of_pcs)
    K = nu * pm.gp.cov.ExpQuad(number_of_pcs, z)

    mu = pm.gp.mean.Zero()
    sigma = pm.HalfCauchy('sigma', 2.5)

    x = features.iloc[:500, :number_of_pcs].values
    y = y_df.values[:500]

    y_obs = pm.gp.GP('y_obs', mean_func=mu, cov_func=K, sigma=sigma, observed={'X': x, 'Y': y})

```

However, I get the following error:

_ValueError: Input dimension mis-match (input[0].shape[1] = 500, input[1].shape[1] = 2)_

(using X=x, observed=y gives the same error)

This works when number\_of\_pcs = 1, but fails if \> 1.

Any ideas on how I should proceed? Or any examples of a similar model that I can try to learn from?

Thank you in advance.

---

<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:** [June 28, 2017, 2:11am UTC](https://discourse.pymc.io/t/multidimensional-input-using-gaussian-process/128/2 "2017-06-28T02:11:38Z")

</div>

Hey there, this works for me in 1 or higher dimensions:

```
y_obs = pm.gp.GP("y_obs", mean_func=mu, cov_func=K, X=x, sigma=sigma, observed={'X': x, 'Y': y})

```

Notice the addition of `X=x`. Does this syntax work for you? I’m on master and I’m seeing the same behavior as you. I’ll see about a patch for this asap. Thank you for posting this!

---

<div class="post-metadata">

**Author:** ![paddyhoran](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/paddyhoran/32/326_2.png) [@paddyhoran](https://discourse.pymc.io/u/paddyhoran)\
**Post date:** [June 28, 2017, 8:32am UTC](https://discourse.pymc.io/t/multidimensional-input-using-gaussian-process/128/3 "2017-06-28T08:32:27Z")

</div>

Thanks @bwengals,

Unfortunately, that does not work for me it still fails with the same error message (3.1 master). I wasn’t sure it was an issue previously (I thought maybe I had done something wrong), do you want me to open a github issue?

---

<div class="post-metadata">

**Author:** ![paddyhoran](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/paddyhoran/32/326_2.png) [@paddyhoran](https://discourse.pymc.io/u/paddyhoran)\
**Post date:** [June 28, 2017, 10:04am UTC](https://discourse.pymc.io/t/multidimensional-input-using-gaussian-process/128/4 "2017-06-28T10:04:40Z")

</div>

I tracked my issue back to line 122 of gp\[cov.py](http://cov.py).

There’s a list of two factors returned by merge\_factors, but the product cannot be calculated. If I change:

```
K = nu * pm.gp.cov.ExpQuad(number_of_pcs, z)

```

to:

```
K = pm.gp.cov.ExpQuad(number_of_pcs, z)

```

then it works correctly. I tried to figure out the underlying issue but my knowledge of theano is a bit lacking.

---

<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:** [June 28, 2017, 3:22pm UTC](https://discourse.pymc.io/t/multidimensional-input-using-gaussian-process/128/5 "2017-06-28T15:22:09Z")

</div>

ah! I think see it now.

```
nu = pm.Gamma('nu', 1, 1, shape=number_of_pcs)
K = nu * pm.gp.cov.ExpQuad(number_of_pcs, z)

```

`nu` should be a scalar since its role is to scale the covariance matrix, but you have it defined as a vector of random variables. Try removing the `shape=number_of_pcs` part.

---

<div class="post-metadata">

**Author:** ![paddyhoran](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/paddyhoran/32/326_2.png) [@paddyhoran](https://discourse.pymc.io/u/paddyhoran)\
**Post date:** [June 28, 2017, 6:37pm UTC](https://discourse.pymc.io/t/multidimensional-input-using-gaussian-process/128/6 "2017-06-28T18:37:48Z")

</div>

Oh, ok I see. Thanks for all your help, I understand now (noob mistake…).

---

<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:** [June 28, 2017, 6:39pm UTC](https://discourse.pymc.io/t/multidimensional-input-using-gaussian-process/128/7 "2017-06-28T18:39:20Z")

</div>

No prob! Thanks for posting. I messed with it for quite a while before noticing
