Current Progress: After final design presentation
This commit is contained in:
1
configs/__init__.py
Normal file
1
configs/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .configer import Configer
|
||||
32
configs/activations.py
Normal file
32
configs/activations.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from neat.genome.activations import *
|
||||
|
||||
ACT_TOTAL_LIST = [sigmoid_act, tanh_act, sin_act, gauss_act, relu_act, elu_act, lelu_act, selu_act, softplus_act,
|
||||
identity_act, clamped_act, inv_act, log_act, exp_act, abs_act, hat_act, square_act, cube_act]
|
||||
|
||||
act_name2key = {
|
||||
'sigmoid': 0,
|
||||
'tanh': 1,
|
||||
'sin': 2,
|
||||
'gauss': 3,
|
||||
'relu': 4,
|
||||
'elu': 5,
|
||||
'lelu': 6,
|
||||
'selu': 7,
|
||||
'softplus': 8,
|
||||
'identity': 9,
|
||||
'clamped': 10,
|
||||
'inv': 11,
|
||||
'log': 12,
|
||||
'exp': 13,
|
||||
'abs': 14,
|
||||
'hat': 15,
|
||||
'square': 16,
|
||||
'cube': 17,
|
||||
}
|
||||
|
||||
|
||||
def refactor_act(config):
|
||||
config['activation_default'] = act_name2key[config['activation_default']]
|
||||
config['activation_options'] = [
|
||||
act_name2key[act_name] for act_name in config['activation_options']
|
||||
]
|
||||
20
configs/aggregations.py
Normal file
20
configs/aggregations.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from neat.genome.aggregations import *
|
||||
|
||||
AGG_TOTAL_LIST = [sum_agg, product_agg, max_agg, min_agg, maxabs_agg, median_agg, mean_agg]
|
||||
|
||||
agg_name2key = {
|
||||
'sum': 0,
|
||||
'product': 1,
|
||||
'max': 2,
|
||||
'min': 3,
|
||||
'maxabs': 4,
|
||||
'median': 5,
|
||||
'mean': 6,
|
||||
}
|
||||
|
||||
|
||||
def refactor_agg(config):
|
||||
config['aggregation_default'] = agg_name2key[config['aggregation_default']]
|
||||
config['aggregation_options'] = [
|
||||
agg_name2key[act_name] for act_name in config['aggregation_options']
|
||||
]
|
||||
97
configs/configer.py
Normal file
97
configs/configer.py
Normal file
@@ -0,0 +1,97 @@
|
||||
import os
|
||||
import warnings
|
||||
import configparser
|
||||
|
||||
from .activations import refactor_act
|
||||
from .aggregations import refactor_agg
|
||||
|
||||
# Configuration used in jit-able functions. The change of values will not cause the re-compilation of JAX.
|
||||
jit_config_keys = [
|
||||
"compatibility_disjoint",
|
||||
"compatibility_weight",
|
||||
"conn_add_prob",
|
||||
"conn_add_trials",
|
||||
"conn_delete_prob",
|
||||
"node_add_prob",
|
||||
"node_delete_prob",
|
||||
"compatibility_threshold",
|
||||
"bias_init_mean",
|
||||
"bias_init_stdev",
|
||||
"bias_mutate_power",
|
||||
"bias_mutate_rate",
|
||||
"bias_replace_rate",
|
||||
"response_init_mean",
|
||||
"response_init_stdev",
|
||||
"response_mutate_power",
|
||||
"response_mutate_rate",
|
||||
"response_replace_rate",
|
||||
"activation_default",
|
||||
"activation_options",
|
||||
"activation_replace_rate",
|
||||
"aggregation_default",
|
||||
"aggregation_options",
|
||||
"aggregation_replace_rate",
|
||||
"weight_init_mean",
|
||||
"weight_init_stdev",
|
||||
"weight_mutate_power",
|
||||
"weight_mutate_rate",
|
||||
"weight_replace_rate",
|
||||
"enable_mutate_rate",
|
||||
]
|
||||
|
||||
|
||||
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.name}")
|
||||
|
||||
@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)
|
||||
|
||||
refactor_act(config)
|
||||
refactor_agg(config)
|
||||
|
||||
return config
|
||||
|
||||
@classmethod
|
||||
def create_jit_config(cls, config):
|
||||
jit_config = {k: config[k] for k in jit_config_keys}
|
||||
return jit_config
|
||||
65
configs/default_config.ini
Normal file
65
configs/default_config.ini
Normal file
@@ -0,0 +1,65 @@
|
||||
[basic]
|
||||
num_inputs = 2
|
||||
num_outputs = 1
|
||||
init_maximum_nodes = 20
|
||||
init_maximum_connections = 20
|
||||
init_maximum_species = 10
|
||||
expands_coe = 2.0
|
||||
forward_way = "pop_batch"
|
||||
|
||||
[population]
|
||||
fitness_threshold = 100000
|
||||
generation_limit = 100
|
||||
fitness_criterion = "max"
|
||||
pop_size = 150
|
||||
|
||||
[genome]
|
||||
compatibility_disjoint = 1.0
|
||||
compatibility_weight = 0.5
|
||||
conn_add_prob = 0.5
|
||||
conn_add_trials = 1
|
||||
conn_delete_prob = 0
|
||||
node_add_prob = 0.2
|
||||
node_delete_prob = 0
|
||||
|
||||
[species]
|
||||
compatibility_threshold = 3.0
|
||||
species_elitism = 2
|
||||
species_max_stagnation = 15
|
||||
genome_elitism = 2
|
||||
survival_threshold = 0.2
|
||||
min_species_size = 1
|
||||
|
||||
[gene-bias]
|
||||
bias_init_mean = 0.0
|
||||
bias_init_stdev = 1.0
|
||||
bias_mutate_power = 0.5
|
||||
bias_mutate_rate = 0.7
|
||||
bias_replace_rate = 0.1
|
||||
|
||||
[gene-response]
|
||||
response_init_mean = 1.0
|
||||
response_init_stdev = 0.0
|
||||
response_mutate_power = 0.0
|
||||
response_mutate_rate = 0.0
|
||||
response_replace_rate = 0.0
|
||||
|
||||
[gene-activation]
|
||||
activation_default = "sigmoid"
|
||||
activation_options = ["sigmoid"]
|
||||
activation_replace_rate = 0.0
|
||||
|
||||
[gene-aggregation]
|
||||
aggregation_default = "sum"
|
||||
aggregation_options = ["sum"]
|
||||
aggregation_replace_rate = 0.0
|
||||
|
||||
[gene-weight]
|
||||
weight_init_mean = 0.0
|
||||
weight_init_stdev = 1.0
|
||||
weight_mutate_power = 0.5
|
||||
weight_mutate_rate = 0.8
|
||||
weight_replace_rate = 0.1
|
||||
|
||||
[gene-enable]
|
||||
enable_mutate_rate = 0.01
|
||||
Reference in New Issue
Block a user