[SciPy-User] Setting up the model for a large nonlinear-in-the-parameters ODE system
Rob Clewley
rob.clewley at gmail.com
Mon Mar 23 17:09:59 EDT 2015
Hi Brian,
> I have a use case where I need to model a large ODE system.
> The purpose of these methods was to calculate some
> nonlinear-in-the-parameter variable. In the example, I just show how some
> baseline value given to the function initially along with other variable
> values would be combined in some way to calculate the parameter value -- the
> form of the math is not important as its just for example purposes.
>From what I can understand of your message, you basically have derived
(and structured) parameters that you want to preset in advance.
Typically, users do have to write some setup code of their own for
such cases. Alternatively, you'd set up auxiliary functions in your
model that determine the current value of those parameters for use in
the RHS. In PyDSTool, at least, unfortunately such functions have to
be called every time step, so this is inefficient if these values are
meant to be static during each integration. There have been some
proposals to include derived parameters inherently in PyDSTool, but
really it's very easy to manage them automatically with some simple
python wrapper code.
> Overall, the class was quite messy and kludge-y, partially because I had
> started to prematurely optimize (I know, I know, the root of all evil :( )
> and gone "Cython from the very start". Every time I wanted to change the
> RHS, I would go in and manually change equations, deleting parameters and
> variables that were no longer necessary, manually changing methods, or if I
> needed new variables, I would lazily add them "some_var = 2" style, where
> some_var can't be accessed nicely without going to the source code and
> changing what it is equal to...
Yes, that approach sounds painful and unnecessary. One good way to
manage the dependencies between equations and parameters is to make a
modular description of your model. Although you could write your own
functions (or classes) to do this involving string "elements"
(equation terms), PyDSTool offers a set of template ModelSpec classes
that can be built up using strings or Symbolic objects, and are
composable in the expected ways. Unless you start getting into
heavyweight 3rd party libraries such as Modelica, I'm not sure there's
any other convenient tools to create dynamical systems in a
structured, manageable way.
Using the ModelSpec classes means that you can make configurable
modules out of your model, which you can interchange or add/delete as
you wish. The parameter declarations associated with each module
belong to the ModelSpec object, so there's no book-keeping for you to
do. In fact, before the model is finally created, there are automatic
internal checks for consistency and resolution of all names used in
your system.
See this tutorial, for instance:
http://www.ni.gsu.edu/~rclewley/PyDSTool/Tutorial/Tutorial_compneuro.html
or ModelSpec_test.py in the examples/ folder. There are pages
specifically about using ModelSpec and the associated tools on the
website.
Maybe you could help develop a simpler tutorial for a system that's
not related to computational neuroscience, based on your use case? An
example like the one mentioned by the previous poster on this thread,
involving a user creating a coupling matrix to determine what elements
are created in the final model, would be a particularly valuable and
interesting demonstration. Feel free to discuss details with me off
list.
-Rob
More information about the SciPy-User
mailing list