Skip to content

An evolutionary computation framework around the Mario AI gym simulator environment.

Notifications You must be signed in to change notification settings

lguerdan/mario-evolutionary-computation

Repository files navigation

First, see the simulator module for information about how to configure the python environment.

Info about the wrapper

Chromosomes:

An python list of lists, where each list entry corresponds to a chromosome and its fitness and the index at which it last ran before dying

The initial numpy array corresponds to the chromosome: It will be max_steps long and each value will be in the range: 0 -> max(ACTION_ENCODING) Not yet evaluated chromosomes have an award of -1


[chromosome numbers], fitness score, last action index before dying
[
    [[1,2,0,3,2,....], -1, -1]
    [[0,6,1,3,2,....], -1, -1]
]

Each step in a chromosome encodes an action in the simulator

SelectionEnv

Only need to update new_generation based on each of our methods. Can overload function definition etc.

MSBGeneticOptimizerEnv

Contains bulk of the code. Important functions:

  • run_generations: Runs main loop of all chromosomes for ngens times
  • run_top_chromosome: Used to visualize how the best solution is running. Test phase more or less
  • evaluate_chromosomes: Runs each chromosome through the simulator and stores the corresponding fitness and the index of death
  • save_optimizer: Saves the current optimizer state to a file
  • load optimizer: Loads the optimizer with previously computed state for continued training or visualization of good solutions

Usage

#create a new optimizer environment and initialize data structure
optimizer = SelectionEnv(max_steps = 500, num_chromosomes=6, render=True)

#run the optimizer for the desired number of generations
optimizer.run_generations(3)

#serialize the data structure to a file. Pickle for effeciency 
optimizer.save_optimizer('mario-4-chromosome.p')

#see how the top performing chromosome looks in the simulator 
optimizer.run_top_chromosome(render=True)


To load a previous environment, either create a new optimizer with the filename,or call the load optimizer function directly. Note this will overwrite the current state

optimizer2 = SelectionEnv(session_file ="mario-4-chromosome.p")
load the previous session and keep training
optimizer2.run_generations(1)
optimizer2.save_optimizer('mario-4-chromosome2.p') #save to an updated file 

About

An evolutionary computation framework around the Mario AI gym simulator environment.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages