complete HyperNEAT!
This commit is contained in:
1
config/__init__.py
Normal file
1
config/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .config import Configer
|
||||
70
config/config.py
Normal file
70
config/config.py
Normal file
@@ -0,0 +1,70 @@
|
||||
import os
|
||||
import warnings
|
||||
import configparser
|
||||
|
||||
import numpy as np
|
||||
|
||||
|
||||
class Configer:
|
||||
|
||||
@classmethod
|
||||
def __load_default_config(cls):
|
||||
par_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
default_config_path = os.path.join(par_dir, "default_config.ini")
|
||||
return cls.__load_config(default_config_path)
|
||||
|
||||
@classmethod
|
||||
def __load_config(cls, config_path):
|
||||
c = configparser.ConfigParser()
|
||||
c.read(config_path)
|
||||
config = {}
|
||||
|
||||
for section in c.sections():
|
||||
for key, value in c.items(section):
|
||||
config[key] = eval(value)
|
||||
|
||||
return config
|
||||
|
||||
@classmethod
|
||||
def __check_redundant_config(cls, default_config, config):
|
||||
for key in config:
|
||||
if key not in default_config:
|
||||
warnings.warn(f"Redundant config: {key} in config!")
|
||||
|
||||
@classmethod
|
||||
def __complete_config(cls, default_config, config):
|
||||
for key in default_config:
|
||||
if key not in config:
|
||||
config[key] = default_config[key]
|
||||
|
||||
@classmethod
|
||||
def load_config(cls, config_path=None):
|
||||
default_config = cls.__load_default_config()
|
||||
if config_path is None:
|
||||
config = {}
|
||||
elif not os.path.exists(config_path):
|
||||
warnings.warn(f"config file {config_path} not exist!")
|
||||
config = {}
|
||||
else:
|
||||
config = cls.__load_config(config_path)
|
||||
|
||||
cls.__check_redundant_config(default_config, config)
|
||||
cls.__complete_config(default_config, config)
|
||||
|
||||
cls.refactor_activation(config)
|
||||
cls.refactor_aggregation(config)
|
||||
|
||||
config['input_idx'] = np.arange(config['num_inputs'])
|
||||
config['output_idx'] = np.arange(config['num_inputs'], config['num_inputs'] + config['num_outputs'])
|
||||
|
||||
return config
|
||||
|
||||
@classmethod
|
||||
def refactor_activation(cls, config):
|
||||
config['activation_default'] = 0
|
||||
config['activation_options'] = np.arange(len(config['activation_option_names']))
|
||||
|
||||
@classmethod
|
||||
def refactor_aggregation(cls, config):
|
||||
config['aggregation_default'] = 0
|
||||
config['aggregation_options'] = np.arange(len(config['aggregation_option_names']))
|
||||
82
config/default_config.ini
Normal file
82
config/default_config.ini
Normal file
@@ -0,0 +1,82 @@
|
||||
[basic]
|
||||
random_seed = 0
|
||||
generation_limit = 1000
|
||||
|
||||
[problem]
|
||||
fitness_threshold = 3.9999
|
||||
num_inputs = 2
|
||||
num_outputs = 1
|
||||
|
||||
[neat]
|
||||
network_type = "feedforward"
|
||||
activate_times = 5
|
||||
maximum_nodes = 50
|
||||
maximum_conns = 50
|
||||
maximum_species = 10
|
||||
|
||||
[hyperneat]
|
||||
below_threshold = 0.2
|
||||
max_weight = 3
|
||||
h_activation = "sigmoid"
|
||||
h_aggregation = "sum"
|
||||
h_activate_times = 5
|
||||
|
||||
[substrate]
|
||||
input_coors = [[-1, 1], [0, 1], [1, 1]]
|
||||
hidden_coors = [[-1, 0], [0, 0], [1, 0]]
|
||||
output_coors = [[0, -1]]
|
||||
|
||||
[population]
|
||||
pop_size = 10
|
||||
|
||||
[genome]
|
||||
compatibility_disjoint = 1.0
|
||||
compatibility_weight = 0.5
|
||||
conn_add_prob = 0.4
|
||||
conn_delete_prob = 0
|
||||
node_add_prob = 0.2
|
||||
node_delete_prob = 0
|
||||
|
||||
[species]
|
||||
compatibility_threshold = 3.0
|
||||
species_elitism = 2
|
||||
max_stagnation = 15
|
||||
genome_elitism = 2
|
||||
survival_threshold = 0.2
|
||||
min_species_size = 1
|
||||
spawn_number_change_rate = 0.5
|
||||
|
||||
[gene]
|
||||
# bias
|
||||
bias_init_mean = 0.0
|
||||
bias_init_std = 1.0
|
||||
bias_mutate_power = 0.5
|
||||
bias_mutate_rate = 0.7
|
||||
bias_replace_rate = 0.1
|
||||
|
||||
# response
|
||||
response_init_mean = 1.0
|
||||
response_init_std = 0.0
|
||||
response_mutate_power = 0.0
|
||||
response_mutate_rate = 0.0
|
||||
response_replace_rate = 0.0
|
||||
|
||||
# activation
|
||||
activation_default = "sigmoid"
|
||||
activation_option_names = ["tanh"]
|
||||
activation_replace_rate = 0.0
|
||||
|
||||
# aggregation
|
||||
aggregation_default = "sum"
|
||||
aggregation_option_names = ["sum"]
|
||||
aggregation_replace_rate = 0.0
|
||||
|
||||
# weight
|
||||
weight_init_mean = 0.0
|
||||
weight_init_std = 1.0
|
||||
weight_mutate_power = 0.5
|
||||
weight_mutate_rate = 0.8
|
||||
weight_replace_rate = 0.1
|
||||
|
||||
[visualize]
|
||||
renumber_nodes = True
|
||||
Reference in New Issue
Block a user