Vector Variables, Preload, and External matlab functions (in m files) in Simbiology

2 visualizaciones (últimos 30 días)
In a previous question, I asked about how to switch between using an ODE-calculated species value, and a forced function fit. In response to some very useful interaction with the Mathworks experts (thank you Arthur), I now have a model with an ODE-calculated species value (x_ODE), a parameter whose value is set by a repeat-assignment-rule parameter (x_forced), a switch (switch_force) and a species whose value is set to either x_ODE or x_forced based upon the switch using a repeat assignment (you could use two repeat assignment rules as well, and select one active and the other not). This node (x_used) is the value used wherever needed (that is, where x_ODE would normally appear).
So I can set x_forced=sin(time) as a test case, and that works. This is a good academic exercise, but few biological functions are based upon a pure sine wave. I'd like to use a spline function set x_forced. So I'd like to use x_forced = spline(tvec, xvec, time), where tvec and xvec are vectors of time and function value, and time is the system variable time.
So, some questions: 1) Can I use vector variables within simbiology? 2) If so, is there a preload function, as in Simulink that I could use to load the vectors to fix the simbiology variable values, prior to simulation? 3) If not, can simulink call external m files, so that my repeat assignment rule would be x_forced = x_external(time) and x_external.m would be an m. function file that (on first call) reads a file, and then (and on subsequent calls) uses the data loaded from the file, and the spline function, to return the value of x at time "time"?
SBML2 only allows for parameter values that are type "double" (SBML 2, section 4.7.2). I believe that this means scalar (parameters are all scalar in Pathway Designer, for example). But biological models sometimes need vector data!

Respuesta aceptada

Arthur Goldsipe
Arthur Goldsipe el 15 de Mzo. de 2018
Currently, SimBiology only supports scalar quantities for species, compartment, and parameter values. However (as you already discovered), you can use arbitrary MATLAB functions in the mathematical expressions you write in SimBiology models. This includes using functions that you write yourself. That is the approach I used for the external forcing functions in the insulin demo mentioned in the previous post. Take a look at the function files EndogenousGlucoseProduction.m, GlucoseAppearanceRate.m, and PlasmaInsulin.m to see how I implemented them.
One note: Although you can use almost any MATLAB function, not all functions or language features are compatible with SimBiology's acceleration feature. As described here, acceleration requires that you restrict yourself to a subset of MATLAB that is compatible with code generation.

Más respuestas (2)

Jim Bosley
Jim Bosley el 14 de Mzo. de 2018
Editada: Jim Bosley el 14 de Mzo. de 2018
Answered one question: I CAN use a user-defined function call to get this information into the model. So if I use
function y = grossblatz(t)
y=sin(t/240); % Or I could put in my spline function
end
And then set a repeat assignment rule for calc_par to be calc_par = grossblatz(time), I get the time function in Simbiology. This is likely simpler than creating a vector class in Simbiology. I'm assuming that such a class does not now exist. Confirm/deny?
Thanks to Stephen for linking to the earlier post.

Jim Bosley
Jim Bosley el 15 de Mzo. de 2018
Editada: Jim Bosley el 15 de Mzo. de 2018
Arthur,
Thank you. One of the things I like about Simbiology is that you have some stuff (like fitting, even nlme fitting) built in, and for other things the power of scripting (via Matlab) is available. Clearly, to do what I want, the Matlab functions work fine. As for "preload", I think that if you run the models via a script you can preload whatever you want. So this was a case of me asking a question I should have known the answer to, and for which I found a solution about 30 minutes after I asked it.
That said, there are details that about this that would not be obvious to me. Your point about acceleration is useful and I thank you for the time it will save me.
BTW, since your answer points out that one can use simbiology to execute matlab functions, I'll point out how nicely one can explain a model using the Matlab Markup language - you write an m file script with proper formatting, and it becomes an explanatory document that runs your model and shows your results in whatever summary form you choose (which is what, in my case, my client's program manager wants). The m file also shows to the pharmacometrician/modeler (who is often my working contact) the code used to exercise the model. Your insulindemo is a great example of this.
I still think we need vector and matrix data (and probably character strings and filename support) available in biology models, but I understand that implementing data types in software is to be taken lightly and for Simbiology now it is premature: vector and array data are not supported by SBML 2.0.
That said, the SBML 3 standard has a draft section on arrays (<http://sbml.org/Documents/Specifications#SBML_Level_3_Packages)>. I suspect that the MathWork's expertise in coding array data will give Simbiology an advantage this when v3 becomes finalized.
As an aside, I'm also pretty excited about the layout standard that should be in v3. SBML 2 has no standard for positional/layout notation. This has been needed for a while.
Thanks again for your timely response.
Jim

Comunidades de usuarios

Más respuestas en  SimBiology Community

Categorías

Más información sobre Scan Parameter Ranges en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by