Subversive modeling

This is a technical post, so Julian Assange fans can tune out. I’m actually writing about source code management for Vensim models.

Occasionally procurements try to treat model development like software development. That can end in tragedy, because modeling isn’t the same as coding. However, there are many common attributes, and therefore software tools can be useful for modeling.

One typical challenge in model development is version control. Model development is iterative, and I typically go through fifty or more named model versions in the course of a project. C-ROADS is at v142 of its second life. It takes discipline to keep track of all those model iterations, especially if you’d like to be able to document changes along the way and recover old versions. Having a distributed team adds to the challenge.

The old school way

Continue reading “Subversive modeling”

Changes afoot

I’m looking forward to some changes in my role at Ventana Systems. From the recent Vensim announcement:

Dear Vensim Community,

We would like to alert you to some exciting changes to the Vensim team.

Bob Eberlein, who has been head of development since almost the beginning of Vensim, has decided to embark on a new chapter of his life, starting in January. While we are sad to see him go, we greatly appreciate all of his efforts and accomplishments over the past 22 years, and wish him the very best in his new adventures.

Vensim is extremely important to our efforts here at Ventana Systems and we know that it is also important to many of you in the System Dynamics community. We are fully committed to maintaining Vensim as the leading System Dynamics software platform and to extending its features and capabilities. We have increased our investment in Vensim with the following team:

Tom Fiddaman has taken on an additional role as Vensim Product Manager. He will make sure that new releases of Vensim address market requirements and opportunities. He will facilitate information flow between the community, our user base, and the Vensim design team.

• Tony Kennedy from Ventana Systems UK will lead the Customer Services functions, including order fulfillment, bug resolution, and the master training schedule. He will also support the Distributor network. Tony has been working with UK Vensim customers for over 10 years.

• Larry Yeager has recently joined Ventana Systems to head the future development of Vensim. Larry has led the development of many software products and applications, including the Jitia System Dynamics software for PA Consulting.

• We have formed a steering team that will provide guidance and expertise to our future product development. This team includes Alan Graham, Tony Kennedy, Tom Fiddaman, Marios Kagarlis, and David Peterson.

We are very excited about the future and look forward to continuing our great relationships with you, our clients and friends.

Most sincerely,

Laura Peterson

President & CEO

Ventana Systems, Inc.

Market Growth

John Morecroft’s implementation of Jay Forrester’s Market Growth model, replicated by an MIT colleague whose name is lost to the mists of time, from:

Morecroft, J. D. W. (1983). System Dynamics: Portraying Bounded Rationality. Omega, 11(2), 131-142.

This paper examines the linkages between system dynamics and the Carnegie school in their treatment of human decision making. It is argued that the structure of system dynamics models implicitly assumes bounded rationality in decision making and that recognition of this assumption would aid system dynamicists in model construction and in communication to other social science disciplines. The paper begins by examining Simon’s “Principle of Bounded Rationality” which draws attention to the cognitive limitations on the information gathering and processing powers of human decision makers. Forrester’s “Market Growth Model” is used to illustrate the central theme that system dynamics models are portrayals of bounded rationality. Close examination of the model formulation reveals decision functions involving simple rules of thumb and limited information content. …

Continue reading “Market Growth”

Oscillation from a purely positive loop

Replicated by Mohammad Mojtahedzadeh from Alan Graham’s thesis, or created anew with the same inspiration. He created these models in the course of his thesis work on structural analysis through pathway participation matrices.

Alan Graham, 1977. Principles on the Relationship Between Structure and Behavior of Dynamic Systems. MIT Thesis. Page 76+

These models are pure positive feedback loops that don’t exhibit exponential growth (under the right initial conditions). See my blog post for a discussion of the details.

These are generic models, and therefore don’t have units. All should run with Vensim PLE, except the generic gain matrix version which uses arrays and therefore requires an advanced version or the Model Reader.

The original 4th order model, replicated from Alan’s thesis: PurePosOscill4.vpm – note that this includes a .cin file with an alternate stable initialization.

My slightly modified version, permitting initialization with different gains at each level: PurePosOscill4alt.vpm

Loops of different orders: 3.vpm 6.vpm 8.vpm 12.vpm (I haven’t spent much time with these. It appears that the high-order versions transition to growth rather quickly – my guess is that this is an artifact of numerical precision, i.e. any tiny imprecision in the initialization introduces a bit of the growth eigenvector, which quickly swamps the oscillatory signal. It would be interesting to try these in double precision Vensim to see if I’m right.)

Stable initializations: 2stab.vpm 12stab.vpm

A generic version, representing a system as a generic gain matrix, so you can use it to explore any linear unforced variant: Generic.vpm

Bifurcating Salmon

A nifty paper on nonlinear dynamics of salmon populations caught my eye on ArXiv.org today. The math is straightforward and elegant, so I replicated the model in Vensim.

A three-species model explaining cyclic dominance of pacific salmon

Authors: Christian Guill, Barbara Drossel, Wolfram Just, Eddy Carmack

Abstract: The four-year oscillations of the number of spawning sockeye salmon (Oncorhynchus nerka) that return to their native stream within the Fraser River basin in Canada are a striking example of population oscillations. The period of the oscillation corresponds to the dominant generation time of these fish. Various – not fully convincing – explanations for these oscillations have been proposed, including stochastic influences, depensatory fishing, or genetic effects. Here, we show that the oscillations can be explained as a stable dynamical attractor of the population dynamics, resulting from a strong resonance near a Neimark Sacker bifurcation. This explains not only the long-term persistence of these oscillations, but also reproduces correctly the empirical sequence of salmon abundance within one period of the oscillations. Furthermore, it explains the observation that these oscillations occur only in sockeye stocks originating from large oligotrophic lakes, and that they are usually not observed in salmon species that have a longer generation time.

The paper does a nice job of connecting behavior to structure, and of relating the emergence of oscillations to eigenvalues in the linearized system.

Units balance, though I had to add a couple implicit scale factors to do so.

The general results are qualitatitively replicable. I haven’t tried to precisely reproduce the authors’ bifurcation diagram and other experiments, in part because I couldn’t find a precise specification of numerical methods used (time step, integration method), so I wouldn’t expect to succeed.

Unlike most SD models, this is a hybrid discrete-continuous system. Salmon, predator and zooplankton populations evolve continuously during a growing season, but with discrete transitions between seasons.

The model uses SAMPLE IF TRUE, so you need an advanced version of Vensim to run it, or the free Model Reader. (It should be possible to replace the SAMPLE IF TRUE if an enterprising person wanted a PLE version). It would also be a good candidate for an application of SHIFT IF TRUE if someone wanted to experiment with the cohort age structure.

sockeye.vmf

For a more policy-oriented take on salmon, check out Andy Ford’s work on smolt migration.

Urban Dynamics

This is an updated version of Urban Dynamics, the classic by Forrester et al.

John Richardson upgraded the diagrams and cleaned up a few variable names that had typos.

I added some units equivalents and fixed a few variables in order to resolve existing errors. The model is now free of units errors, except for 7 warnings about use of dimensioned inputs to lookups (not uncommon practice, but it would be good to normalize these to suppress the warnings and make the model parameterization more flexible). There are also some runtime warnings about lookup bounds that I have not investigated (take a look – there could be a good paper lurking here).

Behavior is identical to that of the original from the standard Vensim distribution.

Urban Dynamics 2010-06-14.vpm

Urban Dynamics 2010-06-14.mdl

Urban Dynamics 2010-06-14.vmf

DICE

This is a replication of William Nordhaus’ original DICE model, as described in Managing the Global Commons and a 1992 Science article and Cowles Foundation working paper that preceded it.

There are many good things about this model, but also some bad. If you are thinking of using it as a platform for expansion, read my dissertation first.

Units balance.

I provide several versions:

  1. Model with simple heuristics replacing the time-vector decisions in the original; runs in Vensim PLE
  2. Full model, with decisions implemented as vectors of points over time; requires Vensim Pro or DSS
  3. Same as #2, but with VECTOR LOOKUP replaced with VECTOR ELM MAP; supports earlier versions of Pro or DSS
    • DICE-vec-6-elm.mdl (you’ll also want a copy of DICE-vec-6.vpm above, so that you can extract the supporting optimization control files)

Note that there may be minor variances from the published versions, e.g. that transversality coefficients for the state variables (i.e. terminal values of the states for optimization) are not included. The optimizations use fewer time decision points than the original GAMS equivalents. These do not have any significant effect on the outcome.

Java Vensim helper

MIT’s Climate Collaboratorium has posted java code that it used to wrap C-LEARN as a web service using the multicontext .dll. If you’re doing something similar, you may find the code useful, particularly the VensimHelper class. The liberal MIT license applies. However, be aware that you’ll need a license for the Vensim multicontext .dll to go with it.

Cumulative Normal Distribution

Vensim doesn’t have a function for the cumulative normal distribution, but it’s easy to implement via a macro. I used to use a polynomial cited in Numerical Recipes (error function, Ch. 6.2):

:MACRO: NCDF(x)
NCDF = 1-Complementary Normal CDF
~	dmnl
~		|
Complementary Normal CDF=
ERFCy/2
~	dmnl
~		|
ERFCy = IF THEN ELSE(y>=0,ans,2-ans)
~	dmnl
~	http://www.library.cornell.edu/nr/bookcpdf/c6-2.pdf
|
y = x/sqrt(2)
~	dmnl
~		|
ans=t*exp(-z*z-1.26551+t*(1.00002+t*(0.374092+t*(0.0967842+
t*(-0.186288+t*(0.278868+t*(-1.1352+t*(1.48852+
t*(-0.822152+t*0.170873)))))))))
~	dmnl
~		|
t=1/(1+0.5*z)
~	dmnl
~		|
z = ABS(y)
~	dmnl
~		|
:END OF MACRO:

I recently discovered a better approximation here, from algorithm 26.2.17 in Abromowitz and Stegun, Handbook of Mathematical Functions:

:MACRO: NCDF2(x)
NCDF2 =  IF THEN ELSE(x >= 0,
(1 - c * exp( -x * x / 2 ) * t *
( t *( t * ( t * ( t * b5 + b4 ) + b3 ) + b2 ) + b1 )),  ( c * exp( -x * x / 2 ) * t *
( t *( t * ( t * ( t * b5 + b4 ) + b3 ) + b2 ) + b1 ))
)
~     dmnl
~     From http://www.sitmo.com/doc/Calculating_the_Cumulative_Normal_Distribution
Implements algorithm 26.2.17 from Abromowitz and Stegun, Handbook of Mathematical 
Functions. It has a maximum absolute error of 7.5e^-8.
http://www.math.sfu.ca/
|
c  =  0.398942
~     dmnl
~           |
t = IF THEN ELSE( x >= 0, 1/(1+p*x), 1/(1-p*x))
~     dmnl
~           |
b5 =  1.33027
~     dmnl
~           |
b4 = -1.82126
~     dmnl
~           |
b3 =  1.78148
~     dmnl
~           |
b2 = -0.356564
~     dmnl
~           |
b1 =  0.319382
~     dmnl
~           |
p  =  0.231642
~     dmnl
~           |
:END OF MACRO:

In advanced Vensim versions, paste the macro into the header of your model (View>As Text). Otherwise, you can implement the equations inside the macro directly in your model.