Introduction to JSim Sensitivity Analysis


This document describes model sensitivity analysis under JSim. Sensitivity analysis is the process of determining how small pertubations of model inputs affect model outputs. Suppose a model has an input parameter p and an output f(t). The derivative df/dp (f:p in JSim syntax) quantifies how f changes with small perturbations of p.



  • Analytic Approach vs. Finite Differences
  • A First Example
  • Absolute versus Relative Sensitivity
  • Comments or Questions?

Give feedback

Analytic Approach vs. Finite Differences

Numerical calculation of f:p can be done analytically or via finite differences. Since JSim models are normally specified analytically in MML, calculation of f:p can be simple in some circumstances. For instance if:


then, by simple calculus:


Unfortunately, two problems may arise with the analytic approach. First, not all JSim models are completely analytic. Specifically, JSim cannot symbolically differentiate variables that are calculated from JSim function generators or external functions and procedures. Second, if a model is very large, the overhead for calculating analytic derivatives may be large, making analytic calculation inefficient.

Alternatively, we may use finite differences to calculate f:p. This involves making two model runs at p=p0 and p=p0+delta (for small delta) and estimating:



The advantages of this approach are that it can work for any JSim model (not just a differentiable one) and that computation time is bounded and predictable (twice that of a normal model run). The disadvantages are that the user must now configure two model runs (instead of one) and wait twice as long for results.

At present, JSim only supports sensitivity analysis using finite differences. Future JSim releases will, hopefully, also support the analytic method where appropriate.

A First Example

Consider the following model, which generates exponential decay and decaying sine & cosine waves:

// Sensitivity analysis tutorial model
math sens1 { 
	realDomain t;
	t.min=0; t.max=4*PI;;
	real amp = 1;
	real phase = 0;
	real decay = 1;

	real u(t) = amp*exp(-decay*t);
	real v(t) = u * sin(t+phase);	
	real w(t) = v * cos(t+phase);	

Download the model and load it into your local JSim application. Then play with the model a bit until you understand its behaviour.

Now let's analyze the model's sensitivity to the decay parameter. Open JSim's "Sensitivity" subtab within the model tab. You will see a 3 column table. In the "Parameter" column type in "decay" (or select decay from the list that appears when you push the associated arrow button). The box should blacken (indicating that "decay" is acceptable here), a check mark should appear in the OK column, and decay's current value will be shown in the "Value" column. If you've changed decay's value while you were playing around above, change it back to 1 (the default value). The "Delta" column should show the default value of 0.01. This indicates that the two values decay will assume in the finite differences method will be 1 and 1.01 (delta is always added to the current value). Now press the "Run" button at the top of the Sensitivity subtab. JSim will run the model twice, once for decay=1, once for decay=1.01.

To examine results, go to a plot page. You may now examine variables such as u:decayv:decay and w:decay. You may use these variables in expressions such as:


If, at this point, you try plotting e.g. v:phase you will notice that the expression is accepted by JSim (the box blackens and the item appears in the legend) but no data is graphed. This is because JSim cannot calculate this data without doing a sensitivity analysis on phase. To remedy this, go back to the "Sensitivity" subtab, put "phase" into the 2nd row Parameter box, and rerun the sensitivity. Now JSim will perform 3 model runs: an unperturbed run, a run with decay perturbed, and a run with phase perturbed. Once the runs complete, data for v:phase will appear in the plot page.

Note that a normal (single) model run, which happens when you press the "Run" on a model's "Run Time" tab does not generate any sensitivity data. Therefore, sensitivity derivatives will show no data on plot pages after normal model runs. We realize that, in some circumstances, this could be confusing and are looking into ways to alert new users to what's going on without hampering the work of expert users. Thank you for your patience in this regard.

Absolute versus Relative Sensitivity

Often during model analysis we are interested in which parameter is a function most sensitive to. To do this we must compare the relative, normalized, sensitivity of a function to different parameters. Using the above example model, let us look at a plot of the absolute sensitivity of function u(t) to amplitude (amp) and decay. First load the model (sens2.proj) and go to the "Sensitivity" subtab:

In the Sensitivity Analysis Configurator we pick paramters amp and decay with "Value" of 1 and "Delta" of 0.01 for each and then run the sensitivity. Go to the "Abs_Sensitivity" plot page. From the absolute sensitivity plot, the sensitivity of function u(t) to both parameters amp and decay go to zero.


Now if take a look at the relative sensitivites we will see a different picture. To plot this we need to make sure the "Delta" for each paramter we are comparing is the same percentage of its value (For this example it is 1%). Both amp and decay have a "Delta" of 0.01 and "Value" of 1. If amp has a "Value" of 5.5 then its "Delta" must be set to 0.055 to give a 1% change. In JSim, Relative sensitivity is plotted as:

where f:p=(f(p0+delta)-f(p0))/delta

So for this example we have:
u:amp*(amp/u), and

Go to the "Rel_Sensitivity" plot page to look at the relative sensitivity of function u(t) to paramters amp and decay. Note how these are plotted. From this plot we see that function u(t) has a constant sensitivity, with time, to parameter amp which is not immediately apparent in the absolute sensitivity plot.

Comments or Questions?

Give feedback

Model development and archiving support at provided by the following grants: NIH U01HL122199 Analyzing the Cardiac Power Grid, 09/15/2015 - 05/31/2020, NIH/NIBIB BE08407 Software Integration, JSim and SBW 6/1/09-5/31/13; NIH/NHLBI T15 HL88516-01 Modeling for Heart, Lung and Blood: From Cell to Organ, 4/1/07-3/31/11; NSF BES-0506477 Adaptive Multi-Scale Model Simulation, 8/15/05-7/31/08; NIH/NHLBI R01 HL073598 Core 3: 3D Imaging and Computer Modeling of the Respiratory Tract, 9/1/04-8/31/09; as well as prior support from NIH/NCRR P41 RR01243 Simulation Resource in Circulatory Mass Transport and Exchange, 12/1/1980-11/30/01 and NIH/NIBIB R01 EB001973 JSim: A Simulation Analysis Platform, 3/1/02-2/28/07.