Forward Sensitivities

The SensitivitiesOdeSolverMethod trait provides a way to compute the forward sensitivities of the solution of an ODE problem, using its solve_dense_sensitivities method.

This method computes both the solution and the sensitivities at the same time, at the time-points provided by the user. These are returned as a tuple containing:

  • A matrix of the solution at each time-point, where each column corresponds to a time-point and each row corresponds to a state variable.
  • a Vec of matrices containing the sensitivities at each time-point. Each element of the outer vector corresponds to the sensitivities for each parameter, and each column of the inner matrix corresponds to a time-point.
use crate::{M, T, V};
use diffsol::{OdeEquationsImplicitSens, SensitivitiesOdeSolverMethod};

pub fn solve_fwd_sens<'a, Solver, Eqn>(solver: &mut Solver)
where
    Solver: SensitivitiesOdeSolverMethod<'a, Eqn>,
    Eqn: OdeEquationsImplicitSens<T = T, V = V, M = M> + 'a,
{
    let t_evals = vec![0.0, 1.0, 2.0, 3.0, 4.0, 5.0];
    let (y, sens) = solver
        .solve_dense_sensitivities(t_evals.as_slice())
        .unwrap();
    println!("solution: {:?}", y);
    for (i, dydp_i) in sens.iter().enumerate() {
        println!("sens wrt parameter {}: {:?}", i, dydp_i);
    }
}