从发电机到R的world2模型

“In 1972 a small paperbound book called ‘The Limits to Growth’ was published with much fanfare […] the book warned that the world was steering a course for disaster. Without a drastic change in direction, the human population would run out of food and natural resources, or else would choke on its own pollution, within 50 or 100 years” (Hayes, 1993).

“ 1972年,一本名为' The Limits to Growth ' 的小型纸质书籍 大张旗鼓地出版了 …… 该书警告说,世界正在为灾难指明方向。 没有方向的急剧变化,人类将在50或100年内耗尽粮食和自然资源,否则将因自身污染而窒息 ”(Hayes,1993年)。

Jay Wright Forrester (1918–2016) was an American computer engineer and systems scientist, credited as the “founding father” of system dynamics. Although less known by the general public than the Meadows couple who wrote ‘The Limits to Growth’ (Meadows et al., 1972), Forrester’s world dynamics model World2 (Forrester, 1971) was the basis of all subsequent models predicting a collapse of our socio-technological-natural system by the mid 21st century. This article revisits this seminal work from a programming perspective, by rewriting the outdated DYNAMO code into R. It will provide a fresh look at this model of world dynamics and could later be used as input model for machine learning exercises.

Jay Wright Forrester (1918–2016)是美国计算机工程师和系统科学家, 被誉为系统动力学的“奠基人” 。 尽管比起草写“增长的极限”的梅多斯夫妇(Meadows等人,1972年), 公众对它的了解较少 ,但Forrester的世界动力学模型World2 (Forrester,1971年)是所有后续模型的基础,这些模型预测了我们的崩溃。到21世纪中叶的社会技术自然系统 。 本文通过将过时的DYNAMO代码重写为R,从编程角度重新审视了这一开创性工作。它将为这种世界动力学模型提供新的外观,并可以稍后用作机器学习练习的输入模型。

“世界动力学”简史 (A brief history of ‘World Dynamics’)

The transcript of a talk given by Forrester at the System Dynamics Society, Stuttgart, Germany, in 1989, provides us with a first-hand account of the media’s reaction to the bombshell that was the publication of his doomsday computer model:

弗雷斯特(Forrester)于1989年在德国斯图加特的系统动力学学会上发表的谈话的文字记录为我们提供了媒体对重磅炸弹React的第一手资料,这是他的世界末日计算机模型的出版:

“‘World Dynamics’ came out the first week of June, 1971. The last week of June it was reviewed on the front page of the London Observer. I received a letter from a university professor in New York asking for more information because he had been reading about the book in the Singapore Times. In August the book had the full front page of the second section of the Christian Science Monitor, in September a page and a half in Fortune, and in October a column in the Wall Street Journal. It was running through editorial columns of mid-America newspapers, it was the subject of prime time documentary television in Europe, it was debated in the environmental press, the zero population growth press, and the anti- establishment underground student press. And, if you don’t like your literature on either the establishment right or the establishment left, then right in the middle of the political spectrum, it had a full-length article in Playboy […] Nine months after ‘World Dynamics’, ‘Limits to Growth’ was published. The message was essentially the same, although much more work had been done and the book was more popularly written…” — Jay W. Forrester, 1989

“'世界动力'于1971年6月的第一周问世。6月的最后一周在《伦敦观察家》的头版进行了评论。 我收到了纽约大学教授的来信,要求提供更多信息,因为他一直在《新加坡时报》上读到这本书。 8月,该书刊登了《基督教科学箴言报》第二部分的完整首页,9月是《财富》杂志的一页半,十月是《华尔街日报》的专栏。 它遍及中美洲报纸的编辑栏目,是欧洲黄金时段的纪录片电视的主题,在环境媒体,零人口增长媒体和反建立地下学生媒体中受到争议。 而且,如果您不喜欢建制权还是建制权左派的文学作品,那么无论是在政治领域的中间,还是右派,《花花公子》 […] 《世界动力》出版九个月后,都有一篇全文,出版了《增长的限制》。 传达的信息基本上是相同的,尽管完成了更多的工作,而且书的写作更受欢迎了……” —杰伊·W·弗雷斯特(Jay W. Forrester),1989年

Image for post
Wikipedia. Wikipedia

System dynamics is an approach to understanding the nonlinear behaviour of complex systems over time using stocks, flows, internal feedback loops, table functions and time delays (Wikipedia). It in fact derives from earlier works on cybernetics.

系统动力学是一种利用存量,流量,内部反馈回路,表函数和时间延迟来了解复杂系统随时间变化的非线性行为的方法 ( 维基百科 )。 实际上,它源于控制论的早期著作。

World2 was not Forrester’s first major work in system dynamics, as he had already applied the method to factory planning in ‘Industrial Dynamics’ ((Forrester, 1961), and then to city planning in ‘Urban Dynamics’ (Forrester, 1969; which, fun fact, would later be influential in the creation of the video game SimCity; Lobo, 2007). Forrester’s work on urban dynamics was noticed by the Club of Rome which led to discussions on global sustainability and the book ‘World Dynamics’ in 1971 where the World2 model was presented. Meadows’ team developed an extension of the model in parallel, leading to the World3 version (Meadows et al., 1972; Meadows, 1974; updated in Meadows et al., 2004; see also Randers, 2012). Interestingly, Forrester had sketched out a preliminary version of the model, called World1, on his flight home from his meeting with the Club of Rome in Switzerland (Hayes, 1993).

World2并不是Forrester在系统动力学方面的第一项主要工作,因为他已经将该方法应用于“工业动力学”中的工厂规划((Forrester,1961),然后应用于“城市动力学”中的城市规划(Forrester,1969;),一个有趣的事实,后来将对电子游戏SimCity的创建产生影响; Lobo,2007年)。 罗马俱乐部注意到了Forrester在城市动力学方面的工作,这引起了关于全球可持续性的讨论,并在1971年出版了《世界动力学》一书, Meadows的团队并行开发了该模型的扩展,从而开发出World3版本 (Meadows等,1972; Meadows,1974; Meadows等,2004更新;另请参见Randers,2012)。有趣的是,弗雷斯特(Forrester)在与瑞士罗马俱乐部会面后的飞行途中草绘了模型的初步版本,称为World1(Hayes,1993)。

Preliminary results from the World1 model. At 2'35: “We come up to the year 2020 and it’s really come right back. More people of course means that you start to chew up your supply of natural resources, and this is this curve here, the N curve, that shows…”
World1模型的初步结果。 在2'35:“我们要到2020年,而现在真的回来了。 当然,更多的人意味着您开始咀嚼自然资源的供应,这条曲线就是N曲线,表明……”

重新运行模型World2和World3 (Rerunning the models World2 and World3)

“In 1971 ‘World Dynamics’ seemed to have everything necessary to guarantee no public notice. First, it had forty pages of equations in the middle of the book, that should be sufficient to squelch public interest. Second, the interesting messages were in the form of computer output graphs, and most of the public do not understand such presentations.” — Jay W. Forrester, 1989

“ 1971年的“世界动态” 似乎拥有一切必要的保证,不会引起公众注意。 首先,它在书的中间四十页的方程式,足以抑制公众利益。 其次,有趣的消息是以计算机输出图的形式出现的,并且大多数公众不理解这种表示。” -杰伊·弗雷斯特(Jay W. Forrester),1989年

Reading about a model’s characteristics and outputs on paper is not sufficient to fully grasp the underlying mechanisms and assumptions. Due to the historical importance of the World2 and World3 models in system dynamics and to the 50-year debate that ensued, it is worthwhile to revisit the source codes.

在纸上仅阅读模型的特征和输出不足以完全掌握潜在的机制和假设。 由于World2和World3模型在系统动力学中的历史重要性以及随之而来的50年争论,值得重新研究源代码。

While I thought it would be easy to find modern versions of those models, I had in fact to dig deep to find some open source codes, and finally decided to redo the World2 model from scratch in R, based on the reading of Forrester (1971). Here is a summary of my journey leading to the Rworld2 project:

虽然我认为找到这些模型的现代版本很容易,但实际上我不得不深入研究以找到一些开源代码,并最终根据Forrester(1971年)的阅读,决定从头开始在R中重做World2模型。 )。 这是我通往Rworld2 项目的旅程的摘要:

  • No code found in R;

    在R中找不到代码;
  • Mentions of a Python code created by a French team in 2018 (PDF1, PDF2) but apparently not directly accessible;

    提及法国团队在2018年创建的Python代码( PDF1PDF2 ),但显然无法直接访问;

Image for post
bit-player.org. bit-player.org的 javascript中World3的Beta版的屏幕截图。
  • Things are getting more concrete: a Javascript dashboard exists that allows the user to try out different parameterisations of the World3 model and plot the results. However, a disclaimer states that “this is a work in progress and may well have serious bugs.” This is linked to a very nice article by the author of the tool, Brian Hayes, who wrote several pieces about ‘The Limits to Growth’ in American Scientist (Hayes, 1993; 2012). Here is a nugget from that article: “The original World3 model ran on mainframe hardware — IBM 360 and 370 machines.” Other nuggets on DYNAMO programming follow, four bullet-points below.

    事情变得越来越具体:存在一个Javascript仪表板 ,该仪表板允许用户尝试World3模型的不同参数化并绘制结果。 但是,有一个免责声明指出:“ 他的工作正在进行中,很可能会出现严重的错误 。” 这与该工具的作者Brian Hayes的一篇非常不错的文章有关,他在《 美国科学家 》中写了几篇有关“增长的极限”的文章(Hayes,1993; 2012)。 这是该文章的一篇文章:“ 原始的World3模型运行在大型机硬件上-IBM 360和370计算机。 ”接下来是有关DYNAMO编程的其他块,下面是四个要点。

  • Hayes mentions “that there are several more versatile and more trustworthy implementations out there” and provides the following link which is unfortunately broken, as of 2020.

    Hayes提到“ 那里有几种更通用,更值得信赖的实现方式 ”,并提供了以下链接 ,不幸的是,截止到2020年,该链接已中断。

  • A trustworthy implementation of World3 is provided by Scott Fortmann-Roe via Insightmaker (Fortmann-Roe, 2014)—However, use of a general-purpose tool for web-based graphical model construction is at odds with the flexibility of the simple script I originally had in mind.

    Scott Fortmann-Roe通过Insightmaker提供了World3的可靠实现(Fortmann-Roe,2014年)。但是,使用通用工具进行基于Web的图形模型构建与我最初使用的简单脚本的灵活性不符。想到了。

Image for post
https://insightmaker.com/insight/1954/The-World3-Model-A-Detailed-World-Forecaster. https://insightmaker.com/insight/1954/The-World3-Model-A-Detailed-World-Forecaster
  • The most reliable and best documented open source versions of World2 and World3 are the ones programmed in Modelica by François E. Cellier (Cellier, 2007; 2008; Castro et al., 2014). The documentation on World3 provides some valuable historical information: “Whereas Jay Forrester listed his entire model in his book ‘World Dynamics’, Dennis Meadows only talked in ‘Limits to Growth’ about the results obtained using his model. The model itself is not listed. […] Yet, Meadows never tried to hide his model from public scrutiny. In fact, he wrote an internal report of 637 pages that describes all facets of his model. He published that internal report as a separate book in 1974: ‘Dynamics of Growth in a Finite World’.” Cellier (2008) adds: “Although the work of Forrester and Meadows caused quite a stir in the early 70s when their books first appeared, world modeling became unfashionable fairly quickly, because essentially all sources of funding dried out for political reasons. Only very recently, in the context of the looming Peak Oil event and because of the ongoing discussions concerning Global Warming, has world modeling become respectable again.” This makes Rworld2 a timely project, especially since the Modelica codes, although available, are very unlikely to be directly used in any modern data science project.

    World2World3的最可靠和记录最好的开源版本是FrançoisE. Cellier在Modelica中编程的版本(Cellier,2007; 2008; Castro等,2014)。 World3的文档提供了一些有价值的历史信息:“ 尽管Jay Forrester在他的《世界动力》一书中列出了他的整个模型,但丹尼斯·梅多斯只是在《增长的极限》中谈到了使用他的模型获得的结果。 该模型本身未列出。 […] 然而,梅多斯(Meadows)从未试图将他的模型隐藏在公开审查之下。 实际上,他写了 一份637页 内部报告,描述了模型的所有方面 1974年,他将该内部报告作为一本单独的书出版:“有限世界中的增长动态”。 ” Cellier(2008)补充道:“ 尽管Forrester和Meadows的著作在70年代初首次出版时引起了轰动,但世界建模很快就变得不流行,因为基本上所有的资金来源都出于政治原因而枯竭。 直到最近,在迫在眉睫的石油高峰事件的背景下,由于有关全球变暖的持续讨论,世界建模才再次受到人们的尊敬 ”这使得Rworld2成为一个及时的项目,特别是因为Modelica代码尽管可用,但极不可能直接用于任何现代数据科学项目中。

Image for post
Left: OpenModelica OMEdit platform with scenario 1 of World2 displayed; Right: Excerpt of World2 program in Modelica (part of the OpenModelica library which can be found in the folder /omlibrary/SystemDynamics 2.1/package.mo).
左:显示World2场景1的OpenModelica OMEdit平台; 右:Modelica中的World2程序的摘录(可以在/ omlibrary / SystemDynamics 2.1 / package.mo文件夹中找到OpenModelica库的一部分)。
  • Back to square 1! Why translate the Modelica program when it is itself translated from the original DYNAMO code provided in Forrester (1971)? DYNAMO (DYNAmic MOdels) was initially developed by Forrester’s MIT team in the late 1950s for system dynamics computation. Both World2 and World3 were originally written in DYNAMO. The language has, since the publication of ‘Limits to Growth’, fallen into disuse. Hayes describes it nicely: “In lexical and syntactic structure DYNAMO is what you’d expect of a language from the punch-card era — six-letter variable names and ALL CAPS — but in other respects it’s an interesting early experiment, with a programming style that falls somewhere between procedural and declarative.” Here is an excerpt from Appendix B ‘Equations of the World Model’ from Forrester (1971:136), showing some lines of code in DYNAMO:

    回到第1方块! 如果从Forrester(1971)中提供的原始DYNAMO代码中自动翻译了Modelica程序,为什么还要对其进行翻译? DYNAMO(DYNAmic MOdels) 最初由Forrester的MIT团队在1950年代后期开发,用于系统动力学计算 。 World2和World3最初都是用DYNAMO编写的。 自从“增长的限制”出版以来,该语言就被废弃了。 Hayes很好地描述了它:“ 在词汇和句法结构中,DYNAMO是您期望打Kong卡时代的一种语言-六个字母的变量名和ALL CAPS-但在其他方面,这是一个有趣的早期实验,带有编程介于程序性和声明性之间的样式。 ”以下摘录自Forrester(1971:136)的附录B“世界模型方程”,其中显示了DYNAMO的一些代码行:

* WORLD DYNAMICS W5
L P.K=P.J+(DT)(BR.JK-DR.JK)
N P=PI
C PI=1.65E9
R BR.KL=(P.K)(CLIP(BRN,BRN1,SWT1,TIME.K))(BRFM.K)(BRMM.K)(BRCM.K)
X (BRPM.K)
C BRN=.04
C BRN1=.04
C SWT1=1970
A BRMM.K=TABHL(BRMMT,MSL.K,0,5,1)
T BRMMT=1.2/1/.85/.75/.7/.7
A MSL.K=ECIR.K/(ECIRN)

从零开始的World2 in R (World2 in R from scratch)

Let us now have a look at the structure of the model, which may look overwhelming at first glimpse. I recommend looking at the structure of World3 first to make the complexity of World2 all the more relative (43 governing equations in World2 versus 150 in World3).

现在让我们看一下模型的结构,乍一看可能看起来有些不知所措。 我建议首先查看World3的结构,以使World2的复杂性更加相关(World2中的43个控制方程式与World3中的150个控制方程式)。

Image for post
Complete diagram of the World2 model interrelating the five level variables — population, natural resource, capital investment, capital-investment-in-agriculture fraction, and pollution, redrawn from Forrester (1971:20–21, Fig. 2–1). World2 is thus a 5th-order differential equation model. How to read this diagram? First, identify the 5 levels (in red), then the rates representing their inflows and outflows (in blue), and finally the many factors (in yellow). Interrelations (in blue) between levels, rates and factors are defined in the World2 equations. 的World2模型的完整图将五个级别变量(人口,自然资源,资本投资,农业资本投资中的份额和污染)相互关联(1971:20-21,图2-1)。 因此,World2是五阶微分方程模型。 如何阅读此图? 首先,确定5个级别(红色),然后确定代表其流入和流出的比率(蓝色),最后确定许多因素(黄色)。 在World2方程中定义了级别,比率和因子之间的相互关系(蓝色)。

I found the DYNAMO scripts provided throughout chapter 3 of Forrester (1971) far more digestible than the full code given in its Appendix B. I identified the different “equations” (i.e. assignment statements) by following the same numbering system as in the book for direct match. Similarly, I kept the same variable and function names. Order does not count in DYNAMO so the most tedious step in R was the reordering of the World2 set of 43 equations and so-called multipliers (see below) so that all variables were defined and updated correctly (I hence manually did the job of the DYNAMO compiler. It would be challenging, although tempting, to code World2 in R as a graph and then apply topological sorting).

我发现在Forrester(1971)的第3章中提供的DYNAMO脚本比其附录B中提供的完整代码更易消化。我通过遵循与本书中相同的编号系统来标识不同的“ 等式 ”(即赋值语句 )。直接匹配。 同样,我保留了相同的变量和函数名称。 在DYNAMO中,顺序不计算在内,因此R中最繁琐的步骤是对World2集的43个方程式和所谓的乘数(请参见下文)进行重新排序,以便正确定义和更新所有变量(因此,我手动完成了DYNAMO编译器:虽然很诱人,但是将R中的World2编码为图形然后进行拓扑排序将是一个挑战。

An example of equation is given below in R:

下面的R中给出了一个方程式的示例:

# logical function used as time switch to change parameter value
CLIP <- function(FUNCT1, FUNCT2, THRESH.K, VAL) if(THRESH.K >= VAL) return(FUNCT1) else return(FUNCT2)DT <- .2
TIME <- seq(1900, 2100, DT) # CALENDAR TIME (YEARS)
n <- length(TIME)# (...)## (2) Birth rate BR ##
# BR.KL = P.K CLIP(BRN, BRN1, SWT1, TIME.K) BRFM.K BRMM.K BRCM.K BRPM.K
# BRFM = BIRTH-RATE-FROM-FOOD MULTIPLIER ()
# BRMM = BIRTH-RATE-FROM-MATERIAL MULTIPLIER ()
# BRCM = BIRTH-RATE-FROM-CROWDING MULTIPLIER ()
# BRPM = BIRTH-RATE-FROM-POLLUTION MULTIPLIER ()
BR <- numeric(n) # BIRTH RATE (PEOPLE/YEAR)
BRN <- .04 # BIRTH RATE NORMAL (FRACTION/YEAR)
BRN1 <- .04 # BIRTH RATE NORMAL no. 1 (FRACTION/YEAR)
SWT1 <- 1970 # SWITCH TIME no. 1 FOR BRN (YEARS)# (...)for(K in 2:n){
J <- K - 1 # (...) BR[K] <- P[J] * CLIP(BRN, BRN1, SWT1, TIME[J]) * BRMM(MSL[J]) * BRCM(CR[J]) * BRFM(FR[J]) * BRPM(POLR[J]) # (2-3,16-18) # (...)

BR is the birth rate, a function of population P, material standard of living MSL, crowding CR, food FR and pollution POL (POLR is the pollution ratio). BR grows proportional with P and depends on the other variables via single-valued functions called multipliers (BR.variable.M). And now an example of multiplier, based on a look-up table defined by Forrester:

BR是出生率,是人口P,MSL生活水平,CR拥挤,食物FR和污染POL(POLR是污染比率)的函数。 BR与P成正比,并通过称为乘数(BR .variable。M )的单值函数依赖于其他变量。 现在是一个乘数示例,它基于Forrester定义的查找表:

library(signal)  # interp1()## (3) Birth-rate-from-material multiplier BRMM ##
BRMM = function(MSL.K){
# MSL = MATERIAL STANDARD OF LIVING ()
# BRMMT = BIRTH-RATE-FROM-MATERIAL MULTIPLIER TABLE
lookup.table <- data.frame(MSL = seq(0, 5, 1),
BRMMT = c(1.2, 1., .85, .75, .7, .7))
return(interp1(lookup.table$MSL, lookup.table$BRMMT, MSL.K))
}

For an articulate explanation of Forrester’s approach to build World2, I recommend this 2016 presentation by Castro and Cellier. Since the Rworld2 code is ~500 lines long (including numerous comments for a direct match to chapter 3 of Forrester, 1971), it is not given here in full but can be found on my GitHub repo hist_gc_sysdyn (short for History_GlobalCatastrophes_ SystemDynamics). Finally, let us plot the results.

有关Forrester构建World2方法的清晰说明,我推荐Castro和Cellier在2016年的演讲 。 由于Rworld2代码的长度约为500行(包括与Forrester,1971年的第3章直接匹配的大量注释),因此此处未完整给出,但可以在我的GitHub存储库hist_gc_sysdyn中找到 ( History_GlobalCatastrophes_ SystemDynamics的缩写 )。 最后,让我们绘制结果。

# basic plots with same y-range as in Fig. 4-1 of Forrester (1971)plot(TIME, P, type = 'l', ylim = c(0, 8e9))
plot(TIME, POLR, type = 'l', ylim = c(0, 40))
plot(TIME, CI, type = 'l', ylim = c(0, 20e9))
plot(TIME, QL, type = 'l', ylim = c(0, 2))
plot(TIME, NR, type = 'l', ylim = c(0, 1000e9))
Image for post
Raw results of Rworld2 for population P, pollution ratio POLR, capital investment CI, quality of life QL and natural resource NR.
Rworld2对人口P,污染比POLR,资本投资CI,生活质量QL和自然资源NR的 原始结果

It was easy to verify that the R code is correct by comparing the results to Fig. 4–1 of Forrester (1971) — see figure on GitHub. The Rworld2 is crude but I wanted to keep the 1970’s essence of Forrester’s original work. Future works will include an interactive dashboard, as already offered in javascript and Insight Maker. Another step will be to write World3 in R (if Rworld2 took me one full day of work, Rworld3 should take about half-a-week). A longer-term project would be to define the model as a graph.

通过将结果与Forrester(1971)的图4-1比较,可以很容易地验证R代码是否正确— 参见 GitHub上的 。 Rworld2很粗糙,但我想保留Forrester 1970年原创作品的精髓。 未来的工作将包括一个交互式仪表板,如javascript和Insight Maker中已提供的那样。 下一步将是用R编写World3(如果Rworld2花了我整整一天的时间,Rworld3应该花大约半个星期的时间)。 较长期的项目是将模型定义为图形。

最后的笔记 (Final notes)

The purpose of this Medium post was to present the World2 model from a programming perspective and provide a R version, which was previously lacking. The debate surrounding the various doomsday scenarios is not the subject of this article but the reader may ask if there is any use in running World2 in 2020. So let me just quote Cellier (2008) in regard to the usefulness of such outdated model: “It turned out that Forrester and Meadows were essentially correct in their assessment, in spite of the fact that their models were very crude in comparison with real world dynamics.” The validity of these “simple” models has been confirmed in recent studies comparing past predictions to observations (Turner, 2008; 2014).

这篇中级帖子的目的是从编程的角度介绍World2模型并提供以前缺少的R版本。 围绕各种世界末日场景的辩论不是本文的主题,而是读者可能会问,2020年运行World2是否有任何用处。因此,对于这种过时的模型的有用性,让我引用Cellier(2008): 事实证明,尽管Forrester和Meadows的模型与真实世界的动力学相比非常粗糙,但他们的评估基本上是正确的。 这些“简单”模型的有效性在最近的研究中得到了证实,该研究将过去的预测与观察结果进行了比较(Turner,2008; 2014)。

翻译自: https://towardsdatascience.com/world2-model-from-dynamo-to-r-2e44fdbd0975

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值