From 4ec0b8f4eb4666fdac5c9bb10a6ade9b33b4747b Mon Sep 17 00:00:00 2001 From: Rafael Cardenas <56218994+rafardenas@users.noreply.github.com> Date: Tue, 22 Dec 2020 15:58:31 +0100 Subject: [PATCH] Minor fixes Using next method while finding the first occurance of the state in episode raised error: 'str' object is not callable --- MC/MC Prediction Solution.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MC/MC Prediction Solution.ipynb b/MC/MC Prediction Solution.ipynb index 25da5f3ca..d72467094 100644 --- a/MC/MC Prediction Solution.ipynb +++ b/MC/MC Prediction Solution.ipynb @@ -92,9 +92,9 @@ " states_in_episode = set([tuple(x[0]) for x in episode])\n", " for state in states_in_episode:\n", " # Find the first occurance of the state in the episode\n", - " first_occurence_idx = next(i for i,x in enumerate(episode) if x[0] == state)\n", + " first_occurence_idx = [i for i,x in enumerate(episode) if x[0] == state]\n", " # Sum up all rewards since the first occurance\n", - " G = sum([x[2]*(discount_factor**i) for i,x in enumerate(episode[first_occurence_idx:])])\n", + " G = sum([x[2]*(discount_factor**i) for i,x in enumerate(episode[first_occurence_idx[0]:])])\n", " # Calculate average return for this state over all sampled episodes\n", " returns_sum[state] += G\n", " returns_count[state] += 1.0\n",