neet-0.4.0.0: A NEAT library for Haskell

Copyright(c) Leon Medvinsky, 2015
LicenseGPL-3
Maintainerlmedvinsky@hotmail.com
Stabilityexperimental
Portabilityghc
Safe HaskellNone
LanguageHaskell2010

Neet.Genome

Contents

Description

 

Synopsis

Genes

newtype NodeId Source

The IDs node genes use to refer to nodes.

Constructors

NodeId 

Fields

getNodeId :: Int
 

data NodeType Source

Types of nodes

Constructors

Input 
Hidden 
Output 

data NodeGene Source

Node genes

Constructors

NodeGene 

Fields

nodeType :: NodeType
 
yHint :: Rational

A hint for recurrency

data ConnGene Source

Connection genes

Constructors

ConnGene 

Fields

connIn :: NodeId
 
connOut :: NodeId
 
connWeight :: Double
 
connEnabled :: Bool
 
connRec :: Bool

A hint for recurrency

newtype InnoId Source

Innovation IDs

Constructors

InnoId 

Fields

getInnoId :: Int
 

data ConnSig Source

Signature of a connection, used in matching innovations fromthe same generation.

Genome

data Genome Source

A NEAT genome. The innovation numbers are stored in here, and not the genes, to prevent data duplication.

Construction

fullConn :: MonadRandom m => MutParams -> Int -> Int -> m Genome Source

Takes the number of inputs, the number of outputs, and gives a genome with the inputs fully connected to the outputs with random weights. The order of the connections are deterministic, so when generating a population, you can just start the innovation number at (iSize + 1) * oSize, since the network includes an additional input for the bias.

sparseConn :: MonadRandom m => MutParams -> Int -> Int -> Int -> m Genome Source

Like fullConn, but with only some input-outputs connected. First integer parameters is the max number of connections to start with.

Stats

genomeComplexity :: Genome -> Int Source

Total number of links and nodes.

Breeding

mutateAdd :: (MonadRandom m, MonadFresh InnoId m) => MutParams -> Map ConnSig InnoId -> Genome -> m (Map ConnSig InnoId, Genome) Source

Mutates the genome, using the specified parameters and innovation context.

mutateSub :: MonadRandom m => MutParams -> Genome -> m Genome Source

Mutates the genome, but uses subtractive mutations instead of additive.

crossover :: MonadRandom m => MutParams -> Genome -> Genome -> m Genome Source

Crossover. The first argument is the fittest genome.

breed :: (MonadRandom m, MonadFresh InnoId m) => MutParams -> Map ConnSig InnoId -> Genome -> Genome -> m (Map ConnSig InnoId, Genome) Source

Breed two genomes together

Distance

distance :: Parameters -> Genome -> Genome -> Double Source

Genetic distance between two genomes

Fitness

data GenScorer score Source

Parameters for search. The type parameter determines the intermediate type for determining if a solution is valid.

Constructors

GS 

Fields

gScorer :: Genome -> score

Scoring function

fitnessFunction :: score -> Double

Convert the score to a fitness

winCriteria :: score -> Bool

Determines if a result is win

Visualization

renderGenome :: Genome -> IO () Source

This graph produced is ugly and janky and will have bugs, like hidden nodes occasionally appearing with output nodes, and weird clustering overall. If you see some problems in the graph, confirm with the Show instance or something else that there really is a problem.

printGenome :: Genome -> IO () Source

A nicer way to display a Genome than the Show instance.

Debugging

validateGenome :: Genome -> Maybe [String] Source

Validates a Genome, returning Nothing on success.