如何在 Repast Simphony 中为测试目的取消随机化?

huangapple go评论75阅读模式
英文:

How to remove randomization in Repast Simphony for testing purposes?

问题

我想要从我的Repast模型中移除所有的随机性,以便我可以放心地进行重构,确保功能没有改变。然而,通过在myBuilder.build()的顶部使用RandomHelper.setSeed(1)来设置种子,并确保我的GUI在初始化时将“默认随机种子”参数种子设置为1,我无法去除随机性。

因此,我尝试从示例JZombies模型中移除随机性,并遇到了相同的问题。同样,我在JZombiesBuilder.build()的顶部设置了RandomHelper.setSeed(1),并确保默认的随机种子设置为1。有时输出是相同的,有时不同。

在这两种情况下,我都使用文本输出器(Text Sink)记录了一定数量的代理总数和代理属性的时间。我在使用Windows的FCFCIV比较输出文件时发现了差异。

我需要做哪些更改以确保确定性行为?

编辑:

在JZombies演示模型中,通过在每个类的构造函数的顶部添加RandomHelper.setSeed(1);,我获得了确定性行为。在我的实际模型中做同样的事情使第一步始终相同。但从第二步开始仍然有差异。我认为问题出在随机调度上,是吗?

英文:

I want to remove all randomization from my Repast model so that I can refactor with confidence that functionality is unchanged. However, I was unable to remove randomization by setting the seed using RandomHelper.setSeed(1) at the top of myBuilder.build(), and making sure that my 'Default Random Seed' parameter seed was set to 1 in the GUI at initialization.

So, I tried to remove randomization from the sample JZombies model and had the same issue. Again, I set RandomHelper.setSeed(1) at the top of JZombiesBuilder.build(), and made sure the Default Random Seed was set to 1. Sometimes the output was identical, sometimes it was not.

In both cases I'm using a Text Sink to record a constant number of ticks of aggregate agent counts and aggregate agent attributes as my data. I found differences in the output files using both Windows's FC & FCIV.

What changes do I need to make to ensure deterministic behavior?

Edit:

I got deterministic behavior in the JZombies demo model by also putting RandomHelper.setSeed(1); at the top of each class's constructor. Doing the same thing in my actual model makes the first step consistently identical. There are still differences from the second tick on. I think the issue is random scheduling, now?

答案1

得分: 2

你不应该需要两次设置随机种子,所以我建议从构建器中移除 RandomHelper.setSeed(1) 的调用(以及其他地方)。
你提到的 GUI 随机种子是通过 JZombies_Demo.rs/parameters.xml 文件设置的。

接下来是你实际的问题。如果你在代码中的所有随机元素都使用了 RandomHelper 调用,你应该会看到可重现的结果。如果没有,这可能表明存在一些未解释的随机性,例如使用了非 RandomHelper 调用,或者像迭代通过 HashMap 这样的操作。例如,当你通过 for 循环在 DefaultContext 上进行迭代时,迭代会发生在 HashSet 上,但当使用 Context.getObjects() 方法时,内部迭代会在 LinkedHashMap 上进行,因此可以确保可重复性。

英文:

You should not have to set your random seed twice, so I would start with removing the RandomHelper.setSeed(1) call in your builder (and elsewhere).
The GUI random seed you are mentioning is set via the JZombies_Demo.rs/parameters.xml file.

On to your actual question. If you are using RandomHelper calls for all of your stochastic elements in the code, you should see reproducible results. If not, this could indicate that there is some unaccounted for stochasticity, e.g., the use of a non-RandomHelper call or something like iterating through a HashMap. E.g., when you iterate using the for loop over a DefaultContext, the iteration occurs over a HashSet, but when using the Context.getObjects() method, the internal iteration is over a LinkedHashMap, so repeatability is ensured.

huangapple
  • 本文由 发表于 2020年5月31日 02:22:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/62106908.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定