commons-stack / commons-simulator

Giving people the ability to easily simulate their own custom Commons with cadCAD
https://sim.commonsstack.org/
33 stars 15 forks source link

use cadCAD random seed for randomness and integration tests #48

Closed randomshinichi closed 3 years ago

randomshinichi commented 3 years ago

Use the cadCAD random seed functionality (investigate) to toggle between randomness or predictable outcomes (for integration tests)

marthendalnunes commented 3 years ago

Example of use:

# declare this outside of the policy/state update functions
NUMBER_OF_MONTE_CARLO_RUNS = 5 # make sure to set this to the actual number
rngs = [np.random.RandomState(i) for i in range(NUMBER_OF_MONTE_CARLO_RUNS)]

# use inside policy/state update functions like this
def policy_function(params, step, state_history, prev_state):
    rng = rngs[prev_state['run'] - 1]
    random_value = rng.beta(params['a'], params['b']) # or whatever other method from numpy.random.RandomState