main content

function-凯发k8网页登录

function-like interface to execute simbiology models

description

the simfunction object provides an interface that allows you to execute a simbiology® model like a function and a workflow to perform parameter scans (in parallel if parallel computing toolbox™ is available), monte carlo simulations, and scans with multiple or vectorized doses. since a simfunction object can be executed like a function handle, you can customize it to integrate simbiology models with other matlab® products and other custom analyses (such as visual predictive checks).

use the createsimfunction method to construct the simfunction object. simfunction objects are immutable once created and automatically accelerated at the first function execution.

syntax

if you specified any dosing information when you called createsimfunction to construct the simfunction object f, then f has the following syntaxes.

simdata = f(phi,t_stop,u,t_output) returns a simdata after simulating a simbiology model using the initial conditions or simulation scenarios specified in phi, simulation stop time, t_stop, dosing information, u, and output time, t_output.

simdata = f(phi,t_stop,u) runs simulations using the input arguments phi, t_stop, and u.

if you did not specify any dosing information when you called createsimfunction, then f has the following syntaxes:

simdata = f(phi,t_stop) returns a simdata after simulating the model using initial conditions or simulation scenarios specified in phi, and simulation stop time, t_stop.

simdata = f(phi,t_stop,[],t_output) uses the input arguments phi, t_stop, empty dosed argument [], and t_output. you must specify u, the dosing information, as an empty array[] for this signature. when t_output is empty and t_stop is specified, the simulations report the solver time points until t_stop. when t_output is specified and t_stop is empty, only the time points in t_output are reported. when both are specified, the reported time points are the union of solver time points and the time points in t_output. if the last t_output is greater than the corresponding t_stop, then simulation proceeds until the last time point in t_output.

simdata = f(phi,tbl) uses the input arguments phi and tbl. using this signature only lets you specify output times as one of the variables of tbl. any data row in tbl where all dependent variable columns having nan values is ignored.

[t,y] = f(_) returns t, a cell array of numeric vector, and y, a cell array of 2-d numeric matrices, using any of the input arguments in the preceding syntaxes.

input arguments

phi

one of the following:

  • empty array [] or empty cell array {}, meaning to perform simulations using the baseline initial values, that is, the values listed in the parameter property of the simfunction object, without altering them.

  • matrix of size s-by-p, where s is the number of simulations to perform and p is the number of parameters specified in the params argument when you called createsimfunction to construct f. each simulation is performed with the parameters specified in the corresponding row of phi.

  • s-by-v matrix of variant objects or a cell column vector of length s, where each element consists of a row vector of variant objects. s is the number of simulations to perform, and v is the number of variant objects. these variants are only allowed to modify the simfunction input parameters, that is, model elements that were specified as the params input argument when you called createsimfunction. in other words, you must specify the variant parameters as the input parameters when you create the simfunction object. any simfunction input parameters that are not specified in the variants use their baseline initial values.

    if, within a row of variants, multiple entries refer to the same model element, the last occurrence is used for simulation.

  • scalar object containing s number of scenarios.

when phi is specified as a 1-by-p or 1-by-v matrix (or a scenarios object with only one scenario), then all simulations use the same parameters, and the number of simulations is determined from the t_stop, u, or t_output argument in that order. for example, if phi and t_stop have a single row and u is a matrix of size n-by-dosetargets, the number of simulations is determined as n.

when phi is specified as a simbiology.scenarios object, all scenarios are simulated. variants are applied before values from the scenarios are set.

t_stop

  • scalar specifying the same stop time for all simulations

  • vector of size n specifying a stop time for each simulation for all n simulations

u

  • empty array [] to apply no doses during simulation unless you specify phi as a scenarios object that has doses defined in its entries.

  • of dosing information with two or three variables containing scheduledose data (scheduledose table), namely, dose time, dose amount, and dose rate (optional). name the table variables as follows.

    u.properties.variablenames = {'time','amount','rate'};

    if unitconversion is on, specify units for each variable. for instance, you can specify units as follows.

    u.properties.variableunits = {'second','molecule','molecule/second'};

    this table can have multiple rows, where each row represents a dose applied to the dose target at a specified dose time with a specified amount and rate if available.

  • with one row and five variables containing repeatdose data (repeatdose table). dose rate variable is optional. name the variables as follows.

    u.properties.variablenames = {'starttime','amount','rate','interval','repeatcount'};

    if unitconversion is on, specify units for each variable. units for 'repeatcount' variable can be empty '' or 'dimensionless'. the unit of the 'amount' variable must be dimensionally consistent with that of the target species. for example, if the unit of target species is in an amount unit (such as mole or molecule), then the 'amount' variable unit must have the same dimension, i.e., its unit must be an amount unit and cannot be a mass unit (such as gram or kilogram). the unit for the 'rate' variable must be dimensionally consistent as well.

    u.properties.variableunits = {'second','molecule','molecule/second','second','dimensionless'};

    tip

    if you already have a dose object (scheduledose or repeatdose), you can get this dose table by using the method of the object.

  • cell array of tables of size 1-by-n, where n is the number of dose targets. each cell can represent either table as described previously.

  • cell array of tables of size s-by-n, where s is the number of simulations and n is the number of dose targets. each cell represents a table. s is equal to the number of rows in phi.

if u is a cell array of tables, then:

  • if phi is also a scenarios object, the combined number of doses in the scenarios object and the number of columns in u must equal to the number of elements in the dosed property of the simfunction object. in other words, the dosing information that you specified during the creation of the simfunction object must be consistent with the dosing information you specify in the execution of the object. the total number of elements for the dosed property is equal to the combination of any doses from the input scenarios object and doses in the dosed input argument of createsimfunction.

  • if phi is not a scenarios object, the number of columns (n) in the cell array u must be equal to the number of elements in the dosed property of the simfunction object. the order of dose tables must also match the order of dosed species in createsimfunction. that is, simbiology assumes one-to-one correspondence between the columns of u and dose targets specified in the dosed property of the simfunction object, meaning the doses (dose tables) in the first column of u are applied to the first dose target in the dosed property and so on.

  • the ith dose for the jth dose target is ignored if u{i,j} = [].

  • if the ith dose is not parameterized, u{i,j} can be [] or either type of table (the scheduledose or repeatdose table).

  • if the ith dose is parameterized, u{i,j} must be [] or a repeatdose table with one row and a column for each property (starttime, amount, rate, interval, repeatcount) that is not parameterized. it is not required to create a column for a dose property that is parameterized. if all of the properties are parameterized, you can pass in a table with one row and no columns to specify the parameterized dose is applied during simulations. to create such table, use table.empty(1,0).

t_output

  • vector of monotonically increasing output times that is applied to all simulations

  • cell array containing a single time vector that is applied to all simulations

  • cell array of vectors representing output times. the ith cell element provides the output times for the ith simulation. the number of elements in the cell array must match the number of rows (simulations) in phi.

tbl

or (statistics and machine learning toolbox) that has time and dosing information such as group labels, independent variable, dependent variable(s), amount(s), and rate(s). you must name the variables of the table or data set as 'group','time','dependentvar1','dependentvar2',...,'amount1','rate1','amount2','rate2',.... the rate variable is optional for each dose.

if the dosed property of the simfunction object f is empty, then amount- and rate-related variables are not required. the number of groups in tbl must be equal to the number of rows, or the number of scenarios, in phi. the combined dosing information in phi, if phi is a simbiology.scenarios object, and the number of amount and rate columns in tbl must be equal to the number of doses in the dosed property of the object f. if tbl has additional columns, they are ignored.

if unitconversion is on, specify a unit for each variable. the unit of 'amount' variable must be dimensionally consistent with that of the target species. see the description of the input argument u for details.

output arguments

simdata

array of simdata objects that contains results from executing the simfunction f. the number of elements in the simdata array is the same as the number of rows in phi. the number of columns in each element of the simdata array, that is, simdata(i).data, is equal to the number of elements in the observed cell array which was specified when creating f.

t

cell array containing a numeric vector of size s x 1. s is the number of simulations. the ith element of t contains the time point from the ith simulation.

y

cell array of 2-d numeric matrices. the ith element of y contains data from the ith simulation. the number of rows in t{i} is equal to the number of rows in y{i}.

constructor summary

createsimfunction (model)create simfunction object

method summary

prepare simfunction object for accelerated simulations
determine if simfunction object is accelerated

property summary

parameters

with variables named:

  • 'name'

  • 'value'

  • 'type'

  • 'units' (only if unitconversion is turned on)

the table contains information about model quantities (species, compartments, or parameters) that define the inputs of a simfunction object. for instance, this table can contain parameters or species whose values are being scanned by the simfunction object. this property is read only.

observables

with variables named:

  • 'name'

  • 'type'

  • 'units' (only if unitconversion is turned on)

this table contains information about model quantities (species, compartments, or parameters) that define the output of a simfunction object. this property is read only.

dosed

containing dosing information with variables named:

  • 'targetname'

  • 'targetdimension' (only if unitconversion is turned on)

in addition, the table also contains variables for each property that is parameterized. for each parameterized property, two variables are added to this table. the first variable has the same name as the property name and the value is the name of the specified parameter. the second variable has the property name suffixed by value (propertynamevalue), and the value is the default value of the parameter. if the unitconversion is on, the unit column is also added with the name propertynameunits.

suppose the amount property of a repeat dose targeting the drug species is parameterized by setting it to a model parameter called amountparam with the value of 10 milligram, and unitconversion is on. the dosed table contains the following variables:

targetnametargetdimensionamountamountvalueamountunits
'drug''mass (e.g., gram)' 'amountparam'10'milligram'
useparallel

logical. if true and parallel computing toolbox is available, simfunction is executed in parallel. this property is read-only.

unitconversion

logical. if true:

  • during the execution of the simfunction object, phi is assumed to be in the same units as units for corresponding model quantities specified in the params argument when the object was created using the createsimfunction method.

  • time (t_output or t_stop) is assumed to be in the same unit as the timeunits property of the active of the simbiology model from which f was created.

  • variables of dose tables (u) must have units specified by setting u.properties.variableunits to a cell array of appropriate units. the dimension of the dose target such as an amount (molecule, mole, etc.) or mass (gram, kilogram, etc.), is stored on the dosed property of f.

  • the simulation result is in the same units as those specified on the corresponding quantities in the simbiology model from which f was created.

this property is read only.

autoaccelerate

logical. when true, the model is accelerated on the first evaluation of the simfunction object.

this property is read only.

dependentfiles

cell array of character vectors containing the names of files that the model depends on. this property is used for deployment. this property is read only.

timeunits

character vector that represents the time units.

examples

this example shows how to simulate the glucose-insulin responses for the normal and diabetic subjects.

load the model of glucose-insulin response. for details about the model, see the background section in simulate the glucose-insulin response.

sbioloadproject('insulindemo', 'm1')

the model contains different initial conditions stored in various variants.

variants = getvariant(m1);

get the initial conditions for the type 2 diabetic patient.

type2 = variants(1)
type2 = 
   simbiology variant - type 2 diabetic (inactive)
   contentindex:     type:        name:             property:           value:
   1                 parameter    plasma volume ... value               1.49
   2                 parameter    k1                value               .042
   3                 parameter    k2                value               .071
   4                 parameter    plasma volume ... value               .04
   5                 parameter    m1                value               .379
   6                 parameter    m2                value               .673
   7                 parameter    m4                value               .269
   8                 parameter    m5                value               .0526
   9                 parameter    m6                value               .8118
   10                parameter    hepatic extrac... value               .6
   11                parameter    kmax              value               .0465
   12                parameter    kmin              value               .0076
   13                parameter    kabs              value               .023
   14                parameter    kgri              value               .0465
   15                parameter    f                 value               .9
   16                parameter    a                 value               6e-05
   17                parameter    b                 value               .68
   18                parameter    c                 value               .00023
   19                parameter    d                 value               .09
   20                parameter    kp1               value               3.09
   21                parameter    kp2               value               .0007
   22                parameter    kp3               value               .005
   23                parameter    kp4               value               .0786
   24                parameter    ki                value               .0066
   25                parameter    [ins ind glu u... value               1.0
   26                parameter    vm0               value               4.65
   27                parameter    vmx               value               .034
   28                parameter    km                value               466.21
   29                parameter    p2u               value               .084
   30                parameter    k                 value               .99
   31                parameter    alpha             value               .013
   32                parameter    beta              value               .05
   33                parameter    gamma             value               .5
   34                parameter    ke1               value               .0007
   35                parameter    ke2               value               269.0
   36                parameter    basal plasma g... value               164.18
   37                parameter    basal plasma i... value               54.81

suppress an informational warning that is issued during simulations.

warnsettings = warning('off','simbiology:dimanalysisnotdone_matlabfcn_dimensionless');

create simfunction objects to simulate the glucose-insulin response for the normal and diabetic subjects.

  • specify an empty array {} for the second input argument to denote that the model will be simulated using the base parameter values (that is, no parameter scanning will be performed).

  • specify the plasma glucose and insulin concentrations as responses (outputs of the function to be plotted).

  • specify the species dose as the dosed species. this species represents the initial concentration of glucose at the start of the simulation.

normsim = createsimfunction(m1,{},...
             {'[plasma glu conc]','[plasma ins conc]'},'dose')
normsim = 
simfunction
parameters:
observables: 
            name                type                 units         
    _____________________    ___________    _______________________
    {'[plasma glu conc]'}    {'species'}    {'milligram/deciliter'}
    {'[plasma ins conc]'}    {'species'}    {'picomole/liter'     }
dosed: 
    targetname       targetdimension   
    __________    _____________________
     {'dose'}     {'mass (e.g., gram)'}
timeunits: hour

for the diabetic patient, specify the initial conditions using the variant type2.

diabsim = createsimfunction(m1,{},...
             {'[plasma glu conc]','[plasma ins conc]'},'dose',type2)
diabsim = 
simfunction
parameters:
observables: 
            name                type                 units         
    _____________________    ___________    _______________________
    {'[plasma glu conc]'}    {'species'}    {'milligram/deciliter'}
    {'[plasma ins conc]'}    {'species'}    {'picomole/liter'     }
dosed: 
    targetname       targetdimension   
    __________    _____________________
     {'dose'}     {'mass (e.g., gram)'}
timeunits: hour

select a dose that represents a single meal of 78 grams of glucose at the start of the simulation.

singlemeal = sbioselect(m1,'name','single meal');

convert the dosing information to the table format.

mealtable  = gettable(singlemeal);

simulate the glucose-insulin response for a normal subject for 24 hours.

sbioplot(normsim([],24,mealtable));

figure contains an axes object. the axes object with title states versus time, xlabel time, ylabel states contains 2 objects of type line. these objects represent glucose appearance.plasma glu conc, insulin secretion.plasma ins conc.

simulate the glucose-insulin response for a diabetic subject for 24 hours.

sbioplot(diabsim([],24,mealtable));

figure contains an axes object. the axes object with title states versus time, xlabel time, ylabel states contains 2 objects of type line. these objects represent glucose appearance.plasma glu conc, insulin secretion.plasma ins conc.

perform a scan using variants

suppose you want to perform a parameter scan using an array of variants that contain different initial conditions for different insulin impairments. for example, the model m1 has variants that correspond to the low insulin sensitivity and high insulin sensitivity. you can simulate the model for both conditions via a single call to the simfunction object.

select the variants to scan.

vartoscan = sbioselect(m1,'name',...
                    {'low insulin sensitivity','high insulin sensitivity'});

check which model parameters are being stored in each variant.

vartoscan(1)
ans = 
   simbiology variant - low insulin sensitivity (inactive)
   contentindex:     type:        name:             property:           value:
   1                 parameter    vmx               value               .0235
   2                 parameter    kp3               value               .0045
vartoscan(2)
ans = 
   simbiology variant - high insulin sensitivity (inactive)
   contentindex:     type:        name:             property:           value:
   1                 parameter    vmx               value               .094
   2                 parameter    kp3               value               .018

both variants store alternate values for vmx and kp3 parameters. you need to specify them as input parameters when you create a simfunction object.

create a simfunction object to scan the variants.

variantscan = createsimfunction(m1,{'vmx','kp3'},...
          {'[plasma glu conc]','[plasma ins conc]'},'dose');

simulate the model and plot the results. run 1 include simulation results for the low insulin sensitivity and run 2 for the high insulin sensitivity.

sbioplot(variantscan(vartoscan,24,mealtable));

figure contains an axes object. the axes object with title states versus time, xlabel time, ylabel states contains 4 objects of type line. these objects represent run 1 - glucose appearance.plasma glu conc, run 1 - insulin secretion.plasma ins conc, run 2 - glucose appearance.plasma glu conc, run 2 - insulin secretion.plasma ins conc.

low insulin sensitivity lead to increased and prolonged plasma glucose concentration.

restore warning settings.

warning(warnsettings);

this example shows how to scan initial amounts of a species from a radioactive decay model with the first-order reaction dzdt=cx, where x and z are species and c is the forward rate constant.

load the sample project containing the radiodecay model m1.

sbioloadproject radiodecay;

create a simfunction object f to scan initial amounts of species x.

f = createsimfunction(m1,{'x'},{'x','z'},[])
f = 
simfunction
parameters:
    name     value       type           units    
    _____    _____    ___________    ____________
    {'x'}    1000     {'species'}    {'molecule'}
observables: 
    name        type           units    
    _____    ___________    ____________
    {'x'}    {'species'}    {'molecule'}
    {'z'}    {'species'}    {'molecule'}
dosed: none
timeunits: second

define four different initial amounts of species x for scanning. the number of rows indicates the total number of simulations, and each simulation uses the parameter value specified in each row of the vector.

phi = [200; 400; 600; 800];

run simulations until the stop time is 20 and plot the simulation results.

sbioplot(f(phi, 20));

figure contains an axes object. the axes object with title states versus time, xlabel time, ylabel states contains 8 objects of type line. these objects represent run 1 - x, run 1 - z, run 2 - x, run 2 - z, run 3 - x, run 3 - z, run 4 - x, run 4 - z.

this example shows how to simulate and scan a parameter of a radiodecay model while a species is being dosed.

load the sample project containing the radiodecay model m1.

sbioloadproject radiodecay;

create a simfunction object f specifying parameter reaction1.c to be scanned and species x as a dosed target.

f = createsimfunction(m1,{'reaction1.c'},{'x','z'},{'x'});

define a scalar dose of amount 200 molecules given at three time points (5, 10, and 15 seconds).

dosetime = [5 10 15];
dose = [200 200 200];
u = table(dosetime', dose');
u.properties.variablenames = {'time','amount'};
u.properties.variableunits = {'second','molecule'};

define the parameter values for reaction1.c to scan.

phi = [0.1 0.2 0.5]';

simulate the model for 20 seconds and plot the results.

sbioplot(f(phi,20,u));

figure contains an axes object. the axes object with title states versus time, xlabel time, ylabel states contains 6 objects of type line. these objects represent run 1 - x, run 1 - z, run 2 - x, run 2 - z, run 3 - x, run 3 - z.

you can also specify different dose amounts at different times.

d1 = table(5,100);
d1.properties.variablenames = {'time','amount'};
d1.properties.variableunits = {'second','molecule'};
d2 = table(10,300);
d2.properties.variablenames = {'time','amount'};
d2.properties.variableunits = {'second','molecule'};
d3 = table(15,600);
d3.properties.variablenames = {'time','amount'};
d3.properties.variableunits = {'second','molecule'};

simulate the model using these doses and plot the results.

sbioplot(f(phi,20,{d1;d2;d3}));

figure contains an axes object. the axes object with title states versus time, xlabel time, ylabel states contains 6 objects of type line. these objects represent run 1 - x, run 1 - z, run 2 - x, run 2 - z, run 3 - x, run 3 - z.

you can also define a cell array of dose tables.

u = cell(3,1);
dosetime = [5 10 15];
dose = [200 200 200];
u{1} = table(dosetime',dose');
u{1}.properties.variablenames = {'time','amount'};
u{1}.properties.variableunits = {'second','molecule'};
dosetime2 = [2 6 12];
dose2 = [500 500 500];
u{2} = table(dosetime2', dose2');
u{2}.properties.variablenames = {'time','amount'};
u{2}.properties.variableunits = {'second','molecule'};
dosetime3 = [3 8 18];
dose3 = [100 100 100];
u{3} = table(dosetime3', dose3');
u{3}.properties.variablenames = {'time','amount'};
u{3}.properties.variableunits = {'second','molecule'};

simulate the model using the dose tables and plot results.

sbioplot(f(phi,20,u));

figure contains an axes object. the axes object with title states versus time, xlabel time, ylabel states contains 6 objects of type line. these objects represent run 1 - x, run 1 - z, run 2 - x, run 2 - z, run 3 - x, run 3 - z.

references

[1] gillespie, d.t. (1977). exact stochastic simulation of coupled chemical reactions. the journal of physical chemistry. 81(25), 2340–2361.

version history

introduced in r2014a

see also

| | | | | |

topics

    网站地图