Last active
January 9, 2019 20:10
-
-
Save tankala/1b5988598ceff25833c60b5fafeca88a to your computer and use it in GitHub Desktop.
For preparing data of CartPole 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, 2) | |
observation, reward, done, info = env.step(action) | |
if len(previous_observation) > 0: | |
game_memory.append([previous_observation, action]) | |
previous_observation = observation | |
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] | |
elif data[1] == 0: | |
output = [1, 0] | |
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