Commit 3118421e authored by Matteo De Carlo's avatar Matteo De Carlo

Added NEAT pseudocode

parent 212ff7e0
Pipeline #118 passed with stage
in 1 minute and 28 seconds
......@@ -679,13 +679,96 @@ This appendix is a collection of the pseudocode for the main components used in
\end{algorithm}
\todo[inline]{Insert NEAT Learner pseudocode}
\alglanguage{pseudocode}
\begin{algorithm}[H]
\caption{NEAT Learner}
\label{alg:NEATlearner}
\begin{algorithmic}[1]
\State TODO
\Function{NEAT.initialisation}{{}}
% \State // $pop$ short for population
\State $pop \gets$ \Call{init\_population}{{}}
\State $record_fitness \gets 0$
\EndFunction
\Function{NEAT.next\_generation}{{}}
\For{$specie \gets pop.species$}
\State $specie$\Call{.compute\_average\_and\_max\_fitness}{{}}
\State $specie$\Call{.adjust\_fitness\_by\_age}{{}}
\EndFor
\State $pop.species$\Call{.sort}{$fitness$}
\If{$pop.generation \mod 30 == 0$}
\State // Remove the lowest performing species over age $20$
\State $specie \gets pop.species$\Call{.find\_last}{$specie.age > 20$}
\If{$specie$ found}
\State $specie$\Call{.delete}{{}}
\EndIf
\EndIf
\For{$specie \gets pop.species$}
\State $specie$\Call{.compute\_expected\_offsprings}{{}}
\EndFor
% \State // Check for new record
\State $champ \gets pop.organisms$\Call{.sorted}{$fitness$}\Call{.first}{{}}
\If{$champ.fitness > record\_fitness$}
\State $record\_fitness \gets champ.fitness$
% \State \Call{print}{\"new record\"}
\EndIf
\For{$organism \gets pop.organisms$}
\State $new\_organism \gets organism$\Call{.reproduce}{{}}
\State $organism$\Call{.Insert}{$new\_organism$}
\EndFor
\State $NEAT$\Call{.speciate}{pop.species}
\State $NEAT$\Call{.generate\_phenotypes}{{}}
\EndFunction
\end{algorithmic}
\end{algorithm}
\begin{algorithm}[H]
\caption{NEAT oraganism reproduction}
\label{alg:NEATorganism}
\begin{algorithmic}[1]
\Function{organism.reproduce}{{}}
\State $organism \gets $\Call{Clone}{$organism$}
\If{\Call{Rand}{$0,1$} $< 0.8$}
\State $organism$\Call{.mutate\_weights}{{}}
\Else
\State // $mutate\_structure$ may call a crossover method with
\State // a compatible organism
\State $organism$\Call{.mutate\_structure}{{}}
\EndIf
\State \Return $organism$
\EndFunction
\end{algorithmic}
\end{algorithm}
\begin{algorithm}[H]
\caption{NEAT Speciation}
\label{alg:NEATspeciate}
\begin{algorithmic}[1]
\Function{NEAT.speciate}{{}}
\For{$org \gets pop.organisms$}
\State $specie \gets org.specie$
\State // If organism and specie are not compatible any more,
\State // search for a new one
\If{not $org$\Call{.is\_compatible}{$specie$}}
\State $org.specie \gets null$
\For{$specie \gets org.species$}
\If{$org$\Call{.is\_compatible}{$specie$}}
\State $org.species \gets specie$
\EndIf
\EndFor
\If{$org.specie == null$}
\State // No compatible specie found,
\State // creating a new one
\State $specie \gets $\Call{Create\_new\_specie}{{}}
\State $org.specie \gets specie$
\EndIf
\EndIf
\EndFor
\EndFunction
\end{algorithmic}
\end{algorithm}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment