Skip to content

Commit 85bc17d

Browse files
Initial docs (#39)
* Write documentation structure and initial docs. Have also included a doctest runner. Once we're happy with this I'll flick the switch on read the docs. * Return to the original scaling for GA. Also include brief background.
1 parent 49ef509 commit 85bc17d

16 files changed

+635
-3
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ script:
1515
- python setup.py develop
1616
- coverage run --source=src -m unittest discover tests
1717
- coverage report -m
18+
- python doctests.py
1819
after_success:
1920
- coveralls

docs/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line.
5+
SPHINXOPTS =
6+
SPHINXBUILD = python -msphinx
7+
SPHINXPROJ = Axelrod-dojo
8+
SOURCEDIR = .
9+
BUILDDIR = _build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/background/genetic_algorithm.rst

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
Genetic Algorithm
2+
=================
3+
4+
A genetic algorithm aims to mimic evolutionary processes so as to optimise a
5+
particular function on some space of candidate solutions.
6+
7+
The process can be described by assuming that there is a function
8+
:math:`f:V\to \mathbb{R}`, where :math:`V` is some vector space.
9+
In the case of the Prisoner's dilemma,
10+
the vector space :math:`V` corresponds to some representation of a
11+
particular archetype (which might not actually be a numeric vector space) and
12+
the function :math:`f` corresponds to some measure of performance/fitness of the
13+
strategy in question.
14+
15+
In this setting a candidate solution :math:`x\in\mathbb{R}^m` corresponds to a
16+
chromosome with each :math:`x_i` corresponding to a gene.
17+
18+
The genetic algorithm has three essential parameters:
19+
20+
- The population size: the algorithm makes use of a number of candidate
21+
solutions at each stage.
22+
- The bottle neck parameter: at every stage the candidates in the population are
23+
ranked according to their fitness, only a certain number are kept (the best
24+
performing ones) from one generation to the next. This number is referred to
25+
as the bottle neck.
26+
- The mutation probability: from one stage to the next when new individuals are
27+
added to the population (more about this process shortly) there is a
28+
probability with which each gene randomly mutates.
29+
30+
New individuals are added to the population (so as to ensure that the population
31+
size stays constant from one stage to the next) using a process of "crossover".
32+
Two high performing individuals are paired and according to some predefined
33+
procedure, genes from both these individuals are combined to create a new
34+
individual.
35+
36+
For each strategy archetype, this library thus defines a process for mutation as
37+
well as for crossover.
38+
39+
Finite state machines
40+
---------------------
41+
42+
A finite state machine is made up of the following:
43+
44+
- a mapping from a state/action pair to another target state/action pair
45+
- an initial state/action pair.
46+
47+
(See [Harper2017]_ for more details.)
48+
49+
The crossover and mutation are implemented in the following way:
50+
51+
- Crossover: this is done by taking a randomly selected number of target
52+
state/actions
53+
pairs from one individual and the rest from the other.
54+
- Mutation: given a mutation probability :math:`delta` each target state/action
55+
has a probability :math:`\delta` of being randomly changed to one of the other
56+
states or actions. Furthermore the **initial** action has a probability of
57+
being swapped of :math:`\delta\times 10^{-1}` and the **initial** state has a
58+
probability of being changed to another random state of :math:`\delta \times
59+
10^{-1} \times N` (where :math:`N` is the number of states).

docs/background/index.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Background
2+
==========
3+
4+
Note that there are currently two algorithms implemented:
5+
6+
- Genetic algorithm
7+
- Particle swam optimisation
8+
9+
Note that these two algorithms are not equally suited to each archetype. For
10+
example the Genetic algorithm is believed to be better suited to discrete space
11+
strategies such as the finite state machines whilst the Particle swarm algorithm
12+
would be better suited to a continuous space strategy such as the Gambler.
13+
14+
For more information on these algorithms and their implementations see:
15+
16+
17+
.. toctree::
18+
:maxdepth: 2
19+
20+
genetic_algorithm.rst

docs/conf.py

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Axelrod-dojo documentation build configuration file, created by
5+
# sphinx-quickstart on Wed Oct 11 09:40:19 2017.
6+
#
7+
# This file is execfile()d with the current directory set to its
8+
# containing dir.
9+
#
10+
# Note that not all possible configuration values are present in this
11+
# autogenerated file.
12+
#
13+
# All configuration values have a default; values that are commented out
14+
# serve to show the default.
15+
16+
# If extensions (or modules to document with autodoc) are in another directory,
17+
# add these directories to sys.path here. If the directory is relative to the
18+
# documentation root, use os.path.abspath to make it absolute, like shown here.
19+
#
20+
# import os
21+
# import sys
22+
# sys.path.insert(0, os.path.abspath('.'))
23+
24+
25+
# -- General configuration ------------------------------------------------
26+
27+
# If your documentation needs a minimal Sphinx version, state it here.
28+
#
29+
# needs_sphinx = '1.0'
30+
31+
# Add any Sphinx extension module names here, as strings. They can be
32+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
33+
# ones.
34+
extensions = ['sphinx.ext.mathjax']
35+
36+
# Add any paths that contain templates here, relative to this directory.
37+
templates_path = ['_templates']
38+
39+
# The suffix(es) of source filenames.
40+
# You can specify multiple suffix as a list of string:
41+
#
42+
# source_suffix = ['.rst', '.md']
43+
source_suffix = '.rst'
44+
45+
# The master toctree document.
46+
master_doc = 'index'
47+
48+
# General information about the project.
49+
project = 'Axelrod-dojo'
50+
copyright = '2017, The Axelrod project developers'
51+
author = 'The Axelrod project developers'
52+
53+
# The version info for the project you're documenting, acts as replacement for
54+
# |version| and |release|, also used in various other places throughout the
55+
# built documents.
56+
#
57+
# The short X.Y version.
58+
version = ''
59+
# The full version, including alpha/beta/rc tags.
60+
release = ''
61+
62+
# The language for content autogenerated by Sphinx. Refer to documentation
63+
# for a list of supported languages.
64+
#
65+
# This is also used if you do content translation via gettext catalogs.
66+
# Usually you set "language" from the command line for these cases.
67+
language = None
68+
69+
# List of patterns, relative to source directory, that match files and
70+
# directories to ignore when looking for source files.
71+
# This patterns also effect to html_static_path and html_extra_path
72+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
73+
74+
# The name of the Pygments (syntax highlighting) style to use.
75+
pygments_style = 'sphinx'
76+
77+
# If true, `todo` and `todoList` produce output, else they produce nothing.
78+
todo_include_todos = False
79+
80+
81+
# -- Options for HTML output ----------------------------------------------
82+
83+
# The theme to use for HTML and HTML Help pages. See the documentation for
84+
# a list of builtin themes.
85+
#
86+
html_theme = 'alabaster'
87+
88+
# Theme options are theme-specific and customize the look and feel of a theme
89+
# further. For a list of options available for each theme, see the
90+
# documentation.
91+
#
92+
# html_theme_options = {}
93+
94+
# Add any paths that contain custom static files (such as style sheets) here,
95+
# relative to this directory. They are copied after the builtin static files,
96+
# so a file named "default.css" will overwrite the builtin "default.css".
97+
html_static_path = ['_static']
98+
99+
# Custom sidebar templates, must be a dictionary that maps document names
100+
# to template names.
101+
#
102+
# This is required for the alabaster theme
103+
# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars
104+
html_sidebars = {
105+
'**': [
106+
'about.html',
107+
'navigation.html',
108+
'relations.html', # needs 'show_related': True theme option to display
109+
'searchbox.html',
110+
'donate.html',
111+
]
112+
}
113+
114+
115+
# -- Options for HTMLHelp output ------------------------------------------
116+
117+
# Output file base name for HTML help builder.
118+
htmlhelp_basename = 'Axelrod-dojodoc'
119+
120+
121+
# -- Options for LaTeX output ---------------------------------------------
122+
123+
latex_elements = {
124+
# The paper size ('letterpaper' or 'a4paper').
125+
#
126+
# 'papersize': 'letterpaper',
127+
128+
# The font size ('10pt', '11pt' or '12pt').
129+
#
130+
# 'pointsize': '10pt',
131+
132+
# Additional stuff for the LaTeX preamble.
133+
#
134+
# 'preamble': '',
135+
136+
# Latex figure (float) alignment
137+
#
138+
# 'figure_align': 'htbp',
139+
}
140+
141+
# Grouping the document tree into LaTeX files. List of tuples
142+
# (source start file, target name, title,
143+
# author, documentclass [howto, manual, or own class]).
144+
latex_documents = [
145+
(master_doc, 'Axelrod-dojo.tex', 'Axelrod-dojo Documentation',
146+
'The Axelrod project developers', 'manual'),
147+
]
148+
149+
150+
# -- Options for manual page output ---------------------------------------
151+
152+
# One entry per manual page. List of tuples
153+
# (source start file, name, description, authors, manual section).
154+
man_pages = [
155+
(master_doc, 'axelrod-dojo', 'Axelrod-dojo Documentation',
156+
[author], 1)
157+
]
158+
159+
160+
# -- Options for Texinfo output -------------------------------------------
161+
162+
# Grouping the document tree into Texinfo files. List of tuples
163+
# (source start file, target name, title, author,
164+
# dir menu entry, description, category)
165+
texinfo_documents = [
166+
(master_doc, 'Axelrod-dojo', 'Axelrod-dojo Documentation',
167+
author, 'Axelrod-dojo', 'One line description of project.',
168+
'Miscellaneous'),
169+
]
170+
171+
172+

docs/howtos/index.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
How to
2+
======
3+
4+
.. toctree::
5+
:maxdepth: 1
6+
7+
use-different-ojective-functions.rst
8+
train-using-genetic-algorithm.rst
9+
train-using-particle-swarm-algorithm.rst
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Train using the genetic algorithm
2+
=================================
3+
4+
WIP: include all details for training with genetic algorithm.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Train using the particle swarm algorithm
2+
========================================
3+
4+
WIP: include all details for training with PSO
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Use different objective functions
2+
=================================
3+
4+
It is currently possible to optimise players for 3 different objectives:
5+
6+
- Score;
7+
- Score difference;
8+
- Probability of fixation in a Moran process.
9+
10+
This is done by passing a different objective :code:`name` to the
11+
:code:`prepare_objective` function::
12+
13+
>>> import axelrod_dojo as dojo
14+
>>> score_objective = dojo.prepare_objective(name="score", turns=10, repetitions=1)
15+
>>> diff_objective = dojo.prepare_objective(name="score_diff", turns=10, repetitions=1)
16+
>>> moran_objective = dojo.prepare_objective(name="moran", turns=10, repetitions=1)

docs/index.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.. Axelrod-dojo documentation master file, created by
2+
sphinx-quickstart on Wed Oct 11 09:40:19 2017.
3+
You can adapt this file completely to your liking, but it should at least
4+
contain the root `toctree` directive.
5+
6+
Welcome to Axelrod-dojo's documentation!
7+
========================================
8+
9+
This library is a companion library to the `Axelrod
10+
<http://axelrod.readthedocs.io/en/stable/>`_ library: a research tool for the
11+
study of the iterated prisoners dilemma. The **Axelrod-dojo** is used to train
12+
strategies.
13+
14+
This is done using implementations of:
15+
16+
- Strategy archetypes :code:`Parameters`
17+
- Algorithms
18+
19+
Table of Contents
20+
-----------------
21+
22+
.. toctree::
23+
:maxdepth: 3
24+
25+
tutorial/index.rst
26+
howtos/index.rst
27+
background/index.rst
28+
reference/index.rst
29+
30+
31+
Indices and tables
32+
==================
33+
34+
* :ref:`genindex`
35+
* :ref:`modindex`
36+
* :ref:`search`

0 commit comments

Comments
 (0)