Skip to content

Commit

Permalink
Pythonic edits
Browse files Browse the repository at this point in the history
Replaced `zip(range(len(..)), ..)` with `enumerate(..)`
  • Loading branch information
billtubbs committed Jun 30, 2019
1 parent af7336a commit b74b1d9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions chapter07/random_walk.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ def figure7_2():
# track the errors for each (step, alpha) combination
errors = np.zeros((len(steps), len(alphas)))
for run in tqdm(range(0, runs)):
for step_ind, step in zip(range(len(steps)), steps):
for alpha_ind, alpha in zip(range(len(alphas)), alphas):
for step_ind, step in enumerate(steps):
for alpha_ind, alpha in enumerate(alphas):
# print('run:', run, 'step:', step, 'alpha:', alpha)
value = np.zeros(N_STATES + 2)
for ep in range(0, episodes):
Expand Down
4 changes: 2 additions & 2 deletions chapter08/maze.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,15 +406,15 @@ def figure_8_2():
steps = np.zeros((len(planning_steps), episodes))

for run in tqdm(range(runs)):
for index, planning_step in zip(range(len(planning_steps)), planning_steps):
for i, planning_step in enumerate(planning_steps):
dyna_params.planning_steps = planning_step
q_value = np.zeros(dyna_maze.q_size)

# generate an instance of Dyna-Q model
model = TrivialModel()
for ep in range(episodes):
# print('run:', run, 'planning step:', planning_step, 'episode:', ep)
steps[index, ep] += dyna_q(q_value, model, dyna_maze, dyna_params)
steps[i, ep] += dyna_q(q_value, model, dyna_maze, dyna_params)

# averaging over runs
steps /= runs
Expand Down
4 changes: 2 additions & 2 deletions chapter12/random_walk.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ def parameter_sweep(value_function_generator, runs, lambdas, alphas):
# track the rms errors
errors = [np.zeros(len(alphas_)) for alphas_ in alphas]
for run in tqdm(range(runs)):
for lambdaIndex, rate in zip(range(len(lambdas)), lambdas):
for alphaIndex, alpha in zip(range(len(alphas[lambdaIndex])), alphas[lambdaIndex]):
for lambdaIndex, rate in enumerate(lambdas):
for alphaIndex, alpha in enumerate(alphas[lambdaIndex]):
valueFunction = value_function_generator(rate, alpha)
for episode in range(episodes):
random_walk(valueFunction)
Expand Down

0 comments on commit b74b1d9

Please sign in to comment.