sdxorg / pysd-cookbook Goto Github PK
View Code? Open in Web Editor NEWSimple Recipes for Powerful Analysis of System Dynamics Models
Simple Recipes for Powerful Analysis of System Dynamics Models
Hi , James
When I use 'pysd' library to write some program, it shows this error as below. How can I solve this isssue. Thanks.
%pylab inline
import pysd
model = pysd.read_vensim('./A4.mdl')
stocks = model.run()
_
Populating the interactive namespace from numpy and matplotlib
File "./A4.py", line 66
@cache('step')
^
SyntaxError: invalid syntax
_
Some things to test:
Dear all,
I'm having issues using the model.run(...,collect=True) function.
When running the last step of the Hello tea temperature example http://pysd-cookbook.readthedocs.io/en/latest/analyses/getting_started/Hello_World_Teacup.html), I got the following error:
TypeError: run() got an unexpected keyword argument 'collect'
Its seems that the model.run() function does not have the collect argument implemented.
Could you give me some advices, please?
Cheers,
Oscar
When we translate the notebooks to rst, before building the documentation, we should add the name of the source file, with a link, to the bottom of the page. That way, if users are reading along on the web docs, they can quickly go to the source and try it for themselves.
Hi,
I am getting error in cookbook example Parallel Model Fitting
TypeError: ("run() got an unexpected keyword argument 'rtol'", 'occurred at index 0')
When I run the code
param_names = ['dec_%i_loss_rate'%i for i in range(1,10)]
def error(param_vals, measurements):
predictions = model.run(params=dict(zip(param_names, param_vals)),
initial_condition=(2000,measurements['2000']),
return_timestamps=2010, rtol=1).loc[2010]
errors = predictions - measurements['2010']
return sum(errors.values[1:]**2) #ignore first decade: no birth info
def fit(row):
res = scipy.optimize.minimize(error, args=row,
x0=[.05]*9,
method='L-BFGS-B');
return pd.Series(index=['dec_%i_loss_rate'%i for i in range(1,10)], data=res['x'])
%%capture
county_params = data.apply(fit, axis=1)
We can use system dynamics to identify tests between theories if we formalize those theories as simulations, and then find the regions in the parameter space that maximize the observable difference between the theories, and then design an experiment to operate in those parameter regimes.
A nice case study for this type of test could be Young, H.Peyton. 2009. “Innovation Diffusion in Heterogeneous Populations : Contagion , Social Influence , and Social Learning.” American Economic Review 99(5):1899–1924.
which compares three different types of adoption under social influence.
We should have some basic examples of running bulk Monte Carlo analyses in parallel.
Together with PySD we are planning to migrate the cookbook in mid-September. More information about migration can be found in:
SDXorg/pysd#348
It would be good to have a script that goes through and builds all of the pieces.
If we're introducing a module that is outside of the standard python stack - e.g. a tool for distributed computing, or an optimization package - we should consider these to be ingredients in the recipes.
We have a dataset of names given to babies over time (https://github.com/JamesPHoughton/PySD-Cookbook/tree/master/source/data/Baby_Names) which exhibits some interesting cyclical behavior. It might be interesting to develop a small model which explains that dynamic, and in fitting it to the dataset, uncover secondary patterns in the parameters of the fit model.
This could be an interesting paper to replicate for demonstrating how one might formalize partial model tests for asserting bounded rationality in decision rules:
Sterman, John D. 1985. “A Behavioral Model of the Economic Long Wave.” Journal of Economic Behavior and Organization 6(February 1984):17–53.
The link polarity from 'Time allocated per unit' to 'Fulfillment Rate' should be negative, as the parameter is in the denominator.
Also, there really should be comments and units in this model.
Probably build on Hazhir's data matching paper.
Could use the economic cycle entrainment model in Mosekilde, Erik, Erik Reimer Larsen, John D. Sterman, and Jesper Skovhus Thomsen. 1992. “Nonelinear Mode-Interaction in the Macroeconomy.” Annals of Operations Research 37:185–215.
Optimization, Monte Carlo, etc. are all analyses that could benefit from running models in parallel.
We have a basic demonstration of parallel model fitting, where we fit the model independently to a lot of datasets: http://pysd-cookbook.readthedocs.org/en/latest/analyses/fitting/Massively_Parallel_Fitting.html
But we should show how these can be distributed across multiple computers. This is facilitated by the fact that pysd and its dependencies are pure-python, and can be pickled and distributed.
Here are a few resources for parallel computing in python:
Distribution frameworks:
Analyze a pair of models together, in such a way that you find the places where their predictions diverge. This is the place to conduct an experiment, as it will give the biggest differentiator between the models.
Because the advance of science is much more economical when we can explicitly eliminate the most likely alternative theories, and because formulating the alternative theories and deriving their consequences is preeminently a theoretical task, the central gift of the great methodologist is his facility at formulating and deriving the consequences of alternative theories in such a way that the observations can actually be made to decide the question. (Stinchcombe 1968)
Formal models should excel at this task, as they are able to actually compare the implications of each formalized theory across a range of parameters.
Going further, If you have an understanding of the uncertainties of the parameters, then you can derive a distribution for the predicted values at that point in the parameters space for each model. Then you have the likelihood of getting a predicted value given that the model is correct (given that one of your models is correct). This is a good setup for model selection using MCMC.
Could show that by preferentially conducting experiments at the place where models diverge, you improve the tightness of your parameter estimation in the MCMC...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.