[SciPy-user] Usage of PyDSTool
Rob Clewley
rob.clewley@gmail....
Wed Aug 13 11:13:19 CDT 2008
>> I wonder I have to provide a textual description of the model of the
>> dynamical system, either using PyDSTool.args() with varspecs, pars and
>> fnpecs attributes, or using a xml file in vfgen case.
>>
>> I do have a python fonction available computing y'=f(y,t). y is a vector
>> of len 2n+2 corresponding to the real and imaginary parts of n complex
>> variables p_n evolving as p_n' = Cn*sum(p_n)+sn*p_n, and two others
>> quantities x and x'.
Right now PyDSTool cannot handle pre-defined python functions for RHS
defintions. In order to work in a non-index world and know properties
of each ODE, certain things must be guaranteed, such as the ordering
of variable names etc. This is all handled internally but the user has
to specify everything using the textual description.
However, there is a ModelSpec module which allows you to build
representations of RHS functions in a way that depend on n, using
symbolic objects. Summing over the p_n is then a matter of using a
'for' constructor that will take all variables of a certain type and
add them up. You then "build" the PyDSTool representation from the
symbolic one. This would be a good thing for me to write a tutorial
on, I suppose -- right now you can only learn from looking at
tests/ModelSpec_test.py and some of the factory functions in
Toolbox/neuralcomp.py (in particular, the makeSoma function therein).
So, that would be harder....
Anyway, even with the string version, you could just write a function
that takes n and spits out a dictionary of strings for each p_n'. It
would like a bit like this:
def my_rhs(varname, n):
rhs_dict = {}
sum_term = " + ".join([varname+'_%i' % i for i in range(n)])
for i in range(n):
rhs_dict[varname+'_%i' % i] = 'C_%i * (%s) + s_%i * %s_%i' %
(i, sum_term, i, varname, i)
return rhs_dict
>>> my_rhs('p',3)
{'p_0': 'C_0 * (p_0 + p_1 + p_2) + s_0 * p_0',
'p_1': 'C_1 * (p_0 + p_1 + p_2) + s_1 * p_1',
'p_2': 'C_2 * (p_0 + p_1 + p_2) + s_2 * p_2'}
This dict is ready to be used in your PyDSTool ODE definition, and you
have to declare your parameters C_i and s_i (which you can also make
factory functions for).
Feel free to post your attempt if you can't get it to work, and I'll
try to fix it. Here's a link to info about the multi-quantity
ModelSpec definitions which are modeled on the same syntax as that in
XPP (sorry for the horrifically long link):
http://www.cam.cornell.edu/~rclewley/cgi-bin/moin.cgi/ModelSpec#head-5a20b27323542c61c63ef968c27a924d18b82099
HTH,
Rob
--
Robert H. Clewley, Ph.D.
Assistant Professor
Department of Mathematics and Statistics
Georgia State University
720 COE, 30 Pryor St
Atlanta, GA 30303, USA
tel: 404-413-6420 fax: 404-413-6403
http://www2.gsu.edu/~matrhc
http://brainsbehavior.gsu.edu/
More information about the SciPy-user
mailing list