solving ODEs on networks with PyDSTool
networking, ode, python
Solution
The solution is definitely not to build separate simulation models. That won't work because so many variables will be continuously coupled between the sub-models. You absolutely must have all the ODEs in one place together.
It sounds like the solution you need is to use the ModelSpec object constructs. These let you hierarchically build the sub-model definitions out of symbolic pieces. They can have their own "epsilon" parameters, etc. You declare all the pieces when you're finished and let PyDSTool make the final strings containing the ODE definitions for you. I suggest you look at the tutorial example at:
http://www.ni.gsu.edu/~rclewley/PyDSTool/Tutorial/Tutorial_compneuro.html
and the provided examples: ModelSpec_test.py, MultiCompartments.py. But, remember that you still have to have a source for the parameters and coupling data (i.e., a big matrix or dictionary loaded from a file) to be able to automate the process of building the model, otherwise you'd still be writing it all out by hand.
You have to build some classes for the components that you want to have. You might also create a factory function (compare 'makeSoma' in the neuralcomp.py toolbox) that will take all your sub-components and create an ODE based on summing something up from each of the declared components. At the end, you can refer to the parameters by their position in the hierarchy. One might be 's1.epsilon' while another might be 'i4.epsilon'.
Unfortunately, to build models like this efficiently you will have to learn to do some more complex programming! So start by understanding all the steps in the tutorial. You can email me directly through the SourceForge support discussions or email once you've got started and have specific questions.
Problem
After using scipy.integrate for a while I am at the point where I need more functions like bifurcation analysis or parameter estimation. This is why im interested in using the PyDSTool, but from the documentation I can't figure out how to work with ModelSpec and if this is actually what will lead me to the solution. Here is a toy example of what I am trying to do: I have a network with two nodes, both having the same (SIR) dynamic, described by two ODEs, but different initial conditions. The equations are coupled between nodes via the Epsilon (see formula below). formulas as a picture for better read, the 'n' and 'm' are indices, not exponents ~> http://image.noelshack.com/fichiers/2014/28/1404918182-odes.png (could not use the upload on stack, sadly) In the two node case my code (using PyDSTool) looks like this: ``` #multiple SIR metapopulations #parameter and initial condition definition; a dict is a must import PyDSTool as pdt params={'alpha': 0.7, 'beta':0.1, 'epsilon1':0.5,'epsilon2':0.5} ini={'s1':0.99,'s2':1,'i1':0.01,'i2':0.00} DSargs=pdt.args(name='SIRtest_multi', ics=ini, pars=params, tdata=[0,20], #the for-macro generates formulas for s1,s2 and i1,i2; #sum works similar but sums over the expressions in it varspecs={'s[o]':'for(o,1,2,-alpha*s[o]*sum(k,1,2,epsilon[k]*i[k]))', 'i[l]':'for(l,1,2,alpha*s[l]*sum(m,1,2,epsilon[m]*i[m]))'}) #generator DS = pdt.Generator.Vode_ODEsystem(DSargs) #computation, a trajectory object is generated trj=DS.compute('test') #extraction of the points for plotting pts=trj.sample() #plotting; pylab is imported along with PyDSTool as plt pdt.plt.plot(pts['t'],pts['s1'],label='s1') pdt.plt.plot(pts['t'],pts['i1'],label='i1') pdt.plt.plot(pts['t'],pts['s2'],label='s2') pdt.plt.plot(pts['t'],pts['i2'],label='i2') pdt.plt.legend() pdt.plt.xlabel('t') pdt.plt.show() ``` But in my original problem, there are more than 1000 nodes and 5 ODEs for each, every node is coupled to a different number of other nodes and the epsilon values are not equal for all the nodes. So tinkering with this syntax did not led me anywhere near the solution yet. What I am actually thinking of is a way to construct separate sub-models/solver(?) for every node, having its own parameters (epsilons, since they are different for every node). Then link them to each other. And this is the point where I do not know wether it is possible in PyDSTool and if it is the way to handle this kind of problems. I looked through the examples and the Docs of PyDSTool but could not figure out how to do it, so help is very appreciated! If the way I'm trying to do things is unorthodox or plain stupid, you are welcome to make suggestions how to do it more efficiently. (Which is actually more efficient/fast/better way to solve problems like this: subdivide it into many small (still not decoupled) models/solvers or one containing all the ODEs at once?) (Im neither a mathematician nor a programmer, but willing to learn, so please be patient!)