We will now code the train_test.py file.
- Importing the packages: First, we import the required packages:
import tensorflow as tfimport numpy as npimport matplotlib.pyplot as pltimport gymimport sysimport timefrom class_ppo import *
- Define function: We then define a function for reward shaping that will give out some extra bonus rewards and penalties for good and bad performance, respectively. We do this for encouraging the car to go higher towards the side of the flag which is on the mountain top, without which the learning will be slow:
def reward_shaping(s_): r = 0.0 if s_[0] > -0.4: r += 5.0*(s_[0] + 0.4) if s_[0] > 0.1: r += 100.0*s_[0] if s_[0] < -0.7: r += 5.0*(-0.7 - s_[0]) if s_[0] < 0.3 and np.abs(s_[1]) ...