Skip to content

Commit

Permalink
Added ReadTheDocs configuration.
Browse files Browse the repository at this point in the history
Add custom aggregation function to memory-fixed example.
Modify memory-fixed example configuration to make better progress.
  • Loading branch information
CodeReclaimers committed May 4, 2022
1 parent af3b25b commit 63f4cf8
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 13 deletions.
29 changes: 29 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions docs/customization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,30 @@ This is demonstrated in the `memory-fixed
the :py:class:`DefaultGenomeConfig <genome.DefaultGenomeConfig>` implementation; different genome implementations
may require a different method of registration.

.. index:: aggregation function

New aggregation functions
-------------------------
New :term:`aggregation functions <aggregation function>` are registered with your :py:class:`Config <config.Config>` instance, prior to creation of the
:py:class:`Population <population.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 <genome.DefaultGenomeConfig.add_aggregation>` is the name by which this aggregation function will be referred to in the configuration settings file.

This is demonstrated in the `memory-fixed
<https://github.com/CodeReclaimers/neat-python/tree/master/examples/memory-fixed>`_ example.

.. note::

This method is only valid when using the :py:class:`DefaultGenome <genome.DefaultGenome>` implementation, with the method being found in
the :py:class:`DefaultGenomeConfig <genome.DefaultGenomeConfig>` implementation; different genome implementations
may require a different method of registration.


.. index:: reporting

Reporting/logging
Expand Down
20 changes: 10 additions & 10 deletions examples/memory-fixed/config
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

18 changes: 15 additions & 3 deletions examples/memory-fixed/evolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"""

import math
import multiprocessing
import os
import random

Expand All @@ -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.
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 63f4cf8

Please sign in to comment.