Replies: 2 comments 4 replies
-
If you reuse the seed within a simulation run, then the random values are repeated: Another problem, even when you have fixed the first problem, is that mapping a random state to a single seed number doesn't apply to NumPy's default RNG, PCG64. Tangent point: I looked at Julia's RNG just now. They had switched from MersenneTwister to Xoshiro256++. I'm not sure how it compares with PCG64. A HN discussion about PCG and alternatives. |
Beta Was this translation helpful? Give feedback.
-
I see this statement to be the main motivation of this discussion (with the variance reduction being a consequence of not accessing the RNG via the model instance):
From the agent's perspective, it needs to access the model to get both its RNG and clock anyway. There could be other model attributes beyond the RNG and the clock that the space/cell may need to access to. This is regardless of whether there is a solution to access the RNG without via the model instance. |
Beta Was this translation helpful? Give feedback.
-
Currently, the seeded random number generator resides in the model class. However, this means that all other classes that need random number generation need a reference to the model class. In particular, for AgentSet, and if we add some CellCollection, this becomes quite burdensome because any class that generates them also needs a reference to the model.
One possible solution would be to turn the seeded random number generator into a singleton. Then, in the
__init__
, or wherever you need it, you instantiate this class and get the singleton instance back.It is even possible to expand upon this. A common technique to reduce variance in stochastic models is to use common random numbers. At the moment this is not easy to do in MESA unless you want to write everything yourself. With a Random class that tracks its instances based on the seed, this becomes easier to do.
Something like the following API would work well for this:
Implementation is pretty straightforward and can even be done in a backward-compatible manner.
Beta Was this translation helpful? Give feedback.
All reactions