Simulating multiple model parameterizations using scenarios and simfunctions

1 view (last 30 days)
I'm having trouble simultaneously simulating multiple parameterizations of a model using simfunctions and scenarios, in R2019b. Please refer to the example below. Is there a proper way of doing this? I think I could get around this error be inputting all of the parameterizations when calling 'createSimFunction', but this is not possible in my application because I do not know a priori how many different parameterizations I plan to simulate.
Thank you,
% The following works:
variants = getvariant(m1);
singleMeal = sbioselect(m1,'Name','Single Meal');
sObj = SimBiology.Scenarios;
f = createSimFunction(m1,sObj,{'[Plasma Glu Conc]','[Plasma Ins Conc]'},[]);
sd = f(sObj,24);
% But the following triggers an error:
nIndivs = 2; % number of parameterizations (let's pretend each individual has different parameterizations -- although in this example they have the same parameterization).
for iEntry = 1:sObj.NumberOfEntries
sObj = sObj.updateEntry(iEntry,'Content',repmat(sObj.getEntry(iEntry).Content,nIndivs,1));
sd2 = f(sObj,24);

Accepted Answer

Abed Alnaif
Abed Alnaif on 12 Dec 2019
Fulden emailed me an example of how to get this to work, and I'm posting it here for reference. Thank you, Florian and Fuilden, for your help with this. This is my first time using the new scenarios object, and I'm really liking it now that I experienced its flexibility and how one can construct complex combinations with very few lines of code. It's a very nice addition to SimBiology! It would be good in the future if the 'sbiofit' command allowed the user to specify different scenarios for each of the groups.
m = sbmlimport('lotka');
cs = getconfigset(m);
set(cs.SolverOptions, 'RelativeTolerance', 1e-6);
% Define doses
d1 = sbiodose('dose for y1');
set(d1, 'TargetName', 'y1');
set(d1, 'Amount', 50);
d2 = sbiodose('dose for y2');
set(d2, 'TargetName', 'y2');
set(d2, 'Amount', 50);
% Define variants
v1 = sbiovariant('individual1');
v1.addcontent({'species', 'y1', 'value', 900});
v2 = sbiovariant('individual2');
v2.addcontent({'species', 'y1', 'value', 900});
v3 = sbiovariant('individual3');
v3.addcontent({'species', 'y1', 'value', 900});
% Create scenarios over variants and doses:
sObj = SimBiology.Scenarios('individuals', [v1, v2]);
add(sObj, 'cartesian', 'doses', [d1, d2]);
% Print content of scenarios object
% Create SimFunction and evaluate
f = createSimFunction(m, sObj, {'y1', 'y2'}, [], 'AutoAccelerate', false);
sd = f(sObj, 10);
% Add additional values to scenarios
sObj.updateEntry('individuals','Content', [v1, v2, v3]);
% Print content of scenarios object
sd = f(sObj, 10);

More Answers (1)

Florian Augustin
Florian Augustin on 10 Dec 2019
Hi Abed,
The short answer why you see the error message is that the SimFunction is being created with one dose input, and it is called (after the modification of the scnearios object) with two dose inputs. In the scearios object, each element in the dose entry is treated as a separate dose input to the SimFunction. The immediate fix would be to create a new SimFunction after you updated the scenarios object.
But this may be expensive in your application and possibly unnecessary. In your example you mention different parameterizations of your doses. In this case, you may be able to use parameterized doses? You could create a scenarios object containing the parameterization parameter(s) instead of the dose objects:
sbioloadproject('insulindemo', 'm1');
variants = getvariant(m1);
singleMeal = sbioselect(m1, 'Name', 'Single Meal');
addparameter(m1, 'DoseAmount', 78, 'Units', 'gram');
set(singleMeal, 'Amount', 'DoseAmount');
sObj = SimBiology.Scenarios;
add(sObj,'cartesian', 'variants', variants);
add(sObj,'cartesian', 'DoseAmount', [75, 78, 85]);
f = createSimFunction(m1, sObj, {'[Plasma Glu Conc]', '[Plasma Ins Conc]'}, singleMeal);
sd = f(sObj, 24, getTable(singleMeal));
There may be other options, but those probably depend on your application.
I hope this helps, but feel free to follow up if there's anything we can help with.
Abed Alnaif
Abed Alnaif on 11 Dec 2019
Hi Florian,
In my application, the doses aren't the same across the scenarios. In some scenarios, a dose is not active, in which case I replaced the dose object with an empty dose object. So, I can't use 'cartesian' combinations.

Sign in to comment.


More Answers in the  SimBiology Community


Find more on Scan Parameter Ranges in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!