diff --git a/.readthedocs.yaml b/.readthedocs.yaml new file mode 100644 index 00000000..e16e01c7 --- /dev/null +++ b/.readthedocs.yaml @@ -0,0 +1,29 @@ +# .readthedocs.yaml +# Read the Docs configuration file +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details + +# Required +version: 2 + +# Set the version of Python and other tools you might need +build: + os: ubuntu-20.04 + tools: + python: "3.9" + # You can also specify other tool versions: + # nodejs: "16" + # rust: "1.55" + # golang: "1.17" + +# Build documentation in the docs/ directory with Sphinx +sphinx: + configuration: docs/conf.py + +# If using Sphinx, optionally build your docs in additional formats such as PDF +# formats: +# - pdf + +# Optionally declare the Python requirements required to build your docs +#python: +# install: +# - requirements: docs/requirements.txt \ No newline at end of file diff --git a/docs/customization.rst b/docs/customization.rst index 189d4660..025efa6e 100644 --- a/docs/customization.rst +++ b/docs/customization.rst @@ -32,6 +32,30 @@ This is demonstrated in the `memory-fixed the :py:class:`DefaultGenomeConfig ` implementation; different genome implementations may require a different method of registration. +.. index:: aggregation function + +New aggregation functions +------------------------- +New :term:`aggregation functions ` are registered with your :py:class:`Config ` instance, prior to creation of the +:py:class:`Population ` instance, as follows:: + + def l2norm(x): + return sqrt(sum(i**2 for i in x)) + + config.genome_config.add_activation('my_l2norm_function', l2norm) + +The first argument to :py:meth:`add_activation ` is the name by which this aggregation function will be referred to in the configuration settings file. + +This is demonstrated in the `memory-fixed +`_ example. + +.. note:: + + This method is only valid when using the :py:class:`DefaultGenome ` implementation, with the method being found in + the :py:class:`DefaultGenomeConfig ` implementation; different genome implementations + may require a different method of registration. + + .. index:: reporting Reporting/logging diff --git a/examples/memory-fixed/config b/examples/memory-fixed/config index b9432358..648ffbd5 100644 --- a/examples/memory-fixed/config +++ b/examples/memory-fixed/config @@ -16,16 +16,16 @@ initial_connection = partial_direct 0.5 feed_forward = False compatibility_disjoint_coefficient = 1.0 compatibility_weight_coefficient = 0.6 -conn_add_prob = 0.1 -conn_delete_prob = 0.1 -node_add_prob = 0.1 -node_delete_prob = 0.1 +conn_add_prob = 0.2 +conn_delete_prob = 0.2 +node_add_prob = 0.2 +node_delete_prob = 0.2 activation_default = my_sinc_function activation_options = sigmoid my_sinc_function activation_mutate_rate = 0.1 aggregation_default = sum -aggregation_options = sum -aggregation_mutate_rate = 0.0 +aggregation_options = sum my_l2norm_function +aggregation_mutate_rate = 0.1 bias_init_mean = 0.0 bias_init_stdev = 1.0 bias_replace_rate = 0.1 @@ -52,13 +52,13 @@ enabled_default = True enabled_mutate_rate = 0.01 [DefaultSpeciesSet] -compatibility_threshold = 3.0 +compatibility_threshold = 3.1 [DefaultStagnation] -species_fitness_func = max +species_fitness_func = mean max_stagnation = 20 [DefaultReproduction] -elitism = 2 -survival_threshold = 0.2 +elitism = 5 +survival_threshold = 0.3 diff --git a/examples/memory-fixed/evolve.py b/examples/memory-fixed/evolve.py index 683f25fb..3fdf13b4 100644 --- a/examples/memory-fixed/evolve.py +++ b/examples/memory-fixed/evolve.py @@ -7,7 +7,6 @@ """ import math -import multiprocessing import os import random @@ -24,6 +23,15 @@ def sinc(x): return 1.0 if x == 0 else math.sin(x) / x +# Demonstration of how to add your own custom aggregation function. +# This l2norm function will be available if my_l2norm_function is included in the +# config file aggregation_options option under the DefaultGenome section. +# Note that l2norm is not necessarily useful for this example, it was chosen +# arbitrarily just to demonstrate adding a custom aggregation function. +def l2norm(x): + return (sum(i**2 for i in x))**0.5 + + # N is the length of the test sequence. N = 4 # num_tests is the number of random examples each network is tested against. @@ -74,13 +82,17 @@ def run(): # config file activation_options option under the DefaultGenome section. config.genome_config.add_activation('my_sinc_function', sinc) + # Demonstration of how to add your own custom aggregation function. + # This l2norm function will be available if my_l2norm_function is included in the + # config file aggregation_options option under the DefaultGenome section. + config.genome_config.add_aggregation('my_l2norm_function', l2norm) + pop = neat.Population(config) stats = neat.StatisticsReporter() pop.add_reporter(stats) pop.add_reporter(neat.StdOutReporter(True)) - pe = neat.ParallelEvaluator(multiprocessing.cpu_count(), eval_genome) - winner = pop.run(pe.evaluate, 1000) + winner = pop.run(eval_genomes, 200) # Log statistics. stats.save()