Jeremy Huard

Tips and Tricks: Use SimFunction for easy and fast model simulations in scripts

Jeremy Huard am 22 Mär. 2019 (Bearbeitet am 22 Mär. 2019)
Letzte Aktivität Bearbeitung durch Jeremy Huard am 22 Mär. 2019

What is it?

SimFunction allows you to perform multiple simulations in a single line of code by providing an interface to execute SimBiology® models like a regular MATLAB function.

Consider the following similarity: If you want to calculate the value of the sine function at multiple times defined in the variable t, you use the following syntax:

 >> y = sin(t)

If mymodel represents a SimFunction, you can simulate your model with multiple parameter sets using the following syntax:

 >> simulationData = mymodel(parameterValues, stopTime, dose)

.

What is it good for?

Multiple simulations

Because it allows you to perform multiple simulations in a single line of code by providing a matrix of parameter values or variants or a cell array of dosing tables, it is particularly suited for

  • parameter and dose scans
  • Monte Carlo simulations
  • customized analyses that require multiple model simulations such as a customized optimization

Performance

SimFunctions are optimized for performance as they are automatically accelerated at the first function execution, which converts the model into compiled C code. Those simulations can be distributed to multiple cores or to a cluster and run in parallel if Parallel Computing Toolbox™ is available thanks to its built-in parallelization or within a parfor loop.

Simulation deployment

Since SimFunction objects cannot be changed once created, they can be shared with others without the risk of altering the model inadvertently.

Also, you can use SimFunctions to integrate a SimBiology model into a customized MATLAB App and compile it as standalone application to share with anyone without the need of a MATLAB license.

.

How does it work?

Create a SimFunction object using the createSimFunction method by choosing:

  1. which parameters it should take as inputs
  2. which targets will be dosed
  3. which model quantities it should return
  4. which sensitivities it should return if any

Have a look at the following example from the SimBiology documentation for an executable script to help you get started: Perform a Parameter Scan.