min function for SimBiology local sensitivity
When you have a SimBiology model with a custom function that calls
minand you are performing local sensitivity analysis on the model, replace
simbio.complexstep.minin your custom function.
You do not need to update SimBiology expressions (such as reaction rates or rules) that directly call
min. SimBiology automatically replaces
Use Replacements for
max in Custom Functions for SimBiology Local Sensitivity Analysis
This example shows how to use replacements for
max in some custom functions so that the model becomes compatible with local sensitivity analysis (LSA). The replacement functions are
simbio.complexstep.max. Specifically, one of the custom functions used by this example computes the net amount of a drug species moved between two compartments. The other custom function sets the thresholds for the forward and reverse reaction fluxes.
Create a model.
model = sbiomodel("model"); c1 = addcompartment(model,"c1"); c2 = addcompartment(model,"c2"); s1 = addspecies(c1,"Drug",2); s2 = addspecies(c2,"Drug"); netFlux = addspecies(c1,"netFlux"); reaction = addreaction(model,"c1.Drug <-> c2.Drug"); kf = addparameter(model,"kf",1.0); kr = addparameter(model,"kr",1.5); fluxMin = addparameter(model,"fluxMin",0.1); fluxMax = addparameter(model,"fluxMax",10);
Define the net amount of drug species moved between two compartments using a custom function
calculateNetFlux based on the constrained forward and reverse reaction fluxes, which are defined later.
rule = addrule(model,"netFlux = calculateNetFlux(boundedForwardFlux,boundedReverseFlux)","rate");
simbio.complexstep.abs, and the function is already saved in the provided file named calculateNetFlux
function netFlux = calculateNetAmount(forwardFlux,reverseFlux) netFlux = simbio.complexstep.abs(forwardFlux-reverseFlux); end
Define the forward and reverse fluxes of the reaction. Set the thresholds on the fluxes using the
imposeBounds custom function.
boundedForwardFlux = addparameter(model,"boundedForwardFlux","Constant",false); boundedReverseFlux = addparameter(model,"boundedReverseFlux","Constant",false); forwardFlux = addparameter(model,"forwardFlux","Constant",false); reverseFlux = addparameter(model,"reverseFlux","Constant",false); forwardFlux = addrule(model,"forwardFlux = kf*c1.Drug","repeatedAssignment"); reverseFlux = addrule(model,"reverseFlux = kr*c2.Drug","repeatedAssignment"); boundedForwardFlux = addrule(model,"boundedForwardFlux = imposeBounds(forwardFlux,fluxMin,fluxMax)","repeatedAssignment"); boundedReverseFlux = addrule(model,"boundedReverseFlux = imposeBounds(reverseFlux,fluxMin,fluxMax)","repeatedAssignment"); reaction.ReactionRate = "boundedForwardFlux - boundedReverseFlux";
simbio.complexstep.max to set the lower and upper limits for the reaction flux.
function boundedFlux = imposeBounds(fluxInput,fluxMin,fluxMax) fm = simbio.complexstep.max(fluxMin,fluxInput); boundedFlux = simbio.complexstep.min(fluxMax,fm); end
Enable local sensitivity analysis.
configset = getconfigset(model); configset.RuntimeOptions.StatesToLog = "netFlux"; configset.SolverOptions.SensitivityAnalysis = true; sensitivityOptions = configset.SensitivityAnalysisOptions; sensitivityOptions.Inputs = [kf,kr]; sensitivityOptions.Outputs = netFlux;
Temporarily disable the warning about unsupported functions. The warning is safe to ignore.
warnState = warning("off","SimBiology:senscsverify:UnsupportedFunction"); cleanupobj = onCleanup(@()warning(warnState));
Simulate the model and perform sensitivity analysis.
simdata = sbiosimulate(model); sbioplot(simdata);
X — First input
First input, specified as a numeric scalar.
Complex Number Support: Yes
Y — Second input
Second input, specified as a numeric scalar.
Complex Number Support: Yes
 Martins, Joaquim, Ilan Kroo, and Juan Alonso. “An Automated Method for Sensitivity Analysis Using Complex Variables.” In 38th Aerospace Sciences Meeting and Exhibit. Reno, NV, U.S.A.: American Institute of Aeronautics and Astronautics, 2000. https://doi.org/10.2514/6.2000-689.
Introduced in R2022b