-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Matthijs den Toom
authored and
Matthijs den Toom
committed
Jan 10, 2019
1 parent
d239963
commit 8f63ae4
Showing
7 changed files
with
253 additions
and
49 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#--- parameters for the cartpole experiment ---# | ||
|
||
[NEAT] | ||
fitness_criterion = max | ||
fitness_threshold = 100 | ||
pop_size = 100 | ||
reset_on_extinction = False | ||
|
||
[DefaultGenome] | ||
# node activation options | ||
activation_default = sigmoid | ||
activation_mutate_rate = 0.0 | ||
activation_options = sigmoid | ||
|
||
# node aggregation options | ||
aggregation_default = sum | ||
aggregation_mutate_rate = 0.0 | ||
aggregation_options = sum | ||
|
||
# node bias options | ||
bias_init_mean = 0.5 | ||
bias_init_stdev = 1.0 | ||
bias_max_value = 1.0 | ||
bias_min_value = -1.0 | ||
bias_mutate_power = 0.5 | ||
bias_mutate_rate = 0.7 | ||
bias_replace_rate = 0.1 | ||
|
||
# genome compatibility options | ||
compatibility_disjoint_coefficient = 1.0 | ||
compatibility_weight_coefficient = 0.5 | ||
|
||
# connection add/remove rates | ||
conn_add_prob = 0.5 | ||
conn_delete_prob = 0.5 | ||
|
||
# connection enable options | ||
enabled_default = True | ||
enabled_mutate_rate = 0.01 | ||
|
||
feed_forward = True | ||
initial_connection = full | ||
|
||
# node add/remove rates | ||
node_add_prob = 0.5 | ||
node_delete_prob = 0.2 | ||
|
||
# network parameters | ||
num_hidden = 0 | ||
num_inputs = 17 | ||
num_outputs = 4 | ||
|
||
# node response options | ||
response_init_mean = 1.0 | ||
response_init_stdev = 0.0 | ||
response_max_value = 5.0 | ||
response_min_value = -5.0 | ||
response_mutate_power = 0.0 | ||
response_mutate_rate = 0.0 | ||
response_replace_rate = 0.0 | ||
|
||
# connection weight options | ||
weight_init_mean = 0.0 | ||
weight_init_stdev = 1.5 | ||
weight_max_value = 10 | ||
weight_min_value = -10 | ||
weight_mutate_power = 0.5 | ||
weight_mutate_rate = 0.8 | ||
weight_replace_rate = 0.1 | ||
|
||
[DefaultSpeciesSet] | ||
compatibility_threshold = 3.0 | ||
|
||
[DefaultStagnation] | ||
species_fitness_func = max | ||
max_stagnation = 20 | ||
species_elitism = 2 | ||
|
||
[DefaultReproduction] | ||
elitism = 2 | ||
survival_threshold = 0.2 | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
""" | ||
Simple example using the tile structure creation task. | ||
""" | ||
|
||
from __future__ import print_function | ||
import os | ||
import neat | ||
import gym | ||
import gym_multi_robot | ||
|
||
num_steps = 3000 | ||
num_robots = 5 | ||
num_trials = 10 | ||
|
||
env = gym.make('tiling-pattern-v0') | ||
|
||
|
||
def eval_genomes(genomes, config): | ||
count = 0 | ||
for genome_id, genome in genomes: | ||
print(count) | ||
count += 1 | ||
net = neat.nn.FeedForwardNetwork.create(genome, config) | ||
genome.fitness = run_environment(net) | ||
|
||
|
||
def run_environment(net): | ||
reward = 0 | ||
for _ in range(num_trials): | ||
observation = env.reset() | ||
|
||
sub_reward = 0 | ||
|
||
for i in range(num_steps): | ||
output = [net.activate(observation[i]) for i in range(len(observation))] | ||
observation, sub_reward, done, info = env.step(output) | ||
|
||
reward += sub_reward | ||
|
||
return reward / num_trials | ||
|
||
|
||
def run(config_file): | ||
# Load configuration. | ||
config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction, | ||
neat.DefaultSpeciesSet, neat.DefaultStagnation, | ||
config_file) | ||
|
||
# Create the population, which is the top-level object for a NEAT run. | ||
p = neat.Population(config) | ||
|
||
# Add a stdout reporter to show progress in the terminal. | ||
p.add_reporter(neat.StdOutReporter(True)) | ||
stats = neat.StatisticsReporter() | ||
p.add_reporter(stats) | ||
|
||
# Run for up to 300 generations. | ||
winner = p.run(eval_genomes, 300) | ||
|
||
# Display the winning genome. | ||
print('\nBest genome:\n{!s}'.format(winner)) | ||
|
||
|
||
if __name__ == '__main__': | ||
# Determine path to configuration file. This path manipulation is | ||
# here so that the script will run successfully regardless of the | ||
# current working directory. | ||
local_dir = os.path.dirname(__file__) | ||
config_path = os.path.join(local_dir, 'config-feedforward') | ||
run(config_path) |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.