When the training phase is achieved, in practice it means that we have found the sequence of weights that best approximates this function, that is, the one that has returned the best reward achievable. Now we have to test the system with these values to check whether the pole is able to stand for at least 100 time steps.
Now, as we are already done in the training phase, to make the whole testing phase easily understandable, we report the whole code block and then comment on it in detail on a line-by-line basis:
observation = env.reset()for j in range(100): env.render() action = 0 if np.matmul(BestWeights,observation) < 0 else 1 observation, reward, done, info = env.step(action) print( j, action)
First, we have to initialize ...