# Comparing Manual and PYMC ExpQuad Kernel Function : DIFFERENT RESULTS

**URL:** <https://discourse.pymc.io/t/comparing-manual-and-pymc-expquad-kernel-function-different-results/11281>\
**Category:** v5\
**Tags:** gaussian\_process\
**Created:** [January 28, 2023, 9:34am UTC](https://discourse.pymc.io/t/comparing-manual-and-pymc-expquad-kernel-function-different-results/11281 "2023-01-28T09:34:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![roesta07](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/roesta07/32/6060_2.png) [@roesta07](https://discourse.pymc.io/u/roesta07)\
**Post date:** [January 28, 2023, 9:34am UTC](https://discourse.pymc.io/t/comparing-manual-and-pymc-expquad-kernel-function-different-results/11281/1 "2023-01-28T09:34:33Z")

</div>

Hi all;  
I am trying to explore Pymc’s Gp class.

and I am having a hard time replicating Mclearth’s estimates from Gaussian Process (island example).  
As I believe that using PYMC’s expEquad kernel function (below equation) is providing different estimates than when calculated manually, which led to loss in precision.

This is ExpEquad kernel function which I am trying to replicate…  
 ![latex_kernel](https://canada1.discourse-cdn.com/flex036/uploads/pymc3/original/2X/c/c37005ff72ee7f353e44d044847c1d0e735038b6.gif)

**USING PYMC’S ExpQuad**

```auto
# Dmat is some Distance Matrix ; source link below
ls=1 ## lets assume ls be 1
gp_object=pm.gp.cov.ExpQuad(input_dim=1,ls=1)
np.round(gp_object.full(X=Dmat).eval(),2)

array([[1. , 0.89, 0.82, 0. , 0.47, 0.13, 0.01, 0.02, 0.18, 0.],
       [0.89, 1. , 0.99, 0. , 0.75, 0.3 , 0.03, 0.07, 0.38, 0.],
       [0.82, 0.99, 1. , 0. , 0.83, 0.37, 0.04, 0.1 , 0.47, 0.],
       [0. , 0. , 0. , 1. , 0.01, 0.07, 0.5 , 0.29, 0.04, 0.42],
       [0.47, 0.75, 0.83, 0.01, 1. , 0.72, 0.15, 0.3 , 0.82, 0.],
       [0.13, 0.3 , 0.37, 0.07, 0.72, 1. , 0.52, 0.75, 0.98, 0.],
       [0.01, 0.03, 0.04, 0.5 , 0.15, 0.52, 1. , 0.93, 0.42, 0.04],
       [0.02, 0.07, 0.1 , 0.29, 0.3 , 0.75, 0.93, 1. , 0.65, 0.02],
       [0.18, 0.38, 0.47, 0.04, 0.82, 0.98, 0.42, 0.65, 1. , 0.],
       [0. , 0. , 0. , 0.42, 0. , 0. , 0.04, 0.02, 0. , 1.]])

```

**Calculating manually**

```auto
ls=1 # lets ls=1 for this too
Dmatsq=np.power(Dmat,2)
np.round(np.exp(-0.5*Dmatsq/ls),2)

array([[1. , 0.89, 0.82, 0. , 0.47, 0.13, 0.01, 0.02, 0.18, 0.],
       [0.89, 1. , 0.95, 0. , 0.47, 0.13, 0.02, 0.03, 0.15, 0.],
       [0.82, 0.95, 1. , 0. , 0.3 , 0.23, 0.04, 0.06, 0.07, 0.],
       [0. , 0. , 0. , 1. , 0. , 0.05, 0.3 , 0.27, 0. , 0.],
       [0.47, 0.47, 0.3 , 0. , 1. , 0.01, 0. , 0. , 0.75, 0.],
       [0.13, 0.13, 0.23, 0.05, 0.01, 1. , 0.2 , 0.7 , 0. , 0.],
       [0.01, 0.02, 0.04, 0.3 , 0. , 0.2 , 1. , 0.48, 0. , 0.],
       [0.02, 0.03, 0.06, 0.27, 0. , 0.7 , 0.48, 1. , 0. , 0.],
       [0.18, 0.15, 0.07, 0. , 0.75, 0. , 0. , 0. , 1. , 0.],
       [0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 1.]])

```

NOTE: When comparing the first row and column these Matrices, they appear to be identical, **but as we move away from these initial positions and examine other rows and columns, we can see that the values start to differ.**

Should this be an issue? Or Did I mis-specify something here?  
Thanks in advance!!

Also link to the Distance matrix(Dmat) is [here.](https://raw.githubusercontent.com/pymc-devs/pymc-resources/main/Rethinking_2/Data/islandsDistMatrix.csv)
