Skip to content

Commit 231121e

Browse files
doc: adjust line numbers in pred-prey fitting example (#234)
1 parent d2c35df commit 231121e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

book/src/primer/population_dynamics_fitting.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Note that the `problem` field of the `Problem` struct is wrapped in a `RefCell`
3131
The argmin `CostFunction` trait requires an implementation of the `cost` method, which will calculate the sum-of-squares difference between the synthetic data and the model output. Since the argmin crate does not support constraints, we'll return a large value if the ODE solver fails to converge.
3232

3333
```rust,ignore
34-
{{#include ../../../examples/predator-prey-fitting-forward/src/main_llvm.rs:26:45}}
34+
{{#include ../../../examples/predator-prey-fitting-forward/src/main_llvm.rs:25:48}}
3535
```
3636

3737
The argmin `Gradient` trait requires an implementation of the `gradient` method, which will calculate the gradient of the cost function with respect to the parameters. Our sum-of-squares cost function can be written as
@@ -49,15 +49,15 @@ where \\(y_i(p)\\) is the model output as a function of the parameters \\(p\\),
4949
where \\(\frac{\partial y_i}{\partial p}\\) is the sensitivity of the model output with respect to the parameters. We can calculate this sensitivity using the `solve_dense_sensitivities` method of the ODE solver. The gradient of the cost function is then the sum of the dot product of the residuals and the sensitivities for each time point. Again, if the ODE solver fails to converge, we'll return a large value for the gradient.
5050

5151
```rust,ignore
52-
{{#include ../../../examples/predator-prey-fitting-forward/src/main_llvm.rs:47:70}}
52+
{{#include ../../../examples/predator-prey-fitting-forward/src/main_llvm.rs:50:82}}
5353
```
5454

5555
With these implementation out of the way, we can now perform the fitting problem. We'll generate some synthetic data using the Lotka-Volterra equations with some true parameters, and then fit the model to this data. We'll use the `LBFGS` solver from the argmin crate, which is a quasi-Newton method that uses the Broyden-Fletcher-Goldfarb-Shanno (BFGS) update formula. We'll also use the `SlogLogger` observer to log the progress of the optimisation.
5656

5757
We'll initialise the optimizer a short distance away from the true parameter values, and then check the final optimised parameter values against the true values.
5858

5959
```rust,ignore
60-
{{#include ../../../examples/predator-prey-fitting-forward/src/main_llvm.rs:72::}}
60+
{{#include ../../../examples/predator-prey-fitting-forward/src/main_llvm.rs:83::}}
6161
```
6262

6363
```

0 commit comments

Comments
 (0)