科学网

 找回密码
  注册

tag 标签: netlogo

相关帖子

版块 作者 回复/查看 最后发表

没有相关内容

相关日志

如何高效入门复杂系统仿真?
wshuyi 2020-2-8 08:15
推荐你一门好课,帮你在研究方法武器库中,添上复杂系统仿真这一项。 方法 提到研究方法,根据你所在学科的不同,一定能想到不同的名词。 学理工科的,可能会想到实验法。 学社会科学的,可能会想到问卷调查、访谈等。 这里,我给你介绍一种稍稍另类的研究方法 —— 复杂系统仿真。 1948 年,美国数学家,信息论的创始人之一 Warren Weaver 提出了 3 类科学问题划分。 这三类问题分别是: 简单问题 无组织复杂问题 有组织复杂问题 所谓简单问题,就是研究少数变量之间的关系。例如你中学物理课学到过的,描述电阻、电压和电流关联的欧姆定律。这一类问题,到了 19 世纪末,就已经能够被解决了。 所谓无组织复杂问题,是指研究对象变量非常多,但是这些变量之间没有强联系,因此可以被近似当做一个整体来简单化处理。 例如气压,它源自于数千亿无组织空气分子的运动。温度和气压之间,是存在关联的。 但是,我们要理解气压和温度之间的关系,是不需要一一考察那无数分子的个体情况,只需要把气压当成一个总体来处理就好。这类的问题,到了 20 世纪中叶,也都获得了解决。 聪明的你,一定已经想到了这最后一类 有组织复杂问题 的定义了。 没错,如果我们的研究对象包括许多变量,而这些变量之间的关系不是微弱的,而恰恰是一种研究者不喜欢看到的 强非线性 关联,那么这类问题,就叫做有组织复杂问题。 例如,小麦的价格如何确定?货币如何有效、明智与稳定地投放? 这些问题,历史上有无数的聪明人,希望通过明确的数学公式来一劳永逸地解决它们。但是尝试过后,效果很不理想。 更要命的是,我们生活的社会里,越是与真实情况相近的问题,就越是具备有组织复杂问题的特性。不信你可以问问企业的管理者。 那么,面对这样的问题,我们该怎么办呢? 社会实验肯定是解决的有效方法之一。就如同历史上那些伟大的社会实验,例如: 六度分割实验 权威服从实验 问题是,不是什么时候,我们都可以选择社会实验法的。这里就会涉及到科研伦理问题。 例如说,我们要研究灾难发生时候逃生通道的情况,以便更好地设计安全的场馆;我们要研究病毒的传播路径,以便更好地防控疫情。 这种灾难,显然不能在真实场景中进行实验,否则后果不堪设想。 这就需要复杂系统仿真方法出场了。 仿真 什么叫做仿真呢? 就是用一个模型,来模拟真实世界的情况,给出一个近似结果。 仿真方法不稀奇。就连数学上概率问题的抛硬币,你都可以用 R 语言来轻易实现一个仿真。 以上抛硬币仿真代码来自这个地址。 但是问题在于,对于复杂系统的仿真,和它是有区别的。 前面提到了,复杂系统的特性,是变量多,而且具有强非线性关联。 因此,这种仿真,对工具是有要求的。即 能够描摹个体的特性与行为 能够刻画个体之间随时间步发生的交互作用 当然,如果你是高手,完全可以随便找来一种高级语言,从头开发自己的仿真工具。就如同有些高手,一言不合,就喜欢拿起汇编语言自己编程玩儿。 但是,这显然不适合普通人。 作为普通人来说,我们最好还是使用别人搭建好的仿真框架,在上面运行求解自己感兴趣的问题。 我做硕士毕业论文的时候,曾经使用过 Sante Fe 研究所开发的 Swarm 仿真工具,模拟无线局域网络中,通过作弊方式获得高带宽的用户行为。 不过,当时的学习过程很痛苦。因为 Sante Fe 研究所选用了一门当时非常冷门的语言作为 Swarm 的编程语言。 好在风水轮流转。后来,你可能听说了,这门语言被 Apple 看上了,一度成了开发 iOS App 的默认语言,又火了起来。 只是那时候,我已经把好不容易学会的这门语言,给忘得差不多了。惭愧。 不过,Swarm 确实不适合普通人来入门复杂系统仿真,使用起来也不是很方便。正如我在《 学 Python ,能提升你的竞争力吗? 》一文中跟你提过的。一门语言本身好坏固然重要,但更重要的,是网络效应,也就是有多少人愿意用。 有良好的社区,你就能很容易学习,遇到问题也容易从同侪那里找到答案;有新的需求,也会有更多的可能获得积极响应和改善。 所以后来,当我发现 Netlogo 的时候,很开心。 工具 和 Swarm 不同,Netlogo 一上来的定位,就是让更多人,特别是非专业编程人员,也能很容易上手复杂系统仿真。 究竟有多容易呢? 这么说吧。你连安装软件都不需要。 只要有一个浏览器,你就可以在里面输入这个链接: https://www.netlogoweb.org/launch 然后,就能欢快地使用了。 方便吧? 不但功能齐全,Netlogo 还具有非常丰富的文档。 更让人兴奋的是,各种学科的模型样例,都很齐全。这是长年以来,社区日积月累的结果。 如果你要研究的问题,跟这些已经做好的模型相似,那么你只需要修改一下模型,就可以用于自己的研究。 我之前做教育部项目,研究虚假信息传播的机制模型与应对策略。其中一篇研究成果《 基于复杂系统仿真的微博客虚假信息扩散模型研究 》,用的基础就是 Netlogo 中的计算机病毒传播模型。 里面模型运行出来,是这样的: 看到这里,你可能早已跃跃欲试了。 别忙,刚才告诉你的,都是好消息那一面。 坏消息是,Netlogo 的语法,非常古怪。 对于从来没有接触过编程的人,困难在于模型一旦复杂化,阅读理解会有些困扰。 然而对他们来说,这种语法的怪异倒还好。他们的背景知识空缺,犹如一张白纸,往上面挥毫泼墨,还算容易。只要功夫深,铁杵磨成针。还是可以通过长期学习和反复练习来增强弥补。 怕就怕你之前学过 C, Java, Javascript 或者 Python 这样的高级语言。那初学 Netlogo 的时候,真的会让你有苦不堪言之感。 你直觉上正确的语句,写出来几乎全都是错的。 那感觉,肯定是不怎么样。 为什么会这样呢? 因为 Netlogo 看似一个玩具语言,简简单单。但是你千万不要被它的表象迷惑住。它属于编程语言里一个非常古老而奇异的家族 ——Lisp。 这个语言的其他亲戚,学起来也会让你觉得不那么直观。 例如下面这段: 所以著名的漫画 XKCD 系列里面,是这样揶揄 Lisp 的: 但是,长得怪不要紧。Lisp 这个语言家族的功能非常强大。 如果你掌握了其精髓,那便如同会用了独孤九剑。逢强则强,变化无穷。 问题的关键,在于你如何学习它。 教程 Netlogo 的教程,一直都很稀缺。那些真正的专家,往往会过度低估 Netlogo 的入门和上手难度,只是希望把它作为工具,介绍复杂系统研究。 例如 Melanie Mitchell 的课程 ,便是如此。 在这些课程里,Netlogo 会被广泛用到,但是其功能使用的细节,不作为重点,很多地方一带而过。你听着挺清楚,自己如果想要实践,或者需要定制修改模型,还是会一头雾水。 直到 2015 年,Netlogo 的作者 Uri Wilensky,和 Bill Rand 合作,才出了一本真正意义上的权威入门教程。我当时在美国访学,书刚一出版就从亚马逊下单,买了一本,背了回来。挺沉的。 说是入门教程,也确实介绍了一些 Netlogo 的使用方法,但作者依然是把重点放在了介绍 Netlogo 在各种领域的研究应用上。 更大的问题是,纸质的书籍,不适合做动态的讲解。你图截得太多,显得冗余而凌乱。图截得太少,可能会漏掉重要的步骤。一切都靠读者领悟,读者学习的认知负荷就过高了。 学习的过程中,依然有很多闹不明白的地方。尤其是那些在其他编程语言里,习以为常的东西。所以我不得不经常跳脱出来,到网上查询各种解法和经验。 例如方括号和圆括号的使用,我就是看了这个帖子,才明白,还特意剪藏到了 evernote 中。 连个括号使用,用户都会有这么多的疑问,以至于需要专门有人写个帖子来答复。Netlogo 使用中坑洼之多,可见一斑。 后来书的作者之一 Bill Rand 在 Sante Fe 的 Complexity Explorer 平台开设了一门 MOOC ,介绍复杂系统仿真。我欣然加入学习,还获得了证书。 有了这些教学材料作为基础,我试图在自己的《网络传播与舆情分析》课上,给研究生们介绍基于 Netlogo 的复杂系统仿真,以期让他们能够多掌握一种不同的研究方法,以便选题时视野更加宽广。 但是,这一部分花了精力不小,收获却不大。 因为学生们学起来困难重重。 起初的上手教程,编个蚂蚁觅食,他们还是玩儿得不亦乐乎的。 刚开始选练习题目的时候,也还算积极。 但是一旦深入到了后面的复杂网络动力学部分,就基本上不求甚解,连蒙带猜了。 为什么呢? 你可能想到了 —— 英语不过关。 我推荐作为辅助材料的 Netlogo 视频教程,都是英文的。学的时候,他们已经有好多地方跟不上,得 反复回放 了。 到了练习中,遇到一些新函数,或者是方法的组合,都需要查资料。而资料里绝大部分,也都是英文的。 虽然我教给了他们如何查询编程手册,但是手册里面的使用方法,往往和实际应用里面的用法有区别。对于初学者来说,这不是很容易处理。 我就一直在想,如果能有一套中文教程,循序渐进介绍 Netlogo 的基础用法,把常见的坑一一指出。然后再进一步,把避坑的方法娓娓道来,那该多好? 我曾经也想过自己做一套这样的教程,但是确实没有足够的时间和毅力。 所以,当我看到集智学园出的这一套中文 Netlogo 教程时,非常惊喜。 介绍 这部教程的作者,是集智学园的创始人,北京师范大学张江教授。 张老师的课程,有一个特别好的地方,就是给那些曾经学过高级语言的人,讲了讲 Netlogo 奇怪语法与它们的区别。 我曾经就是在这里,被卡得一塌糊涂。 因为实在是不适应。 他上来就说,为了学好 Netlogo ,你得忘掉之前学的一切其他语言的语法,或者学会翻译它们。 你看,这就是个教程里展示 翻译 的样例: 你可以学会用十几行代码,就构造出朗顿蚂蚁模型。 然后,亲眼见证 10000 步左右涌现出的 高速公路 效果。 你还可以通过最简单的 羊 - 草 生态模型,了解语句的上下文关系。 对于没一个步骤,张老师都给出了非常清晰地介绍和图示。尤其是对重难点做了非常细致的总结和梳理。 通过一个简单的经济模型,你可以了解如何绘制动态直方图。 甚至更进一步,用另一张图,动态绘制洛伦兹曲线。 更妙的是,当我们需要考虑多个变量的交互影响或者综合因素时,还可以使用 Netlogo 给我们提供的简便实验环境 behavior space。 在使用中,每一步都有详细的介绍说明。使得你也可以让机器高速工作,帮你在短短的几分钟里面,做 2000 轮的实验。 最终的结果,还能非常方便地导出。 怎么样?是不是觉得学这样一套教程,很有意义啊? 你一定很关心价格吧? 没错,集智学园里面,有些课程确实要价不菲。 但是这一门课程,是免费的。 它是集智学园 “防疫助力” 课程的一部分。这一板块里面全部课程,你目前都可以免费学习。 怎么样? 是不是觉得这个漫长的假期,有事儿可做了呢? 小结 本文为你介绍了以下知识点: 研究问题按照复杂度的分类方式; 复杂系统研究的方法,尤其是仿真方法的必要性和应用场景; 复杂系统仿真的工具 Netlogo 及其特点; 入门 Netlogo 的优秀中文免费课程资源。 点击 这个链接 ,抓紧学习吧。 我这样说,不是因为我当老师,有督促你学习的职业病。而是有经验教训的。 2003 年,我上大三的时候,曾经和许多同学一样,在一个周末,被学校要求在家自我隔离。 当时我做的事儿,是把几年积攒下来的 DVD 看了个遍,很开心。 但是,等到 6 月份宣布恢复上课和考试的时候,我就傻眼了。前几天回看当时的日记,充满了惶恐与悔恨。 要知道,其他同学在家里,利用那宝贵的假期时间,把互联网协议,就是那一堆 RFC 文件,从头到尾读了一遍。 希望你,能珍惜眼前的时光,做到停课不停学。用这些优秀的教程,填充你的知识结构,增长自己的见识和实力。 祝学习愉快! 读过本文,如果觉得有收获,请 点赞 。 要读更多的文章,微信关注我的公众号 “玉树芝兰”(nkwangshuyi) 。别忘了 加星标 ,以免错过新推送提示。 如果本文对你身边的亲友有帮助,也欢迎你把本文通过微博或朋友圈分享给他们。 延伸阅读 你可能也会对以下话题感兴趣。点击链接就可以查看。 如何高效读论文? 如何快速写作论文初稿? 文科生用机器学习做论文,该写些什么? 如何用人工智能帮你找论文? 如何选研究题目? 如何高效学 Python? 题图: Photo by Moon on Unsplash
5561 次阅读|0 个评论
Netlogo 中出现的JVM错误
mikletonsen 2017-4-27 15:27
在用Netlogo运行文件时,有时会出现fail to launch JVM, 刚开始以为是java虚拟机出现问题。下载相关软件安装完成后,再用Netlogo打开那个文件,还是同样的错误。搁置起来吧,不知道怎么处理,好像度娘也没有办法。一次偶然发现了解决的办法。问题不在于JVM,而是因为那个文件的存放地址中有中文。
4157 次阅读|0 个评论
Netlogo的几个使用查询
zhangenzhan 2012-3-16 11:16
来自用户手册: 1、如何防止两个turtles占据同一个patche?——》参考模型库Code Examples部分中的 One Turtle Per Patch example. 2、让turtle死亡的命令: set turtles 1 3、中括号 of car-ahead slow-down-car ] ;;otherwise speed up 该示例表示前方有车辆,就减慢速度,否则就加速。 9、怎样使用不同的turtles的patches临域(“neighborhoods”)(圆形,Von Neumann临域,Moore临域等)? 可参考模型库Code Examples部分的Moore Von Neumann Example。
个人分类: NETlogo|6847 次阅读|0 个评论
Netlogo test from the software (for myself)
zhanghaisu 2009-4-22 21:38
This page was automatically generated by NetLogo 4.1beta1. Questions, problems? Contact feedback@ccl.northwestern.edu . The applet requires Java 5 or higher. Java must be enabled in your browser settings. Mac users must have Mac OS X 10.4 or higher. Windows and Linux users may obtain the latest Java from Sun's Java site . In order for this to work, this file, your model file (Diffusion Graphics.nlogo), and the file NetLogoLite.jar must all be in the same directory. (You can copy NetLogoLite.jar from the directory where you installed NetLogo.) On some systems, you can test the applet locally on your computer before uploading it to a web server. It doesn't work on all systems, though, so if it doesn't work from your hard drive, please try uploading it to a web server. You don't need to include everything in this file in your page. If you want, you can just take the HTML code beginning with applet and ending with /applet, and paste it into any HTML file you want. It's even OK to put multiple applet tags on a single page. If NetLogoLite.jar and your model are in different directories, you must modify the archive= and value= lines in the HTML code to point to their actual locations. (For example, if you have multiple applets in different directories on the same web server, you may want to put a single copy of NetLogoLite.jar in one central place and change the archive= lines of all the HTML files to point to that one central copy. This will save disk space for you and download time for your users.) powered by NetLogo view/download model file: Diffusion Graphics.nlogo WHAT IS IT? Diffusion Graphics is unlike most other NetLogo models, in that it really doesn't 'model' anything. It simply explores the power behind an interesting patch primitive: 'diffuse'. In this model, the turtles are hot spots -- they set a certain value (a patch variable called 'heat') to the maximum level every time step. Each patch (through the 'diffuse' primitive) then shares its value of 'heat' with its surrounding patches. It's not intended to closely model real heat, it's just a number that behaves something like heat -- it slowly spreads itself evenly across a plane. (See the 'Diffusion' model for a model that models real heat more closely.) Here you can watch what happens as hot-spots interact with each other, as they move around, as their values become negative, or as the 'heat' slowly decays down to nothing. The whole point of the project is to give you an idea how patches interact via the 'diffuse' primitive. (Or maybe just to give you something nice to stare at if you're bored.) HOW TO USE IT Two buttons, SETUP and GO, control execution of the model. As in most NetLogo models, the SETUP button will initialize the 'hot-spots' and other variables, preparing the model to be run. The GO button, a forever button, will then run the model. Four sliders and two switches determine the various properties of the model. Each of them can be set prior to initialization; most can be used mid-run to affect what will happen. NUM-TURTLES determines how many turtles there are. TURTLE-SPEED determines how fast they move. Each turtle sets the 'heat' of the patch it is over to TURTLE-HEAT. Then that patch diffuses it into the nearby patches. The DIFFUSION-RATE slider is the rate at which the colors diffuse out from each patch. All patches diffuse their color value to their neighbors each time step. DIFFUSION-RATE is simply the fraction of this color leaked out. The WANDER? switch, if on, allows the turtles to move around the view. If the switch is off, the turtles will stay rooted in place. THINGS TO NOTICE Mainly what Diffusion Graphics will show you is how patch-color is diffused in NetLogo. The graphical display may evoke fractal imagery, or a topographical landscape. Diffusion Graphics really does bring about a topography of sorts, with the turtles being peaks, and the darkest colors being valleys. The model essentially tries to then smooth out these differences. Let the model run for a while with WANDER all off (all set to 0). Watch what happens to the 'terrain'. What do you predict will eventually happen? This model was built to please. Just play around with the sliders and switches. Later, try altering the code and see what works (and what doesn't work, too). THINGS TO TRY Try setting TURTLE-HEAT to a very large number. What happens? What does this show you about NetLogo's color model? Try setting TURTLE-HEAT to a negative number. What happens? What does this show you about NetLogo's color model? Try setting the patch size to a small number for a richer display. Or make the patch size large, for a 'zoomed-in' perspective. EXTENDING THE MODEL Change it so that the NUM-TURTLES slider will the change the number of turtles on the fly, instead of requiring you to hit SETUP. In 'diffusion-graphics', the position of each turtle is determined randomly at setup. Change the model so that the user may position turtles with the mouse. Color the patches a different way, perhaps along the traditional ROY-G-BIV (red, orange, yellow, green, blue, indigo, violet) spectrum. NETLOGO FEATURES The Diffusion Graphics model was designed around the 'diffuse' primitive. 'diffuse' is an observer primitive that takes two inputs, a patch variable and a number. 'diffuse' makes all the patches share that patch variable with their eight neighbors. The second input is a number between 0 and 1.0 determines what fraction of the patch variable is shared. (In this model, the amount shared is controlled by the CHANGE-RATE slider.) So for example, if I ask the observer to 'diffuse heat 0.5', the observer tells each patch to give half of 'heat' to the eight other patches. If a patch had 80 to begin with, then it keeps 40 and gives 5 away to each neighbor. The total value of 'heat' for all the patches remains constant. There is also a 'diffuse4' primitive where the patches only share with their neighbors in the north, south, east, and west directions, not with their diagonal neighbors. CREDITS AND REFERENCES To refer to this model in academic publications, please use: Wilensky, U. (1997). NetLogo Diffusion Graphics model. http://ccl.northwestern.edu/netlogo/models/DiffusionGraphics . Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. In other publications, please use: Copyright 1997 Uri Wilensky. All rights reserved. See http://ccl.northwestern.edu/netlogo/models/DiffusionGraphics for terms of use. PROCEDURES patches-own to setup clear-all set-default-shape turtles circle create-turtles num-turtles ; each turtle is like a heat source ; turtles set the patch variable recolor-patches ; color patches according to heat end to go ask turtles ; turtles set the patch variable if wander? ] ; movement of turtles is controlled by WANDER? switch diffuse heat diffusion-rate ; this causes the spreading of heat recolor-patches ; color patches according to heat tick end to wander ; turtle procedure rt random 50 - random 50 fd turtle-speed end to recolor-patches ;; color patches according to heat ask patches end ; *** NetLogo 4.1beta1 Model Copyright Notice *** ; ; This model was created as part of the project: CONNECTED MATHEMATICS: ; MAKING SENSE OF COMPLEX PHENOMENA THROUGH BUILDING OBJECT-BASED PARALLEL ; MODELS (OBPML). The project gratefully acknowledges the support of the ; National Science Foundation (Applications of Advanced Technologies ; Program) -- grant numbers RED #9552950 and REC #9632612. ; ; Copyright 1997 by Uri Wilensky. All rights reserved. ; ; Permission to use, modify or redistribute this model is hereby granted, ; provided that both of the following requirements are followed: ; a) this copyright notice is included. ; b) this model will not be redistributed for profit without permission ; from Uri Wilensky. ; Contact Uri Wilensky for appropriate licenses for redistribution for ; profit. ; ; This model was converted to NetLogo as part of the projects: ; PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING ; IN CLASSROOMS and/or INTEGRATED SIMULATION AND MODELING ENVIRONMENT. ; The project gratefully acknowledges the support of the ; National Science Foundation (REPP ROLE programs) -- ; grant numbers REC #9814682 and REC-0126227. ; Converted from StarLogoT to NetLogo, 2001. ; ; To refer to this model in academic publications, please use: ; Wilensky, U. (1997). NetLogo Diffusion Graphics model. ; http://ccl.northwestern.edu/netlogo/models/DiffusionGraphics. ; Center for Connected Learning and Computer-Based Modeling, ; Northwestern University, Evanston, IL. ; ; In other publications, please use: ; Copyright 1997 Uri Wilensky. All rights reserved. ; See http://ccl.northwestern.edu/netlogo/models/DiffusionGraphics ; for terms of use. ; ; *** End of NetLogo 4.1beta1 Model Copyright Notice ***
个人分类: 复杂网络演化|4271 次阅读|0 个评论

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-6-18 21:44

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部