### Importing packages

#### Others


```python
# Used to read the data file
import pandas as pd

# Used in the definition of the model and its initial condition
import numpy as np

# Used for plots other than those generated by the parameter estimation module
import matplotlib.pyplot as plt
%matplotlib inline
```

#### The module itself


```python
import PDEparams as pde
```

### Defining the model

We use the Fisher-KPP equation defined by
$$\begin{align}
\frac{\partial u}{\partial t} &= D \frac{\partial^2 u}{\partial x^2} + r\,u(1-u)
\end{align}$$

with parameters $D$ and $r$.

#### Boundary conditions

We use no-flux boundary conditions in the domain defined by the data, *i.e.*,

$$\frac{\partial u}{\partial x} = 0$$

at the boundaries.

#### Second-order derivatives of $u$

In practice, if we consider $u$ to be a discrete 1D vector $(u_0, u_1, ...)$, then we can obtain the central differences

$$\begin{align}
h\, u'_i &= u_{i+1}-u_{i-1}\\
h^2\, u''_i &= u_{i+1}+u_{i-1}-2u_i
\end{align}$$

where $h=dx$, $u' = \partial u/\partial x$, and $u'' = \partial^2 u/\partial x^2$. If we have a boundary condition $u'_0 = 0$, and we take an imaginary point $u_{-1}$ to the left of our domain so that

$$h^2\, u''_0 = u_{1}+u_{-1}-2u_0$$

at the boundary, we obtain from the first-order difference $u_{-1} = u_1$. Therefore, in our case

$$\begin{align}h^2u''_0 &= 2u_1 - 2u_0
\end{align}$$


```python
def Fisher(u, t, x, D, r):
    '''The input u corresponds to the current state of the system, and it's a vector of values u(x). Since
    the input is in 1D, no pre-processing is needed.
    
    t is the current time.
    
    x is the spatial grid of the model.

    D and r correspond to the unknown parameters.
    '''
    
    # We compute step in x
    dx = x[1]-x[0]
    
    # We initialise the spatial derivatives we need as empty arrays of the same shape of our variable
    dudxx = np.empty_like(u)

    # Second-order derivative
    
    # Left boundary. In the grid array, first element: [0]
    dudxx[0] = (2.0*u[1] - 2.0*u[0])/dx**2
    
    # Away from the x-boundary. In the grid array, second to penultimate elements: [1:-1]
    # np.diff(array, order) is used to compute 2nd-order differences
    dudxx[1:-1] = np.diff(u,2)/dx**2
    
    # Right boundary. In the grid array, last element: [-1]
    dudxx[-1] = (2.0*u[-2] - 2.0*u[-1])/dx**2
    
    # Adding the second term
    # We use np.maximum() to force the values of ru(1-u) to be non-negative and avoid small numerical errors
    
    dudt = D*dudxx + np.maximum(r*u*(1-u),0)
    
    return dudt
```

Here we specify the function that defines the initial condition for $u$ which, when generating the data, has been set to $u=1$ for $x<-0.3$ and $u=0$ otherwise.


```python
def initfunc(x):
    return 1.*int(x<-0.3)
```

### Using `PDEparams` to estimate parameters

First, we load the data from the `.csv` file.

The data consist of 3 replicates, and have been generated using parameter values $D=0.1$, $r=5$.

The columns are, in order: $t$, $x$, $u$.


```python
df = pd.read_csv('FisherData.csv')

df.head()
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>0</th>
      <th>1</th>
      <th>2</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>0.075758</td>
      <td>-0.479798</td>
      <td>0.911668</td>
    </tr>
    <tr>
      <th>1</th>
      <td>0.075758</td>
      <td>-0.479798</td>
      <td>0.914364</td>
    </tr>
    <tr>
      <th>2</th>
      <td>0.075758</td>
      <td>-0.479798</td>
      <td>0.911544</td>
    </tr>
    <tr>
      <th>3</th>
      <td>0.075758</td>
      <td>-0.429293</td>
      <td>0.865805</td>
    </tr>
    <tr>
      <th>4</th>
      <td>0.075758</td>
      <td>-0.429293</td>
      <td>0.866684</td>
    </tr>
  </tbody>
</table>
</div>



#### Constructing the `PDEmodel` object.

The inputs are

**Required:**
1. The data table `df`.
2. The model `Fisher`.
3. The list of initial condition functions. In this case, a list of one element.
4. The bounds for the parameter values.

**Optional:**
1. The parameter names.
2. The number of variables: 1.
3. The number of spatial dimensions: 1.
4. The number of replicates in the data: 3. **(Default is 1, this needs to be provided in this case)**
5. The indices of the measured variables. In this case, the default `None`, since we have only one variable.
6. The function to apply to the output. In this case, the default `None`, since our data is directly $u$.


```python
my_model = pde.PDEmodel(df, Fisher, [initfunc], bounds=[(0.01, 0.2), (4,6)], 
                        param_names=[r'$D$', r'$r$'], nvars=1, ndims=1, nreplicates=3, obsidx=None, outfunc=None)
```

Let us plot the initial condition.


```python
plt.plot(my_model.space, my_model.initial_condition)
plt.xlabel(r'$x$')
plt.ylabel(r'$u(x,t=0)$')
```

#### Finding the best fit parameters.


```python
%%time
my_model.fit()
```

            $D$     $r$
    0  0.094684  5.1056
    CPU times: user 19.8 s, sys: 12.1 s, total: 32 s
    Wall time: 21.5 s



```python
my_model.best_params
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>$D$</th>
      <th>$r$</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>0.094684</td>
      <td>5.1056</td>
    </tr>
  </tbody>
</table>
</div>




```python
my_model.best_error
```




    3.515106675704532e-05



#### Likelihood profiles

We use the default grid of 100 points per parameter.

**Note:** if you see a "widget not found" message, just ignore it; a progress bar will appear when you run the cell below.


```python
%%time
my_model.likelihood_profiles()
```


    HBox(children=(IntProgress(value=0, description='parameters', max=2, style=ProgressStyle(description_width='in…



    HBox(children=(IntProgress(value=0, description='values within parameters', style=ProgressStyle(description_wi…



    HBox(children=(IntProgress(value=0, description='values within parameters', style=ProgressStyle(description_wi…


    
    CPU times: user 30min 54s, sys: 27min 55s, total: 58min 50s
    Wall time: 31min 27s


The raw results


```python
my_model.result_profiles
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>parameter</th>
      <th>value</th>
      <th>error</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>$D$</td>
      <td>0.010000</td>
      <td>0.164802</td>
    </tr>
    <tr>
      <th>1</th>
      <td>$D$</td>
      <td>0.011919</td>
      <td>0.144492</td>
    </tr>
    <tr>
      <th>2</th>
      <td>$D$</td>
      <td>0.013838</td>
      <td>0.125980</td>
    </tr>
    <tr>
      <th>3</th>
      <td>$D$</td>
      <td>0.015758</td>
      <td>0.109224</td>
    </tr>
    <tr>
      <th>4</th>
      <td>$D$</td>
      <td>0.017677</td>
      <td>0.094326</td>
    </tr>
    <tr>
      <th>5</th>
      <td>$D$</td>
      <td>0.019596</td>
      <td>0.081308</td>
    </tr>
    <tr>
      <th>6</th>
      <td>$D$</td>
      <td>0.021515</td>
      <td>0.070059</td>
    </tr>
    <tr>
      <th>7</th>
      <td>$D$</td>
      <td>0.023434</td>
      <td>0.060386</td>
    </tr>
    <tr>
      <th>8</th>
      <td>$D$</td>
      <td>0.025354</td>
      <td>0.052074</td>
    </tr>
    <tr>
      <th>9</th>
      <td>$D$</td>
      <td>0.027273</td>
      <td>0.044923</td>
    </tr>
    <tr>
      <th>10</th>
      <td>$D$</td>
      <td>0.029192</td>
      <td>0.038758</td>
    </tr>
    <tr>
      <th>11</th>
      <td>$D$</td>
      <td>0.031111</td>
      <td>0.033430</td>
    </tr>
    <tr>
      <th>12</th>
      <td>$D$</td>
      <td>0.033030</td>
      <td>0.028814</td>
    </tr>
    <tr>
      <th>13</th>
      <td>$D$</td>
      <td>0.034949</td>
      <td>0.024809</td>
    </tr>
    <tr>
      <th>14</th>
      <td>$D$</td>
      <td>0.036869</td>
      <td>0.021328</td>
    </tr>
    <tr>
      <th>15</th>
      <td>$D$</td>
      <td>0.038788</td>
      <td>0.018298</td>
    </tr>
    <tr>
      <th>16</th>
      <td>$D$</td>
      <td>0.040707</td>
      <td>0.015661</td>
    </tr>
    <tr>
      <th>17</th>
      <td>$D$</td>
      <td>0.042626</td>
      <td>0.013365</td>
    </tr>
    <tr>
      <th>18</th>
      <td>$D$</td>
      <td>0.044545</td>
      <td>0.011367</td>
    </tr>
    <tr>
      <th>19</th>
      <td>$D$</td>
      <td>0.046465</td>
      <td>0.009631</td>
    </tr>
    <tr>
      <th>20</th>
      <td>$D$</td>
      <td>0.048384</td>
      <td>0.008124</td>
    </tr>
    <tr>
      <th>21</th>
      <td>$D$</td>
      <td>0.050303</td>
      <td>0.006821</td>
    </tr>
    <tr>
      <th>22</th>
      <td>$D$</td>
      <td>0.052222</td>
      <td>0.005696</td>
    </tr>
    <tr>
      <th>23</th>
      <td>$D$</td>
      <td>0.054141</td>
      <td>0.004731</td>
    </tr>
    <tr>
      <th>24</th>
      <td>$D$</td>
      <td>0.056061</td>
      <td>0.003907</td>
    </tr>
    <tr>
      <th>25</th>
      <td>$D$</td>
      <td>0.057980</td>
      <td>0.003210</td>
    </tr>
    <tr>
      <th>26</th>
      <td>$D$</td>
      <td>0.059899</td>
      <td>0.002624</td>
    </tr>
    <tr>
      <th>27</th>
      <td>$D$</td>
      <td>0.061818</td>
      <td>0.002140</td>
    </tr>
    <tr>
      <th>28</th>
      <td>$D$</td>
      <td>0.063737</td>
      <td>0.001745</td>
    </tr>
    <tr>
      <th>29</th>
      <td>$D$</td>
      <td>0.065657</td>
      <td>0.001431</td>
    </tr>
    <tr>
      <th>...</th>
      <td>...</td>
      <td>...</td>
      <td>...</td>
    </tr>
    <tr>
      <th>170</th>
      <td>$r$</td>
      <td>5.414141</td>
      <td>0.000149</td>
    </tr>
    <tr>
      <th>171</th>
      <td>$r$</td>
      <td>5.434343</td>
      <td>0.000164</td>
    </tr>
    <tr>
      <th>172</th>
      <td>$r$</td>
      <td>5.454545</td>
      <td>0.000179</td>
    </tr>
    <tr>
      <th>173</th>
      <td>$r$</td>
      <td>5.474747</td>
      <td>0.000195</td>
    </tr>
    <tr>
      <th>174</th>
      <td>$r$</td>
      <td>5.494949</td>
      <td>0.000211</td>
    </tr>
    <tr>
      <th>175</th>
      <td>$r$</td>
      <td>5.515152</td>
      <td>0.000229</td>
    </tr>
    <tr>
      <th>176</th>
      <td>$r$</td>
      <td>5.535354</td>
      <td>0.000247</td>
    </tr>
    <tr>
      <th>177</th>
      <td>$r$</td>
      <td>5.555556</td>
      <td>0.000265</td>
    </tr>
    <tr>
      <th>178</th>
      <td>$r$</td>
      <td>5.575758</td>
      <td>0.000285</td>
    </tr>
    <tr>
      <th>179</th>
      <td>$r$</td>
      <td>5.595960</td>
      <td>0.000304</td>
    </tr>
    <tr>
      <th>180</th>
      <td>$r$</td>
      <td>5.616162</td>
      <td>0.000325</td>
    </tr>
    <tr>
      <th>181</th>
      <td>$r$</td>
      <td>5.636364</td>
      <td>0.000346</td>
    </tr>
    <tr>
      <th>182</th>
      <td>$r$</td>
      <td>5.656566</td>
      <td>0.000368</td>
    </tr>
    <tr>
      <th>183</th>
      <td>$r$</td>
      <td>5.676768</td>
      <td>0.000390</td>
    </tr>
    <tr>
      <th>184</th>
      <td>$r$</td>
      <td>5.696970</td>
      <td>0.000413</td>
    </tr>
    <tr>
      <th>185</th>
      <td>$r$</td>
      <td>5.717172</td>
      <td>0.000436</td>
    </tr>
    <tr>
      <th>186</th>
      <td>$r$</td>
      <td>5.737374</td>
      <td>0.000460</td>
    </tr>
    <tr>
      <th>187</th>
      <td>$r$</td>
      <td>5.757576</td>
      <td>0.000485</td>
    </tr>
    <tr>
      <th>188</th>
      <td>$r$</td>
      <td>5.777778</td>
      <td>0.000510</td>
    </tr>
    <tr>
      <th>189</th>
      <td>$r$</td>
      <td>5.797980</td>
      <td>0.000535</td>
    </tr>
    <tr>
      <th>190</th>
      <td>$r$</td>
      <td>5.818182</td>
      <td>0.000561</td>
    </tr>
    <tr>
      <th>191</th>
      <td>$r$</td>
      <td>5.838384</td>
      <td>0.000587</td>
    </tr>
    <tr>
      <th>192</th>
      <td>$r$</td>
      <td>5.858586</td>
      <td>0.000614</td>
    </tr>
    <tr>
      <th>193</th>
      <td>$r$</td>
      <td>5.878788</td>
      <td>0.000642</td>
    </tr>
    <tr>
      <th>194</th>
      <td>$r$</td>
      <td>5.898990</td>
      <td>0.000669</td>
    </tr>
    <tr>
      <th>195</th>
      <td>$r$</td>
      <td>5.919192</td>
      <td>0.000698</td>
    </tr>
    <tr>
      <th>196</th>
      <td>$r$</td>
      <td>5.939394</td>
      <td>0.000726</td>
    </tr>
    <tr>
      <th>197</th>
      <td>$r$</td>
      <td>5.959596</td>
      <td>0.000755</td>
    </tr>
    <tr>
      <th>198</th>
      <td>$r$</td>
      <td>5.979798</td>
      <td>0.000785</td>
    </tr>
    <tr>
      <th>199</th>
      <td>$r$</td>
      <td>6.000000</td>
      <td>0.000815</td>
    </tr>
  </tbody>
</table>
<p>200 rows × 3 columns</p>
</div>



Visualisation


```python
my_model.plot_profiles()
```

#### Bootstrapping

We use the default 100 repetitions.

**Note:** if you see a "widget not found" message, just ignore it; a progress bar will appear when you run the cell below.


```python
%%time
my_model.bootstrap()
```


    HBox(children=(IntProgress(value=0, description='runs', style=ProgressStyle(description_width='initial')), HTM…


    
                  $D$         $r$
    count  100.000000  100.000000
    mean     0.094740    5.103248
    std      0.000064    0.002262
    min      0.094536    5.096778
    25%      0.094699    5.101904
    50%      0.094747    5.103201
    75%      0.094784    5.104362
    max      0.094897    5.109668
    CPU times: user 28min, sys: 28min 45s, total: 56min 45s
    Wall time: 27min 28s


The summary


```python
my_model.bootstrap_summary
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>$D$</th>
      <th>$r$</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>count</th>
      <td>100.000000</td>
      <td>100.000000</td>
    </tr>
    <tr>
      <th>mean</th>
      <td>0.094740</td>
      <td>5.103248</td>
    </tr>
    <tr>
      <th>std</th>
      <td>0.000064</td>
      <td>0.002262</td>
    </tr>
    <tr>
      <th>min</th>
      <td>0.094536</td>
      <td>5.096778</td>
    </tr>
    <tr>
      <th>25%</th>
      <td>0.094699</td>
      <td>5.101904</td>
    </tr>
    <tr>
      <th>50%</th>
      <td>0.094747</td>
      <td>5.103201</td>
    </tr>
    <tr>
      <th>75%</th>
      <td>0.094784</td>
      <td>5.104362</td>
    </tr>
    <tr>
      <th>max</th>
      <td>0.094897</td>
      <td>5.109668</td>
    </tr>
  </tbody>
</table>
</div>



The raw results


```python
my_model.bootstrap_raw
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>$D$</th>
      <th>$r$</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>0.094666</td>
      <td>5.105857</td>
    </tr>
    <tr>
      <th>1</th>
      <td>0.094802</td>
      <td>5.101306</td>
    </tr>
    <tr>
      <th>2</th>
      <td>0.094698</td>
      <td>5.104337</td>
    </tr>
    <tr>
      <th>3</th>
      <td>0.094710</td>
      <td>5.104589</td>
    </tr>
    <tr>
      <th>4</th>
      <td>0.094795</td>
      <td>5.101503</td>
    </tr>
    <tr>
      <th>5</th>
      <td>0.094731</td>
      <td>5.103505</td>
    </tr>
    <tr>
      <th>6</th>
      <td>0.094798</td>
      <td>5.102691</td>
    </tr>
    <tr>
      <th>7</th>
      <td>0.094744</td>
      <td>5.103123</td>
    </tr>
    <tr>
      <th>8</th>
      <td>0.094751</td>
      <td>5.102683</td>
    </tr>
    <tr>
      <th>9</th>
      <td>0.094750</td>
      <td>5.103047</td>
    </tr>
    <tr>
      <th>10</th>
      <td>0.094671</td>
      <td>5.106643</td>
    </tr>
    <tr>
      <th>11</th>
      <td>0.094897</td>
      <td>5.096778</td>
    </tr>
    <tr>
      <th>12</th>
      <td>0.094746</td>
      <td>5.102953</td>
    </tr>
    <tr>
      <th>13</th>
      <td>0.094685</td>
      <td>5.104622</td>
    </tr>
    <tr>
      <th>14</th>
      <td>0.094816</td>
      <td>5.101104</td>
    </tr>
    <tr>
      <th>15</th>
      <td>0.094709</td>
      <td>5.104438</td>
    </tr>
    <tr>
      <th>16</th>
      <td>0.094745</td>
      <td>5.102176</td>
    </tr>
    <tr>
      <th>17</th>
      <td>0.094782</td>
      <td>5.103249</td>
    </tr>
    <tr>
      <th>18</th>
      <td>0.094702</td>
      <td>5.104978</td>
    </tr>
    <tr>
      <th>19</th>
      <td>0.094704</td>
      <td>5.104017</td>
    </tr>
    <tr>
      <th>20</th>
      <td>0.094798</td>
      <td>5.101398</td>
    </tr>
    <tr>
      <th>21</th>
      <td>0.094695</td>
      <td>5.104247</td>
    </tr>
    <tr>
      <th>22</th>
      <td>0.094814</td>
      <td>5.100049</td>
    </tr>
    <tr>
      <th>23</th>
      <td>0.094609</td>
      <td>5.105373</td>
    </tr>
    <tr>
      <th>24</th>
      <td>0.094806</td>
      <td>5.102363</td>
    </tr>
    <tr>
      <th>25</th>
      <td>0.094733</td>
      <td>5.103153</td>
    </tr>
    <tr>
      <th>26</th>
      <td>0.094748</td>
      <td>5.103949</td>
    </tr>
    <tr>
      <th>27</th>
      <td>0.094725</td>
      <td>5.101927</td>
    </tr>
    <tr>
      <th>28</th>
      <td>0.094800</td>
      <td>5.101076</td>
    </tr>
    <tr>
      <th>29</th>
      <td>0.094776</td>
      <td>5.103519</td>
    </tr>
    <tr>
      <th>...</th>
      <td>...</td>
      <td>...</td>
    </tr>
    <tr>
      <th>70</th>
      <td>0.094730</td>
      <td>5.103557</td>
    </tr>
    <tr>
      <th>71</th>
      <td>0.094668</td>
      <td>5.106973</td>
    </tr>
    <tr>
      <th>72</th>
      <td>0.094536</td>
      <td>5.109668</td>
    </tr>
    <tr>
      <th>73</th>
      <td>0.094853</td>
      <td>5.099582</td>
    </tr>
    <tr>
      <th>74</th>
      <td>0.094770</td>
      <td>5.101361</td>
    </tr>
    <tr>
      <th>75</th>
      <td>0.094680</td>
      <td>5.104199</td>
    </tr>
    <tr>
      <th>76</th>
      <td>0.094795</td>
      <td>5.101674</td>
    </tr>
    <tr>
      <th>77</th>
      <td>0.094789</td>
      <td>5.102594</td>
    </tr>
    <tr>
      <th>78</th>
      <td>0.094738</td>
      <td>5.102674</td>
    </tr>
    <tr>
      <th>79</th>
      <td>0.094788</td>
      <td>5.100907</td>
    </tr>
    <tr>
      <th>80</th>
      <td>0.094756</td>
      <td>5.100542</td>
    </tr>
    <tr>
      <th>81</th>
      <td>0.094619</td>
      <td>5.106410</td>
    </tr>
    <tr>
      <th>82</th>
      <td>0.094732</td>
      <td>5.103821</td>
    </tr>
    <tr>
      <th>83</th>
      <td>0.094698</td>
      <td>5.104928</td>
    </tr>
    <tr>
      <th>84</th>
      <td>0.094759</td>
      <td>5.103685</td>
    </tr>
    <tr>
      <th>85</th>
      <td>0.094811</td>
      <td>5.101733</td>
    </tr>
    <tr>
      <th>86</th>
      <td>0.094779</td>
      <td>5.104111</td>
    </tr>
    <tr>
      <th>87</th>
      <td>0.094763</td>
      <td>5.102247</td>
    </tr>
    <tr>
      <th>88</th>
      <td>0.094774</td>
      <td>5.102384</td>
    </tr>
    <tr>
      <th>89</th>
      <td>0.094596</td>
      <td>5.107622</td>
    </tr>
    <tr>
      <th>90</th>
      <td>0.094734</td>
      <td>5.102828</td>
    </tr>
    <tr>
      <th>91</th>
      <td>0.094762</td>
      <td>5.103256</td>
    </tr>
    <tr>
      <th>92</th>
      <td>0.094718</td>
      <td>5.104975</td>
    </tr>
    <tr>
      <th>93</th>
      <td>0.094714</td>
      <td>5.103760</td>
    </tr>
    <tr>
      <th>94</th>
      <td>0.094762</td>
      <td>5.101073</td>
    </tr>
    <tr>
      <th>95</th>
      <td>0.094699</td>
      <td>5.105013</td>
    </tr>
    <tr>
      <th>96</th>
      <td>0.094811</td>
      <td>5.101284</td>
    </tr>
    <tr>
      <th>97</th>
      <td>0.094697</td>
      <td>5.104681</td>
    </tr>
    <tr>
      <th>98</th>
      <td>0.094658</td>
      <td>5.104336</td>
    </tr>
    <tr>
      <th>99</th>
      <td>0.094690</td>
      <td>5.103858</td>
    </tr>
  </tbody>
</table>
<p>100 rows × 2 columns</p>
</div>



Visualisation


```python
my_model.plot_bootstrap()
```

### Only a function of the variables is observed

Now we consider the case when it's not the raw outputs of the system that are observed, but rather a function of them. In this case, let us assume that the observed quantity is

$$\mathcal{F}(u) = u(1-u)$$


```python
df2 = df[df.columns[[0,1]]] # we take only the space-time coordinates

# We add the new function
df2[r'$\mathcal{F}$'] = df['2']-df['2']*df['2'] # u is column 2 in the data table

df2.head()
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>0</th>
      <th>1</th>
      <th>$\mathcal{F}$</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>0.075758</td>
      <td>-0.479798</td>
      <td>0.080530</td>
    </tr>
    <tr>
      <th>1</th>
      <td>0.075758</td>
      <td>-0.479798</td>
      <td>0.078302</td>
    </tr>
    <tr>
      <th>2</th>
      <td>0.075758</td>
      <td>-0.479798</td>
      <td>0.080632</td>
    </tr>
    <tr>
      <th>3</th>
      <td>0.075758</td>
      <td>-0.429293</td>
      <td>0.116187</td>
    </tr>
    <tr>
      <th>4</th>
      <td>0.075758</td>
      <td>-0.429293</td>
      <td>0.115543</td>
    </tr>
  </tbody>
</table>
</div>



#### Constructing the `PDEmodel` object.

The inputs are the same as before, except for the data&mdash;now `df2`&mdash;and `outfunc`, which specifies the function to be applied to the outputs before computing the error.


```python
def F(z):
    return z*(1-z)
```


```python
my_model2 = pde.PDEmodel(df2, Fisher, [initfunc], bounds=[(0.01, 0.2), (4,6)], 
                         param_names=[r'$D$', r'$r$'], nvars=1, ndims=1, nreplicates=3, obsidx=None, outfunc=F)
```

#### Finding the best fit parameters.


```python
%%time
my_model2.fit()
```

            $D$       $r$
    0  0.094969  5.083631
    CPU times: user 16.8 s, sys: 18.5 s, total: 35.3 s
    Wall time: 16.1 s



```python
my_model2.best_params
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>$D$</th>
      <th>$r$</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>0.094969</td>
      <td>5.083631</td>
    </tr>
  </tbody>
</table>
</div>




```python
my_model2.best_error
```




    1.3675800592789573e-05



#### Likelihood profiles

**Note:** if you see a "widget not found" message, just ignore it; a progress bar will appear when you run the cell below.


```python
%%time
my_model2.likelihood_profiles()
```


    HBox(children=(IntProgress(value=0, description='parameters', max=2, style=ProgressStyle(description_width='in…



    HBox(children=(IntProgress(value=0, description='values within parameters', style=ProgressStyle(description_wi…



    HBox(children=(IntProgress(value=0, description='values within parameters', style=ProgressStyle(description_wi…


    
    CPU times: user 26min 57s, sys: 24min 53s, total: 51min 50s
    Wall time: 24min 40s


The raw results


```python
my_model2.result_profiles
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>parameter</th>
      <th>value</th>
      <th>error</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>$D$</td>
      <td>0.010000</td>
      <td>0.014846</td>
    </tr>
    <tr>
      <th>1</th>
      <td>$D$</td>
      <td>0.011919</td>
      <td>0.014109</td>
    </tr>
    <tr>
      <th>2</th>
      <td>$D$</td>
      <td>0.013838</td>
      <td>0.013432</td>
    </tr>
    <tr>
      <th>3</th>
      <td>$D$</td>
      <td>0.015758</td>
      <td>0.012794</td>
    </tr>
    <tr>
      <th>4</th>
      <td>$D$</td>
      <td>0.017677</td>
      <td>0.012112</td>
    </tr>
    <tr>
      <th>5</th>
      <td>$D$</td>
      <td>0.019596</td>
      <td>0.011336</td>
    </tr>
    <tr>
      <th>6</th>
      <td>$D$</td>
      <td>0.021515</td>
      <td>0.010480</td>
    </tr>
    <tr>
      <th>7</th>
      <td>$D$</td>
      <td>0.023434</td>
      <td>0.009585</td>
    </tr>
    <tr>
      <th>8</th>
      <td>$D$</td>
      <td>0.025354</td>
      <td>0.008694</td>
    </tr>
    <tr>
      <th>9</th>
      <td>$D$</td>
      <td>0.027273</td>
      <td>0.007834</td>
    </tr>
    <tr>
      <th>10</th>
      <td>$D$</td>
      <td>0.029192</td>
      <td>0.007023</td>
    </tr>
    <tr>
      <th>11</th>
      <td>$D$</td>
      <td>0.031111</td>
      <td>0.006268</td>
    </tr>
    <tr>
      <th>12</th>
      <td>$D$</td>
      <td>0.033030</td>
      <td>0.005573</td>
    </tr>
    <tr>
      <th>13</th>
      <td>$D$</td>
      <td>0.034949</td>
      <td>0.004938</td>
    </tr>
    <tr>
      <th>14</th>
      <td>$D$</td>
      <td>0.036869</td>
      <td>0.004361</td>
    </tr>
    <tr>
      <th>15</th>
      <td>$D$</td>
      <td>0.038788</td>
      <td>0.003839</td>
    </tr>
    <tr>
      <th>16</th>
      <td>$D$</td>
      <td>0.040707</td>
      <td>0.003369</td>
    </tr>
    <tr>
      <th>17</th>
      <td>$D$</td>
      <td>0.042626</td>
      <td>0.002948</td>
    </tr>
    <tr>
      <th>18</th>
      <td>$D$</td>
      <td>0.044545</td>
      <td>0.002572</td>
    </tr>
    <tr>
      <th>19</th>
      <td>$D$</td>
      <td>0.046465</td>
      <td>0.002237</td>
    </tr>
    <tr>
      <th>20</th>
      <td>$D$</td>
      <td>0.048384</td>
      <td>0.001941</td>
    </tr>
    <tr>
      <th>21</th>
      <td>$D$</td>
      <td>0.050303</td>
      <td>0.001680</td>
    </tr>
    <tr>
      <th>22</th>
      <td>$D$</td>
      <td>0.052222</td>
      <td>0.001451</td>
    </tr>
    <tr>
      <th>23</th>
      <td>$D$</td>
      <td>0.054141</td>
      <td>0.001252</td>
    </tr>
    <tr>
      <th>24</th>
      <td>$D$</td>
      <td>0.056061</td>
      <td>0.001079</td>
    </tr>
    <tr>
      <th>25</th>
      <td>$D$</td>
      <td>0.057980</td>
      <td>0.000931</td>
    </tr>
    <tr>
      <th>26</th>
      <td>$D$</td>
      <td>0.059899</td>
      <td>0.000806</td>
    </tr>
    <tr>
      <th>27</th>
      <td>$D$</td>
      <td>0.061818</td>
      <td>0.000700</td>
    </tr>
    <tr>
      <th>28</th>
      <td>$D$</td>
      <td>0.063737</td>
      <td>0.000609</td>
    </tr>
    <tr>
      <th>29</th>
      <td>$D$</td>
      <td>0.065657</td>
      <td>0.000527</td>
    </tr>
    <tr>
      <th>...</th>
      <td>...</td>
      <td>...</td>
      <td>...</td>
    </tr>
    <tr>
      <th>170</th>
      <td>$r$</td>
      <td>5.414141</td>
      <td>0.000074</td>
    </tr>
    <tr>
      <th>171</th>
      <td>$r$</td>
      <td>5.434343</td>
      <td>0.000081</td>
    </tr>
    <tr>
      <th>172</th>
      <td>$r$</td>
      <td>5.454545</td>
      <td>0.000088</td>
    </tr>
    <tr>
      <th>173</th>
      <td>$r$</td>
      <td>5.474747</td>
      <td>0.000096</td>
    </tr>
    <tr>
      <th>174</th>
      <td>$r$</td>
      <td>5.494949</td>
      <td>0.000104</td>
    </tr>
    <tr>
      <th>175</th>
      <td>$r$</td>
      <td>5.515152</td>
      <td>0.000112</td>
    </tr>
    <tr>
      <th>176</th>
      <td>$r$</td>
      <td>5.535354</td>
      <td>0.000121</td>
    </tr>
    <tr>
      <th>177</th>
      <td>$r$</td>
      <td>5.555556</td>
      <td>0.000130</td>
    </tr>
    <tr>
      <th>178</th>
      <td>$r$</td>
      <td>5.575758</td>
      <td>0.000140</td>
    </tr>
    <tr>
      <th>179</th>
      <td>$r$</td>
      <td>5.595960</td>
      <td>0.000149</td>
    </tr>
    <tr>
      <th>180</th>
      <td>$r$</td>
      <td>5.616162</td>
      <td>0.000159</td>
    </tr>
    <tr>
      <th>181</th>
      <td>$r$</td>
      <td>5.636364</td>
      <td>0.000169</td>
    </tr>
    <tr>
      <th>182</th>
      <td>$r$</td>
      <td>5.656566</td>
      <td>0.000180</td>
    </tr>
    <tr>
      <th>183</th>
      <td>$r$</td>
      <td>5.676768</td>
      <td>0.000191</td>
    </tr>
    <tr>
      <th>184</th>
      <td>$r$</td>
      <td>5.696970</td>
      <td>0.000202</td>
    </tr>
    <tr>
      <th>185</th>
      <td>$r$</td>
      <td>5.717172</td>
      <td>0.000213</td>
    </tr>
    <tr>
      <th>186</th>
      <td>$r$</td>
      <td>5.737374</td>
      <td>0.000225</td>
    </tr>
    <tr>
      <th>187</th>
      <td>$r$</td>
      <td>5.757576</td>
      <td>0.000236</td>
    </tr>
    <tr>
      <th>188</th>
      <td>$r$</td>
      <td>5.777778</td>
      <td>0.000248</td>
    </tr>
    <tr>
      <th>189</th>
      <td>$r$</td>
      <td>5.797980</td>
      <td>0.000261</td>
    </tr>
    <tr>
      <th>190</th>
      <td>$r$</td>
      <td>5.818182</td>
      <td>0.000273</td>
    </tr>
    <tr>
      <th>191</th>
      <td>$r$</td>
      <td>5.838384</td>
      <td>0.000286</td>
    </tr>
    <tr>
      <th>192</th>
      <td>$r$</td>
      <td>5.858586</td>
      <td>0.000299</td>
    </tr>
    <tr>
      <th>193</th>
      <td>$r$</td>
      <td>5.878788</td>
      <td>0.000312</td>
    </tr>
    <tr>
      <th>194</th>
      <td>$r$</td>
      <td>5.898990</td>
      <td>0.000326</td>
    </tr>
    <tr>
      <th>195</th>
      <td>$r$</td>
      <td>5.919192</td>
      <td>0.000340</td>
    </tr>
    <tr>
      <th>196</th>
      <td>$r$</td>
      <td>5.939394</td>
      <td>0.000353</td>
    </tr>
    <tr>
      <th>197</th>
      <td>$r$</td>
      <td>5.959596</td>
      <td>0.000368</td>
    </tr>
    <tr>
      <th>198</th>
      <td>$r$</td>
      <td>5.979798</td>
      <td>0.000382</td>
    </tr>
    <tr>
      <th>199</th>
      <td>$r$</td>
      <td>6.000000</td>
      <td>0.000396</td>
    </tr>
  </tbody>
</table>
<p>200 rows × 3 columns</p>
</div>



Visualisation


```python
my_model2.plot_profiles()
```

#### Bootstrapping

**Note:** if you see a "widget not found" message, just ignore it; a progress bar will appear when you run the cell below.


```python
%%time
my_model2.bootstrap()
```


    HBox(children=(IntProgress(value=0, description='runs', style=ProgressStyle(description_width='initial')), HTM…


    
                  $D$         $r$
    count  100.000000  100.000000
    mean     0.095067    5.080556
    std      0.000071    0.002290
    min      0.094886    5.074651
    25%      0.095025    5.079063
    50%      0.095074    5.080528
    75%      0.095113    5.082047
    max      0.095243    5.087920
    CPU times: user 27min 1s, sys: 29min 4s, total: 56min 5s
    Wall time: 24min 23s


The summary


```python
my_model2.bootstrap_summary
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>$D$</th>
      <th>$r$</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>count</th>
      <td>100.000000</td>
      <td>100.000000</td>
    </tr>
    <tr>
      <th>mean</th>
      <td>0.095067</td>
      <td>5.080556</td>
    </tr>
    <tr>
      <th>std</th>
      <td>0.000071</td>
      <td>0.002290</td>
    </tr>
    <tr>
      <th>min</th>
      <td>0.094886</td>
      <td>5.074651</td>
    </tr>
    <tr>
      <th>25%</th>
      <td>0.095025</td>
      <td>5.079063</td>
    </tr>
    <tr>
      <th>50%</th>
      <td>0.095074</td>
      <td>5.080528</td>
    </tr>
    <tr>
      <th>75%</th>
      <td>0.095113</td>
      <td>5.082047</td>
    </tr>
    <tr>
      <th>max</th>
      <td>0.095243</td>
      <td>5.087920</td>
    </tr>
  </tbody>
</table>
</div>



The raw results


```python
my_model2.bootstrap_raw
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>$D$</th>
      <th>$r$</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>0.095120</td>
      <td>5.077602</td>
    </tr>
    <tr>
      <th>1</th>
      <td>0.095122</td>
      <td>5.079371</td>
    </tr>
    <tr>
      <th>2</th>
      <td>0.095101</td>
      <td>5.080106</td>
    </tr>
    <tr>
      <th>3</th>
      <td>0.095056</td>
      <td>5.078753</td>
    </tr>
    <tr>
      <th>4</th>
      <td>0.094886</td>
      <td>5.087920</td>
    </tr>
    <tr>
      <th>5</th>
      <td>0.095074</td>
      <td>5.079421</td>
    </tr>
    <tr>
      <th>6</th>
      <td>0.095087</td>
      <td>5.080536</td>
    </tr>
    <tr>
      <th>7</th>
      <td>0.095014</td>
      <td>5.083736</td>
    </tr>
    <tr>
      <th>8</th>
      <td>0.095091</td>
      <td>5.079607</td>
    </tr>
    <tr>
      <th>9</th>
      <td>0.095077</td>
      <td>5.079072</td>
    </tr>
    <tr>
      <th>10</th>
      <td>0.095135</td>
      <td>5.079777</td>
    </tr>
    <tr>
      <th>11</th>
      <td>0.095060</td>
      <td>5.080693</td>
    </tr>
    <tr>
      <th>12</th>
      <td>0.095051</td>
      <td>5.080331</td>
    </tr>
    <tr>
      <th>13</th>
      <td>0.095084</td>
      <td>5.079636</td>
    </tr>
    <tr>
      <th>14</th>
      <td>0.094975</td>
      <td>5.082261</td>
    </tr>
    <tr>
      <th>15</th>
      <td>0.095083</td>
      <td>5.080486</td>
    </tr>
    <tr>
      <th>16</th>
      <td>0.095135</td>
      <td>5.080915</td>
    </tr>
    <tr>
      <th>17</th>
      <td>0.095015</td>
      <td>5.080661</td>
    </tr>
    <tr>
      <th>18</th>
      <td>0.095103</td>
      <td>5.081113</td>
    </tr>
    <tr>
      <th>19</th>
      <td>0.095091</td>
      <td>5.080658</td>
    </tr>
    <tr>
      <th>20</th>
      <td>0.095028</td>
      <td>5.082916</td>
    </tr>
    <tr>
      <th>21</th>
      <td>0.095185</td>
      <td>5.078336</td>
    </tr>
    <tr>
      <th>22</th>
      <td>0.095059</td>
      <td>5.077571</td>
    </tr>
    <tr>
      <th>23</th>
      <td>0.095100</td>
      <td>5.076753</td>
    </tr>
    <tr>
      <th>24</th>
      <td>0.095030</td>
      <td>5.079962</td>
    </tr>
    <tr>
      <th>25</th>
      <td>0.095078</td>
      <td>5.082028</td>
    </tr>
    <tr>
      <th>26</th>
      <td>0.095074</td>
      <td>5.080825</td>
    </tr>
    <tr>
      <th>27</th>
      <td>0.095008</td>
      <td>5.081758</td>
    </tr>
    <tr>
      <th>28</th>
      <td>0.095126</td>
      <td>5.078971</td>
    </tr>
    <tr>
      <th>29</th>
      <td>0.095120</td>
      <td>5.077627</td>
    </tr>
    <tr>
      <th>...</th>
      <td>...</td>
      <td>...</td>
    </tr>
    <tr>
      <th>70</th>
      <td>0.095108</td>
      <td>5.081082</td>
    </tr>
    <tr>
      <th>71</th>
      <td>0.095061</td>
      <td>5.081164</td>
    </tr>
    <tr>
      <th>72</th>
      <td>0.095105</td>
      <td>5.079508</td>
    </tr>
    <tr>
      <th>73</th>
      <td>0.095085</td>
      <td>5.080144</td>
    </tr>
    <tr>
      <th>74</th>
      <td>0.094995</td>
      <td>5.082997</td>
    </tr>
    <tr>
      <th>75</th>
      <td>0.095050</td>
      <td>5.078992</td>
    </tr>
    <tr>
      <th>76</th>
      <td>0.095009</td>
      <td>5.082134</td>
    </tr>
    <tr>
      <th>77</th>
      <td>0.095075</td>
      <td>5.081099</td>
    </tr>
    <tr>
      <th>78</th>
      <td>0.095074</td>
      <td>5.079624</td>
    </tr>
    <tr>
      <th>79</th>
      <td>0.095112</td>
      <td>5.077622</td>
    </tr>
    <tr>
      <th>80</th>
      <td>0.095113</td>
      <td>5.082174</td>
    </tr>
    <tr>
      <th>81</th>
      <td>0.095076</td>
      <td>5.080310</td>
    </tr>
    <tr>
      <th>82</th>
      <td>0.095027</td>
      <td>5.082834</td>
    </tr>
    <tr>
      <th>83</th>
      <td>0.095070</td>
      <td>5.080591</td>
    </tr>
    <tr>
      <th>84</th>
      <td>0.094988</td>
      <td>5.082555</td>
    </tr>
    <tr>
      <th>85</th>
      <td>0.095041</td>
      <td>5.082848</td>
    </tr>
    <tr>
      <th>86</th>
      <td>0.095013</td>
      <td>5.083177</td>
    </tr>
    <tr>
      <th>87</th>
      <td>0.095153</td>
      <td>5.079036</td>
    </tr>
    <tr>
      <th>88</th>
      <td>0.095030</td>
      <td>5.083744</td>
    </tr>
    <tr>
      <th>89</th>
      <td>0.095110</td>
      <td>5.077943</td>
    </tr>
    <tr>
      <th>90</th>
      <td>0.094904</td>
      <td>5.085185</td>
    </tr>
    <tr>
      <th>91</th>
      <td>0.095133</td>
      <td>5.076794</td>
    </tr>
    <tr>
      <th>92</th>
      <td>0.094934</td>
      <td>5.083864</td>
    </tr>
    <tr>
      <th>93</th>
      <td>0.095031</td>
      <td>5.079779</td>
    </tr>
    <tr>
      <th>94</th>
      <td>0.095094</td>
      <td>5.081389</td>
    </tr>
    <tr>
      <th>95</th>
      <td>0.095021</td>
      <td>5.081919</td>
    </tr>
    <tr>
      <th>96</th>
      <td>0.094968</td>
      <td>5.081443</td>
    </tr>
    <tr>
      <th>97</th>
      <td>0.095046</td>
      <td>5.080520</td>
    </tr>
    <tr>
      <th>98</th>
      <td>0.095098</td>
      <td>5.078301</td>
    </tr>
    <tr>
      <th>99</th>
      <td>0.095182</td>
      <td>5.076560</td>
    </tr>
  </tbody>
</table>
<p>100 rows × 2 columns</p>
</div>



Visualisation


```python
my_model2.plot_bootstrap()
```

c3a451e5bf1b8f846dcd66d12f982e3defe2d551
ipynb
Jupyter Notebook
examples/Fisher.ipynb
systemsmedicine/PDEparams-1
8f7f4653b8cf9a06cf461cee132957a84ed92811
MIT
2019-12-20T05:03:46.000Z
2021-10-07T18:18:53.000Z
examples/Fisher.ipynb
systemsmedicine/PDEparams-1
8f7f4653b8cf9a06cf461cee132957a84ed92811
MIT
2021-09-02T11:54:31.000Z
2021-11-03T01:45:22.000Z
examples/Fisher.ipynb
systemsmedicine/PDEparams-1
8f7f4653b8cf9a06cf461cee132957a84ed92811
MIT
2019-12-20T05:04:26.000Z
2021-11-10T15:53:25.000Z
Qwen/Qwen-72B
1. YES
2. YES