Last active
October 19, 2018 16:47
-
-
Save tankala/6f46dbeb056d631e740f4bdb0c33b3cb to your computer and use it in GitHub Desktop.
For preparing data of MountainCar game which we need to use for our deep learning model training.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def model_data_preparation(): | |
training_data = [] | |
accepted_scores = [] | |
for game_index in range(intial_games): | |
score = 0 | |
game_memory = [] | |
previous_observation = [] | |
for step_index in range(goal_steps): | |
action = random.randrange(0, 3) | |
observation, reward, done, info = env.step(action) | |
if len(previous_observation) > 0: | |
game_memory.append([previous_observation, action]) | |
previous_observation = observation | |
if observation[0] > -0.2: | |
reward = 1 | |
score += reward | |
if done: | |
break | |
if score >= score_requirement: | |
accepted_scores.append(score) | |
for data in game_memory: | |
if data[1] == 1: | |
output = [0, 1, 0] | |
elif data[1] == 0: | |
output = [1, 0, 0] | |
elif data[1] == 2: | |
output = [0, 0, 1] | |
training_data.append([data[0], output]) | |
env.reset() | |
print(accepted_scores) | |
return training_data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment