Performing Global Sensitivity Analysis

JuliaSimModelOptimizer helps users to consider additional model exploration based on Global Sensitivity Analysis (GSA). This approach is helpful to further investigate how the model output reacts to variance in the model input. For example, we can analyse quantitatively how the variance in single input variables and how combinations of variances in several input variables affect output variables as shown in the figure below:

  1. Influence of first input variable,
  2. Influence of second input variable,
  3. Influence of third input variable,
  4. Influence of second and third input variable.

GSA objective

The GlobalSensitivity package provides a large variety of algorithms via gsa(f, method). The function that is used to compuite the sensitivity can be based on simulate, so that one can take advantage of already specified experiments. [1]

For example let's consider the predator prey model and perform GSA using the Morris method.

using JuliaSimModelOptimizer
using GlobalSensitivity
using Statistics
using OrdinaryDiffEq
using ModelingToolkit
import ModelingToolkit: D_nounits as D, t_nounits as t
using Plots

function lotka()
    @variables x(t)=3.1 y(t)=1.5
    @parameters α=1.3 β=0.9 γ=0.8 δ=1.8
    eqs = [
        D(x) ~ α * x - β * x * y,
        D(y) ~ -δ * y + γ * x * y,
    ]
    @named sys = ODESystem(eqs, t)
end

sys = complete(lotka())

tspan = (0.0, 10.0)

experiment = Experiment(nothing, sys;
    tspan,
    saveat = range(0, stop = 10, length = 200),
    alg = Tsit5()
)

prob = InverseProblem(experiment,
    [
        sys.α => (1.0, 5.0),
        sys.β => (1.0, 5.0),
        sys.γ => (1.0, 5.0),
        sys.δ => (1.0, 5.0),
    ])

function f(x)
    sol = simulate(experiment, prob, x)
    [mean(sol[:x]), maximum(sol[:y])]
end

lb = lowerbound(prob)
ub = upperbound(prob)

param_range = [[l, u] for (l, u) in zip(lb, ub)]

m = gsa(f, Morris(total_num_trajectory=1000, num_trajectory=150), param_range)
GlobalSensitivity.MorrisResult{Matrix{Float64}, Vector{Any}}([0.03823325120139277 -0.011090752999033532 -0.5346271474064263 0.42657664088602415; 0.4935795106011996 -1.4741712982136008 0.9892154200071233 -0.5180764453459801], [0.23089601997397075 0.03677934264451136 0.5346271474064263 0.42657664088602415; 0.5076941168145868 1.4788938619877898 1.0137310269746989 0.5374500746310664], [0.16671083305694906 0.003814080867386051 0.4320989154877898 0.19326913064929085; 0.40981831675344016 5.986385683421369 0.4882804582861998 0.20000490753201325], Any[[[0.054578571935822585, 0.6646645566265895], [0.09480806875892844, 0.23975355369187712], [0.08938287070717567, 0.4387537677558731], [0.24848814135621372, 3.2644445517605827], [0.13976946485614827, 2.9634620569957444], [0.18801930953432913, 2.833270062821426], [0.18801930953432913, 2.833270062821426], [0.21076463626226458, 0.09568103666714134], [0.2326555705760403, 0.026981039959902413], [-0.27628724715095077, 0.16178827371851184]  …  [-0.07544837955548046, 0.22266941118592345], [-0.0784302809434822, 0.22670295756428235], [-0.0788140357930106, 0.310662026193751], [-0.010122227760411742, 0.33915499720910797], [-0.031664923753516004, 0.32520279811698577], [-0.01572894046637331, 0.3656215296958608], [-0.04689318632785719, 1.344342220320473], [-0.06476013693044916, 1.2924812996372117], [-0.16777029517795683, 0.023334019402969027], [-0.18072143389848366, -0.018709557549343146]], [[-0.010086238468902239, -1.0011818504693095], [0.07111221052771653, -13.948450787034613], [0.11945804136005014, -17.235124361861246], [-0.028120098932840107, -0.09718808139431227], [-0.028120098932840107, -0.09718808139431227], [-0.028120098932840107, -0.09718808139431227], [0.020236669185299018, -0.4725741481119263], [0.021534911140910967, -0.46090163600543205], [-0.01218091816634873, -0.9173180518861392], [-0.027588658609142825, -0.9645889289443029]  …  [0.0019877698280510456, -1.0129874019572802], [0.0019877698280510456, -1.0129874019572802], [0.0019877698280510456, -1.0129874019572802], [0.0045492734881511215, -0.9442858026410037], [-0.004371824712946552, -0.6695291813828653], [-0.07627899152895938, -3.659094638624434], [-0.10299221102294288, -3.7182969701773745], [-0.018119699606268996, -0.020263237150210316], [-0.021280247195640343, -0.009687271863875961], [-0.010966680282655834, -0.009712210629478572]], [[-0.19408143111393034, 0.6441202063168187], [-0.18004889538760577, 0.7706288758983498], [-0.1808855147818989, 0.7745688475851239], [-0.1808855147818989, 0.7745688475851239], [-0.1863107128336517, 0.9735690616491199], [-0.5643486977560698, 2.564178261045539], [-0.5912366532355895, 2.499649733584879], [-0.36085595211998694, 3.109489520346686], [-0.4175273928719704, 3.0564376236292796], [-0.4175273928719704, 3.0564376236292796]  …  [-1.1699086590630412, 0.25256778640282657], [-0.05113183628771054, 1.24759592865823], [-0.03188650480031058, 1.051750387392357], [-0.029282274385148875, 0.9676503418578841], [-0.05641206248208523, 0.8556847345993772], [-0.05641206248208523, 0.8556847345993772], [-0.6421619640282218, 1.9288347331773845], [-0.6715399186522977, 1.7464249558104448], [-0.7253064315149997, 1.9275319192694613], [-2.1808340274558584, 0.24052090408743765]], [[0.7072573418078686, -0.5423650581414942], [0.6970819471041548, -0.3732434613650513], [0.6403951013346473, -1.4612903209432435], [0.49544536291963753, -2.0695430306609457], [0.9451083870448156, -1.8661227032685441], [0.713022132644846, -0.13791591033683975], [0.719307141428392, -0.24212409558876602], [0.03861162416639165, -0.3644190629373625], [0.024393264431177505, -0.39413758136583266], [0.35908607982867846, -0.5161377850799813]  …  [0.007948178613867075, -0.8594795728194874], [0.014760126432295892, -0.2841841205227719], [0.07590989249516347, -0.3968943124396532], [0.05914699106823295, -0.4868247055910102], [0.20329318542310434, -0.49118178875849927], [0.29288796336706824, -1.366718191512054], [0.29288796336706824, -1.366718191512054], [0.651944080622579, -0.105330337665471], [0.6317004281083494, -0.15700501927318294], [0.6894095499751612, -0.07576106031211684]]])

We can plot the results using

scatter(m.means[1,:], m.variances[1,:], series_annotations=[:α,:β,:y,:δ], color=:gray)
Example block output

and

scatter(m.means[2,:], m.variances[2,:], series_annotations=[:α,:β,:y,:δ], color=:gray)
Example block output

For the Sobol method, we can similarly do:

m = gsa(f, Sobol(), param_range, samples=1000)
GlobalSensitivity.SobolResult{Matrix{Float64}, Nothing, Nothing, Nothing}([-0.0008389428883520519 -8.756670289610017e-5 0.5453477447320645 0.35422274149024063; 0.06407858586209089 0.5004449209741907 0.23566374011216046 0.0656586576659527], nothing, nothing, nothing, [0.00626573037556132 0.003431279478512331 0.6315860428169109 0.4426612886457248; 0.13079977909017643 0.6194845252432749 0.2860124582905267 0.09457763813881277], nothing)

See the documentation for GlobalSensitivity for more details.

  • 1Derived from https://docs.sciml.ai/GlobalSensitivity/stable/tutorials/parallelized_gsa/ from from https://github.com/SciML/SciMLDocs, MIT licensed, see repository for details.