# 2. 2-D example with 1 parameters

The following example shows how to construct the kernel, automatically, from a symbolic expression defining the linear differential operator in **2D**.

We consider the following operator, for an unknwon *u*

$$
\mathcal{L}^{\phi} u := \phi u + \partial_x u + \partial_{yy} u
$$


```python
# imports
from mlhiphy.calculus import dx, dy, dz
from mlhiphy.calculus import Constant
from mlhiphy.calculus import Unknown
from mlhiphy.kernels import compute_kernel, generic_kernel

from sympy import expand
from sympy import symbols
from sympy import exp
from sympy import Tuple
```


```python
x, x_i, x_j = symbols('x x_i x_j')
y, y_i, y_j = symbols('y y_i y_j')

X  = Tuple(x,y)
X_i = Tuple(x_i,y_i)
X_j = Tuple(x_j,y_j)

u = Unknown('u')

phi = Constant('phi')
theta_1 = Constant('theta_1')
theta_2 = Constant('theta_2')

expr = phi * u + dx(u) + dy(dy(u))
```


```python
kuu = generic_kernel(expr, u, (X_i, X_j))
```


```python
from IPython.display import Math
from sympy import latex

Math(latex(expand(kuu)))
```




$$\phi^{2} u{\left (x_{i},y_{i},x_{j},y_{j} \right )} + \phi \frac{\partial}{\partial x_{i}} u{\left (x_{i},y_{i},x_{j},y_{j} \right )} + \phi \frac{\partial}{\partial x_{j}} u{\left (x_{i},y_{i},x_{j},y_{j} \right )} + \phi \frac{\partial^{2}}{\partial y_{i}^{2}}  u{\left (x_{i},y_{i},x_{j},y_{j} \right )} + \phi \frac{\partial^{2}}{\partial y_{j}^{2}}  u{\left (x_{i},y_{i},x_{j},y_{j} \right )} + \frac{\partial^{2}}{\partial x_{i}\partial x_{j}}  u{\left (x_{i},y_{i},x_{j},y_{j} \right )} + \frac{\partial^{3}}{\partial x_{i}\partial y_{j}^{2}}  u{\left (x_{i},y_{i},x_{j},y_{j} \right )} + \frac{\partial^{3}}{\partial x_{j}\partial y_{i}^{2}}  u{\left (x_{i},y_{i},x_{j},y_{j} \right )} + \frac{\partial^{4}}{\partial y_{i}^{2}\partial y_{j}^{2}}  u{\left (x_{i},y_{i},x_{j},y_{j} \right )}$$




```python
# RBF kernel

kuu = exp(- theta_1 * (x_i - x_j)**2 - theta_2 * (y_i - y_j)**2)

kuf = compute_kernel(expr, kuu, X_i)
kfu = compute_kernel(expr, kuu, X_j)
kff = compute_kernel(expr, kuu, (X_i, X_j))
```


```python
Math(latex(expand(kuf)))
```




$$\phi u{\left (x_{i},y_{i} \right )} - 2 \theta_{1} x_{i} e^{- \theta_{1} x_{i}^{2}} e^{- \theta_{1} x_{j}^{2}} e^{- \theta_{2} y_{i}^{2}} e^{- \theta_{2} y_{j}^{2}} e^{2 \theta_{1} x_{i} x_{j}} e^{2 \theta_{2} y_{i} y_{j}} + 2 \theta_{1} x_{j} e^{- \theta_{1} x_{i}^{2}} e^{- \theta_{1} x_{j}^{2}} e^{- \theta_{2} y_{i}^{2}} e^{- \theta_{2} y_{j}^{2}} e^{2 \theta_{1} x_{i} x_{j}} e^{2 \theta_{2} y_{i} y_{j}} + 4 \theta_{2}^{2} y_{i}^{2} e^{- \theta_{1} x_{i}^{2}} e^{- \theta_{1} x_{j}^{2}} e^{- \theta_{2} y_{i}^{2}} e^{- \theta_{2} y_{j}^{2}} e^{2 \theta_{1} x_{i} x_{j}} e^{2 \theta_{2} y_{i} y_{j}} - 8 \theta_{2}^{2} y_{i} y_{j} e^{- \theta_{1} x_{i}^{2}} e^{- \theta_{1} x_{j}^{2}} e^{- \theta_{2} y_{i}^{2}} e^{- \theta_{2} y_{j}^{2}} e^{2 \theta_{1} x_{i} x_{j}} e^{2 \theta_{2} y_{i} y_{j}} + 4 \theta_{2}^{2} y_{j}^{2} e^{- \theta_{1} x_{i}^{2}} e^{- \theta_{1} x_{j}^{2}} e^{- \theta_{2} y_{i}^{2}} e^{- \theta_{2} y_{j}^{2}} e^{2 \theta_{1} x_{i} x_{j}} e^{2 \theta_{2} y_{i} y_{j}} - 2 \theta_{2} e^{- \theta_{1} x_{i}^{2}} e^{- \theta_{1} x_{j}^{2}} e^{- \theta_{2} y_{i}^{2}} e^{- \theta_{2} y_{j}^{2}} e^{2 \theta_{1} x_{i} x_{j}} e^{2 \theta_{2} y_{i} y_{j}}$$




```python
Math(latex(expand(kfu)))
```




$$\phi u{\left (x_{j},y_{j} \right )} + 2 \theta_{1} x_{i} e^{- \theta_{1} x_{i}^{2}} e^{- \theta_{1} x_{j}^{2}} e^{- \theta_{2} y_{i}^{2}} e^{- \theta_{2} y_{j}^{2}} e^{2 \theta_{1} x_{i} x_{j}} e^{2 \theta_{2} y_{i} y_{j}} - 2 \theta_{1} x_{j} e^{- \theta_{1} x_{i}^{2}} e^{- \theta_{1} x_{j}^{2}} e^{- \theta_{2} y_{i}^{2}} e^{- \theta_{2} y_{j}^{2}} e^{2 \theta_{1} x_{i} x_{j}} e^{2 \theta_{2} y_{i} y_{j}} + 4 \theta_{2}^{2} y_{i}^{2} e^{- \theta_{1} x_{i}^{2}} e^{- \theta_{1} x_{j}^{2}} e^{- \theta_{2} y_{i}^{2}} e^{- \theta_{2} y_{j}^{2}} e^{2 \theta_{1} x_{i} x_{j}} e^{2 \theta_{2} y_{i} y_{j}} - 8 \theta_{2}^{2} y_{i} y_{j} e^{- \theta_{1} x_{i}^{2}} e^{- \theta_{1} x_{j}^{2}} e^{- \theta_{2} y_{i}^{2}} e^{- \theta_{2} y_{j}^{2}} e^{2 \theta_{1} x_{i} x_{j}} e^{2 \theta_{2} y_{i} y_{j}} + 4 \theta_{2}^{2} y_{j}^{2} e^{- \theta_{1} x_{i}^{2}} e^{- \theta_{1} x_{j}^{2}} e^{- \theta_{2} y_{i}^{2}} e^{- \theta_{2} y_{j}^{2}} e^{2 \theta_{1} x_{i} x_{j}} e^{2 \theta_{2} y_{i} y_{j}} - 2 \theta_{2} e^{- \theta_{1} x_{i}^{2}} e^{- \theta_{1} x_{j}^{2}} e^{- \theta_{2} y_{i}^{2}} e^{- \theta_{2} y_{j}^{2}} e^{2 \theta_{1} x_{i} x_{j}} e^{2 \theta_{2} y_{i} y_{j}}$$




```python
Math(latex(expand(kff)))
```




$$\phi^{2} u{\left (x_{i},y_{i},x_{j},y_{j} \right )} - 2 \phi \theta_{1} x_{i} e^{- \theta_{1} x_{i}^{2}} e^{- \theta_{1} x_{j}^{2}} e^{- \theta_{2} y_{i}^{2}} e^{- \theta_{2} y_{j}^{2}} e^{2 \theta_{1} x_{i} x_{j}} e^{2 \theta_{2} y_{i} y_{j}} + 2 \phi \theta_{1} x_{j} e^{- \theta_{1} x_{i}^{2}} e^{- \theta_{1} x_{j}^{2}} e^{- \theta_{2} y_{i}^{2}} e^{- \theta_{2} y_{j}^{2}} e^{2 \theta_{1} x_{i} x_{j}} e^{2 \theta_{2} y_{i} y_{j}} + 8 \phi \theta_{2}^{2} y_{i}^{2} e^{- \theta_{1} x_{i}^{2}} e^{- \theta_{1} x_{j}^{2}} e^{- \theta_{2} y_{i}^{2}} e^{- \theta_{2} y_{j}^{2}} e^{2 \theta_{1} x_{i} x_{j}} e^{2 \theta_{2} y_{i} y_{j}} - 16 \phi \theta_{2}^{2} y_{i} y_{j} e^{- \theta_{1} x_{i}^{2}} e^{- \theta_{1} x_{j}^{2}} e^{- \theta_{2} y_{i}^{2}} e^{- \theta_{2} y_{j}^{2}} e^{2 \theta_{1} x_{i} x_{j}} e^{2 \theta_{2} y_{i} y_{j}} + 8 \phi \theta_{2}^{2} y_{j}^{2} e^{- \theta_{1} x_{i}^{2}} e^{- \theta_{1} x_{j}^{2}} e^{- \theta_{2} y_{i}^{2}} e^{- \theta_{2} y_{j}^{2}} e^{2 \theta_{1} x_{i} x_{j}} e^{2 \theta_{2} y_{i} y_{j}} - 4 \phi \theta_{2} e^{- \theta_{1} x_{i}^{2}} e^{- \theta_{1} x_{j}^{2}} e^{- \theta_{2} y_{i}^{2}} e^{- \theta_{2} y_{j}^{2}} e^{2 \theta_{1} x_{i} x_{j}} e^{2 \theta_{2} y_{i} y_{j}} + \phi \frac{\partial}{\partial x_{j}} u{\left (x_{i},y_{i},x_{j},y_{j} \right )} - 4 \theta_{1}^{2} x_{i}^{2} e^{- \theta_{1} x_{i}^{2}} e^{- \theta_{1} x_{j}^{2}} e^{- \theta_{2} y_{i}^{2}} e^{- \theta_{2} y_{j}^{2}} e^{2 \theta_{1} x_{i} x_{j}} e^{2 \theta_{2} y_{i} y_{j}} + 8 \theta_{1}^{2} x_{i} x_{j} e^{- \theta_{1} x_{i}^{2}} e^{- \theta_{1} x_{j}^{2}} e^{- \theta_{2} y_{i}^{2}} e^{- \theta_{2} y_{j}^{2}} e^{2 \theta_{1} x_{i} x_{j}} e^{2 \theta_{2} y_{i} y_{j}} - 4 \theta_{1}^{2} x_{j}^{2} e^{- \theta_{1} x_{i}^{2}} e^{- \theta_{1} x_{j}^{2}} e^{- \theta_{2} y_{i}^{2}} e^{- \theta_{2} y_{j}^{2}} e^{2 \theta_{1} x_{i} x_{j}} e^{2 \theta_{2} y_{i} y_{j}} + 2 \theta_{1} e^{- \theta_{1} x_{i}^{2}} e^{- \theta_{1} x_{j}^{2}} e^{- \theta_{2} y_{i}^{2}} e^{- \theta_{2} y_{j}^{2}} e^{2 \theta_{1} x_{i} x_{j}} e^{2 \theta_{2} y_{i} y_{j}} + 16 \theta_{2}^{4} y_{i}^{4} e^{- \theta_{1} x_{i}^{2}} e^{- \theta_{1} x_{j}^{2}} e^{- \theta_{2} y_{i}^{2}} e^{- \theta_{2} y_{j}^{2}} e^{2 \theta_{1} x_{i} x_{j}} e^{2 \theta_{2} y_{i} y_{j}} - 64 \theta_{2}^{4} y_{i}^{3} y_{j} e^{- \theta_{1} x_{i}^{2}} e^{- \theta_{1} x_{j}^{2}} e^{- \theta_{2} y_{i}^{2}} e^{- \theta_{2} y_{j}^{2}} e^{2 \theta_{1} x_{i} x_{j}} e^{2 \theta_{2} y_{i} y_{j}} + 96 \theta_{2}^{4} y_{i}^{2} y_{j}^{2} e^{- \theta_{1} x_{i}^{2}} e^{- \theta_{1} x_{j}^{2}} e^{- \theta_{2} y_{i}^{2}} e^{- \theta_{2} y_{j}^{2}} e^{2 \theta_{1} x_{i} x_{j}} e^{2 \theta_{2} y_{i} y_{j}} - 64 \theta_{2}^{4} y_{i} y_{j}^{3} e^{- \theta_{1} x_{i}^{2}} e^{- \theta_{1} x_{j}^{2}} e^{- \theta_{2} y_{i}^{2}} e^{- \theta_{2} y_{j}^{2}} e^{2 \theta_{1} x_{i} x_{j}} e^{2 \theta_{2} y_{i} y_{j}} + 16 \theta_{2}^{4} y_{j}^{4} e^{- \theta_{1} x_{i}^{2}} e^{- \theta_{1} x_{j}^{2}} e^{- \theta_{2} y_{i}^{2}} e^{- \theta_{2} y_{j}^{2}} e^{2 \theta_{1} x_{i} x_{j}} e^{2 \theta_{2} y_{i} y_{j}} - 48 \theta_{2}^{3} y_{i}^{2} e^{- \theta_{1} x_{i}^{2}} e^{- \theta_{1} x_{j}^{2}} e^{- \theta_{2} y_{i}^{2}} e^{- \theta_{2} y_{j}^{2}} e^{2 \theta_{1} x_{i} x_{j}} e^{2 \theta_{2} y_{i} y_{j}} + 96 \theta_{2}^{3} y_{i} y_{j} e^{- \theta_{1} x_{i}^{2}} e^{- \theta_{1} x_{j}^{2}} e^{- \theta_{2} y_{i}^{2}} e^{- \theta_{2} y_{j}^{2}} e^{2 \theta_{1} x_{i} x_{j}} e^{2 \theta_{2} y_{i} y_{j}} - 48 \theta_{2}^{3} y_{j}^{2} e^{- \theta_{1} x_{i}^{2}} e^{- \theta_{1} x_{j}^{2}} e^{- \theta_{2} y_{i}^{2}} e^{- \theta_{2} y_{j}^{2}} e^{2 \theta_{1} x_{i} x_{j}} e^{2 \theta_{2} y_{i} y_{j}} + 12 \theta_{2}^{2} e^{- \theta_{1} x_{i}^{2}} e^{- \theta_{1} x_{j}^{2}} e^{- \theta_{2} y_{i}^{2}} e^{- \theta_{2} y_{j}^{2}} e^{2 \theta_{1} x_{i} x_{j}} e^{2 \theta_{2} y_{i} y_{j}}$$




```python
from IPython.core.display import HTML
def css_styling():
    styles = open("../styles/custom.css", "r").read()
    return HTML(styles)
css_styling()
```




<link href='http://fonts.googleapis.com/css?family=Fenix' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Alegreya+Sans:100,300,400,500,700,800,900,100italic,300italic,400italic,500italic,700italic,800italic,900italic' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Source+Code+Pro:300,400' rel='stylesheet' type='text/css'>
<style>
    @font-face {
        font-family: "Computer Modern";
        src: url('http://mirrors.ctan.org/fonts/cm-unicode/fonts/otf/cmunss.otf');
    }
    div.cell{
        width:600px;
        margin-left:16% !important;
        margin-right:auto;
    }
    h1 {
        font-family: 'Alegreya Sans', sans-serif;
    }
    h2 {
        font-family: 'Fenix', serif;
    }
    h3{
		font-family: 'Fenix', serif;
        margin-top:12px;
        margin-bottom: 3px;
       }
	h4{
		font-family: 'Fenix', serif;
       }
    h5 {
        font-family: 'Alegreya Sans', sans-serif;
    }	   
    div.text_cell_render{
        font-family: 'Alegreya Sans',Computer Modern, "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
        line-height: 135%;
        font-size: 120%;
        width:600px;
        margin-left:auto;
        margin-right:auto;
    }
    .CodeMirror{
            font-family: "Source Code Pro";
			font-size: 90%;
    }
/*    .prompt{
        display: None;
    }*/
    .text_cell_render h1 {
        font-weight: 200;
        font-size: 50pt;
		line-height: 100%;
        color:#054BCD;
        margin-bottom: 0.5em;
        margin-top: 0.5em;
        display: block;
    }	
    .text_cell_render h5 {
        font-weight: 300;
        font-size: 16pt;
        color: #054BCD;
        font-style: italic;
        margin-bottom: .5em;
        margin-top: 0.5em;
        display: block;
    }

    .warning{
        color: rgb( 240, 20, 20 )
        }  
</style>






```python

```

23ccd1f427ad5b0f242f971b2bdc4f751d372c5f
ipynb
Jupyter Notebook
autoker/02_example_2d.ipynb
ratnania/mlhiphy
c75b5c4b5fbc557f77d234df001fe11b10681d7d
MIT
2018-07-12T09:03:43.000Z
2019-10-29T09:50:34.000Z
autoker/02_example_2d.ipynb
ratnania/mlhiphy
c75b5c4b5fbc557f77d234df001fe11b10681d7d
MIT
autoker/02_example_2d.ipynb
ratnania/mlhiphy
c75b5c4b5fbc557f77d234df001fe11b10681d7d
MIT
2018-04-25T06:33:03.000Z
2020-03-13T02:25:07.000Z
Qwen/Qwen-72B
1. YES
2. YES