Calibrating Models to Data
Calibrating models to data, or finding parameters which make a model a sufficiently close fit to data, is part of the core functionality of JuliaSimModelOptimizer. The calibrate
function is designed as an automated mechanism for performing such model calibration in an accurate and efficient manner. It uses alternative methods for building the cost functions, also called transcription methods, such as multiple shooting and collocation to improve the stability of the training process, along with mixing in techniques for sampling initial conditions, to ensure that an accurate fit can be generate with little to no effort.
calibrate
is designed for finding a single best fitting parameter set for a model. For a set of potential fits to characterize fitting uncertainty, see the documentation on the parametric_uq
function for parametric uncertainty quantification
The calibrate
Function
JuliaSimModelOptimizer.calibrate
— Functioncalibrate(prob, alg; adtype = Optimization.AutoForwardDiff())
Find the best parameters to solve the inverse problem prob
using the calibration algorithm given by alg
.
Arguments
prob
: theInverseProblem
to solvealg
: the calibration algorithm used for building the loss function
Keyword Arguments
adtype
: Automatic differentiation choice, see the
Optimization.jl docs for details. Defaults to AutoForwardDiff()
.
Calibration Algorithms
Multiple shoothing methods
Multiple shooting methods work by splitting the timespan that is simulated in multiple segments or trajectories and enforcing the continuity between them. In the simplest case, SingleShooting
we only have one trajectory, so no split occurs.
JuliaSimModelOptimizer.SingleShooting
— TypeSingleShooting(;maxiters=nothing, maxtime=nothing, optimizer=Optim.LBFGS(linesearch = BackTracking()), kwargs...)
Single shooting is the simplest transcription method for building the loss function. In this case we solve all the model equation and then we compare the solutions against the data with the user given error functions.
The optimization method will get the cost function as the sum of the individual previously mentioned costs. To change the optimization method, you can use the optimizer
keyword argument. The default optimization method is BFGS
from OptimizationOptimJL
. The maximum number of iterations for the optimizer is given by maxiters
, which is a required keywork argument.
JuliaSimModelOptimizer.MultipleShooting
— TypeMultipleShooting(;maxiters=nothing, maxtime=nothing, optimizer=Optim.LBFGS(linesearch = BackTracking()), interval_saveat_points=0, trajectories=0, continuitylossfun=l2loss, continuitylossweight=100, kwargs...)
Multiple shooting is a calibration algorithm in which we split the solves of the model equations in several parts, as it can be easier to avoid local minima if we fit the individual segments and them match them up. The number of groups can be controlled via the trajectories
keyword argument. The initial conditions between the segments are added to the optimization as extra hidden parameters that have to be fit. The continuity of the resulting solution ensemble is enforced using a continuity penalty between segments. The continuity loss function can be changed via continuitylossfun
, defaulting to l2loss
and the penalty used for the continuity is weighted via a the continuitylossweight
, which defaults to 100.
The optimization method will get the cost function as the sum of the individual previously mentioned costs. To change the optimization method, you can use the optimizer
keyword argument. The default optimization method is BFGS
from OptimizationOptimJL
. The maximum number of iterations for the optimizer is given by maxiters
, which is a required keywork argument.
JuliaSimModelOptimizer.DataShooting
— TypeDataShooting(;maxiters=nothing, maxtime=nothing, optimizer=Optim.LBFGS(linesearch = BackTracking()), groupsize, continuitylossfun=l2loss, continuitylossweight=100, kwargs...)
DataShooting
is a variant of the multiple shooting method (see MultipleShooting
for more details), where we use the data for the internal initial conditions between segments instead of having the optimizer find them. If the data is considered noisy, it might be better to let the optimizer find the initial conditions, as we would inevitably introduce errors if we use DataShooting
. To specify the group size, we can use groupsize
keyword argument. The continuity of the resulting solution ensemble is enforced using a continuity penalty between segments. The continuity losss function can be changed via continuitylossfun
, defaulting to l2loss
and the penalty used for the continuity is weighted via a the continuitylossweight
, which defaults to 100.
The optimization method will get the cost function as the sum of the individual previously mentioned costs. To change the optimization method, you can use the optimizer
keyword argument. The default optimization method is BFGS
from OptimizationOptimJL
. The maximum number of iterations for the optimizer is given by maxiters
, which is a required keywork argument.
Collocation methods
Collocation methods work by computing the derivatives of the data instead of integrating the equations. For more details on how they work, take a look at the collocation manual page.
Collocation methods work with data by design, so they can only be used when you have data in the loss functions.