jeudi 24 septembre 2020

I can't replicate my results even after setting the random.seed

I have a class Simulation(theta), in which two of its methods draw a random number from an exponential distribution (numpy.random.exponential(theta[i]]), i=[0,1]).

numpy.random.seed(42)

n_sim = 1000

ss_syn = numpy.zeros((n_sim, 4))

for i in range(n_sim):

    theta = [numpy.random.uniform(3, 7), numpy.random.uniform(7, 14)]
    
    s = Simulation(theta)

    while s.num_departs < 200:
        s.advance_time()
        
    ss_syn[i, 0] = theta[0]
    ss_syn[i, 1] = theta[1]
    ss_syn[i, 2] = s.total_wait / 200

ss_syn = pandas.DataFrame(ss_syn, columns=['arrival_avg', 'serving_avg', 'total_wait_avg'])

print(ss_syn)

The output is:

enter image description here

The problem lies when I try to replicate the result, for instance:

s = Simulation([6.026572, 11.560237])
# I've also tried Simulation([ss_syn.iloc[0, 0], ss_syn.iloc[0, 1])

while s.num_departs < 200:
        s.advance_time()

print(s.total_wait / 200)

which gives me an output of 96.1220525219869 (totally different from the one I expected: 151.143088)

Notice that I do set the random seed. I've even tried switching IDE (from JupyterLab to Pycharm) and the result is still the same. Does the fact that I am drawing a random number inside the class have something to do with this replication problem? If so, how could I replicate my results then?




Aucun commentaire:

Enregistrer un commentaire