lecture-python icon indicating copy to clipboard operation
lecture-python copied to clipboard

Random seeds in the solution for Exercise 1 in mccall_model

Open oyamad opened this issue 5 years ago • 0 comments

In the plot from the solution code for Exercise 1: image the steps are perfectly flat. I believe this is an artifact of the way how the random seeds are supplied in compute_mean_stopping_time, where the seed values are always the same set of numbers 0, ..., num_reps.

As long as w_bar is in a same interval (w_vals[i-1], w_vals[i]] for some i, compute_mean_stopping_time generates exactly same stopping times.

One way to modify this is the following:

@jit(nopython=True)
def compute_mean_stopping_time(w_bar, num_reps=100000, init_seed=0):
    obs = np.empty(num_reps)
    for i in range(num_reps):
        obs[i] = compute_stopping_time(w_bar, seed=init_seed+i)
    return obs.mean()

c_vals = np.linspace(10, 40, 25)
stop_times = np.empty_like(c_vals)
num_reps = 100000
for i, c in enumerate(c_vals):
    w_bar = compute_reservation_wage_two(c=c)
    stop_times[i] = compute_mean_stopping_time(w_bar, num_reps=num_reps,
                                               init_seed=num_reps*(i-1))

image

(EDIT: Fixed a small bug.)

oyamad avatar May 13 '19 12:05 oyamad