3

so I run a parameter variation experiment with many probabilistic parameters. I use random seeds, which results in a variety of different outcomes, and this is basically what I want. One experiment in my case consists of 200 runs.

It is good practice in stochastic modelling, however, to use the same seeds for the same runs, i.e. when I run two experiments with 200 runs each, I want that the first runs of each experiment use the same seed, the second runs of each experiment using the same seed (but a different one from the first runs), the third... and so on until 200. This means that I can compare two experiments with each other because they have used the same seed.

How can I accomplish this is Anylogic? When I use the random seed option, I get different seeds for each run. When I use fixed seeds, I get the same outcome every time, because the values chosen from the probabilistic parameters are always the same. Can this be achieved by using the 'Custom generator' in the 'Randomness' property of the parameter variation experiment? Or could this work with a replication-option?

Thank you very much, please let me know if you need more details.

jonas_fe
  • 51
  • 6

1 Answers1

2

Within the parameter variation experiments --> Java Actions under 'Before simulation run' you can set the seed manually for each replication,

e.g. root.getDefaultRandomGenerator().setSeed(listOfSeeds.get(getCurrentReplication()));

listOfSeeds is a collection within your ParametersVariation which you can either generate in the interface or at 'Initial experiment setup' which stores all your seeds for each replication.

  • Thanks, that sounds really useful and I understand the locig behind it. However, I get the error that 'seed' cannot be resolved or is not a field (for the command `root.seed = listOfSeeds.get(getCurrentReplication());` What could I do? – jonas_fe May 12 '20 at 06:33
  • 1
    Oh, true. i save the seed as a variable in main so that I can take a look at it later during each run. I corrected the code above to set the seed directly in the ParametersVariation experiment. – Christian Fikar May 12 '20 at 08:14
  • Thank you very much! I replaced `getCurrentReplication`with `getCurrentIteration` in your code because with `getCurrentReplication` all of my results were the same (ie only one seed). Also, I used an array variable instead of a collection and used variable[getCurrentIteration()] to retrieve the current iteration. Do you think using an array variable and `getCurrentIteration` achieves the same goal? Thank you very much!! :) – jonas_fe May 12 '20 at 08:41
  • Depends on your implemenation. Array does not matter at all. Iteration is more tricky. For instance, assume you have one parameter which you want to vary from 0 to 1. Than you have 2 iterations and you would run a different seed on the setting with 0 and the setting with 1. Replication repeats each setting (e.g., 100 times). Consequently, you do 200 simulation runs, 100 for 0 and 100 for 1. Normally, you want to make sure that these 100 runs are similiar between the two settings. However, if you modeled the replication as an iteration, you will achieve the same result. – Christian Fikar May 12 '20 at 08:59
  • Yes I understand. I think in my case it does not matter, because I just want to make sure that two independent experiments use the same seeds. So I run one experiment 200 times, go back to Anylogic, change some parameters, and I run another experiment 200 times. I think with my implementation I make sure that these two experiments use the same seeds. – jonas_fe May 12 '20 at 09:06