# Scaling covariance function in Gaussian Processes

**URL:** https://discourse.pymc.io/t/scaling-covariance-function-in-gaussian-processes/4013
**Category:** Questions
**Created:** [October 24, 2019, 9:26am UTC](https://discourse.pymc.io/t/scaling-covariance-function-in-gaussian-processes/4013 "2019-10-24T09:26:30Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Mcb](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/mcb/32/2274_2.png) [@Mcb](https://discourse.pymc.io/u/Mcb)
#### Post date: [October 24, 2019, 9:26am UTC](https://discourse.pymc.io/t/scaling-covariance-function-in-gaussian-processes/4013/1 "2019-10-24T09:26:30Z")

</div>

Hi,

This one is directed to @bwengals since it’s a direct question on one of his [notebooks](https://bwengals.github.io/gaussian-processes-models.html).

In particular there is a scaling RV σsq\_gp which is multiplied by the overall covariance function.  
Can you expand on the choice for this variable and why it was used?  
Below there is additional context for the model.

```
# define positive normal distribution with a lower bound
BoundedNormal = pm.Bound(pm.Normal, lower=0)
# define gp model in pymc3
with pm.Model() as conjugate_gp:
    σsq_gp = pm.HalfCauchy("σsq_gp", beta=2) # scales the covariance function    
    ℓ = BoundedNormal("ℓ", mu=0.5, sd=1) # lengthscale of the covariance function (weakly informative)

    k = σsq_gp * pm.gp.cov.Matern52(1, ℓ) # the covariance function
    ....

```

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: [October 24, 2019, 4:17pm UTC](https://discourse.pymc.io/t/scaling-covariance-function-in-gaussian-processes/4013/2 "2019-10-24T16:17:33Z")

</div>

That parameters role is to scale the covariance function. It controls the magnitude of the GP. You can try setting up a GP prior with different values of that parameter and see what the function samples look like to see how it affects things.

I’d want to refer you to the pymc3 documentation and examples, the code on that blog is extremely out of date.

---

<div class="post-metadata">

### Author: ![Mcb](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/mcb/32/2274_2.png) [@Mcb](https://discourse.pymc.io/u/Mcb)
#### Post date: [October 28, 2019, 9:45am UTC](https://discourse.pymc.io/t/scaling-covariance-function-in-gaussian-processes/4013/3 "2019-10-28T09:45:37Z")

</div>

Thanks for the input.  
I’m somewhat familiar with the examples on the pymc3 docs. Great stuff by the way.

I was wondering if the scaling factor was following a formal rule to control the GP.

---

<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: [October 28, 2019, 2:48pm UTC](https://discourse.pymc.io/t/scaling-covariance-function-in-gaussian-processes/4013/4 "2019-10-28T14:48:33Z")

</div>

Yes it is. It comes from the rules for constructing kernels. Multiplying a kernel (or covariance function) by some function a(x) is a valid kernel: a(x) k(x, x') a(x'), so to design a changepoint a(x) you can use a sigmoid function for a(x).
