Documentation ¶
Index ¶
- func AddRandomNeuron(counter Counter, g *Genotype, activation Activation) error
- func AddRandomSynapse(counter Counter, g *Genotype, weightStddev float64, isRecurrent bool, ...) error
- func MutateRandomSynapse(g *Genotype, stddev float64)
- func PruneRandomSynapse(g *Genotype)
- type Activation
- type AtomicCounter
- type Counter
- type Genotype
- func (n *Genotype) AddNeuron(counter Counter, conn int, activation Activation) (int, int, error)
- func (n *Genotype) AddSynapse(counter Counter, from, to int, weight float64) (int, error)
- func (n *Genotype) GetNeuronOrder(nid int) (int, error)
- func (n *Genotype) IsNeuron(id int) bool
- func (n *Genotype) IsSynapse(id int) bool
- func (n *Genotype) LookupSynapse(from, to int) (int, error)
- func (n *Genotype) PruneSynapse(sid int) error
- func (n *Genotype) Topology() (int, int, int)
- type GenotypeVisualiser
- type Neuron
- type NeuronType
- type Phenotype
- type PhenotypeConnection
- type RecurrentPhenotypeConnection
- type Synapse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddRandomNeuron ¶
func AddRandomNeuron(counter Counter, g *Genotype, activation Activation) error
Add a neuron on a random synapse of `g` with activation function `activation`
func AddRandomSynapse ¶
func AddRandomSynapse(counter Counter, g *Genotype, weightStddev float64, isRecurrent bool, attempts int) error
Add a new synapse to `g` with weight sampled from normal distribution with standard deviation `stddev`. `isRecurrent` specifies if the synapse should be recurrent or forward-facing. `attempts` is the maximum number of random combinations of neurons to try before deciding there is no more space for synapses. A good value for `attempts` is 5
func MutateRandomSynapse ¶
Mutate the weight of a random synapse in `g` by sampling the normal distribution with standard deviation `stddev“
func PruneRandomSynapse ¶
func PruneRandomSynapse(g *Genotype)
Prune a random synapse from `g`. This has the capability to prun more than one synapse and neuron as it also removes redundant neurons and synapses.
Types ¶
type Activation ¶
type Activation string
A string representing an activation function. It must be one of the consts that start with 'Activation...'
const ( // y = x ActivationLinear Activation = "linear" // y = x {x > 0} | y = 0 {x <= 0} ActivationReLU Activation = "relu" // y = tanh(x) ActivationTanh Activation = "tanh" // y = ln(x) {x > 0} | y = 0 {x <= 0}. I have found this can benefit recurrent networks by not allowing the values to explode ActivationReLn Activation = "reln" // y = sigmoid(x) ActivationSigmoid Activation = "sigmoid" // y = x {1 > x > 0} | y = 0 {x <= 0} | y = 1 {x >= 1} ActivationReLUMax Activation = "relumax" )
type AtomicCounter ¶
type AtomicCounter struct {
I int64
}
An implementation of the Counter interface which is goroutine safe
type Counter ¶
type Counter interface { // Get the next innovation id Next() int }
An interface that describes a type that can generate unique ids
func NewAtomicCounter ¶
func NewAtomicCounter() Counter
Create a new AtomicCounter which starts from id 0
type Genotype ¶
type Genotype struct { // The number of input neurons. READONLY NumIn int `json:"num_in"` // The number of output neurons. READONLY NumOut int `json:"num_out"` // A record of all neurons stored according to their id. READONLY Neurons map[int]*Neuron `json:"neurons"` // A record of all synapses stored according to their id. READONLY Synapses map[int]*Synapse `json:"synapses"` // A record of all neurons ids stored in execution order. READONLY NeuronOrder []int `json:"neuron_order"` // A record of all neurons orders stored according to neuron id. READONLY InverseNeuronOrder map[int]int `json:"inverse_neuron_order"` }
A type representing a genotype (effectively DNA) used in the NEAT algorithm
func NewGenotype ¶
func NewGenotype(counter Counter, numIn, numOut int, inActivation, outActivation Activation) *Genotype
Create a new Genotype. Create all new innovation IDs with the provided Counter `counter`. The genotype will have `numIn` input nodes and `numOut` output nodes. The input nodes will have activation `inActivation` and the output nodes will have activation `outActivation`
func NewGenotypeCopy ¶
Create a new Genotype which is a clone of `g`
func NewGenotypeEmpty ¶
func NewGenotypeEmpty() *Genotype
func (*Genotype) AddNeuron ¶
Create a hidden neuron on a synapse using the provided Counter, with activation function `activation`. `conn` is the ID of the synapse to create the neuron on, and `conn` must not refer to a recurrent connection. Will return `neuronID, synapseID, error`, where synapseID is the id of the synapse that was created due to the original synapse being split. This synapse connects the new neuron to the old synapses endpoint, and the old synapses endpoint is moved to the new neuron
func (*Genotype) AddSynapse ¶
Create a synapse between two neurons using the provided Counter, with weight `weight`. `from` and `to` are the innovation IDs of two neurons. If `from` is ordered after `to` then the connection is recurrent. Will return `synapseID, error`
func (*Genotype) GetNeuronOrder ¶
Gets the order (position in which the neurons are calculated) of a neuron ID
func (*Genotype) LookupSynapse ¶
Find the ID of the synapse that goes from `from` to `to`. Will return `synapseID, error`, where error might be caused by the connection not existing
func (*Genotype) PruneSynapse ¶
Prune the synapse with id `sid` from the genotype. Then recursively check to see if this has made any other synapses or neurons redundant, and remove those too.
type GenotypeVisualiser ¶
type GenotypeVisualiser struct { ImgSizeX int ImgSizeY int NeuronSize int InputNeuronColor color.Color HiddenNeuronColor color.Color OutputNeuronColor color.Color }
func NewGenotypeVisualiser ¶
func NewGenotypeVisualiser() GenotypeVisualiser
func (*GenotypeVisualiser) DrawImage ¶
func (v *GenotypeVisualiser) DrawImage(g *Genotype) draw.Image
func (*GenotypeVisualiser) DrawImageToJPGFile ¶
func (v *GenotypeVisualiser) DrawImageToJPGFile(filename string, g *Genotype)
func (*GenotypeVisualiser) DrawImageToPNGFile ¶
func (v *GenotypeVisualiser) DrawImageToPNGFile(filename string, g *Genotype)
type Neuron ¶
type Neuron struct { // The type of this neuron Type NeuronType `json:"type"` // The activation of this neuron Activation Activation `json:"activation"` }
A type representing a genotype neuron
type NeuronType ¶
type NeuronType string
A type denoting the type of a neuron (input, hidden, output). Must be one of the consts that start with 'Neuron...'
const ( // Input neuron NeuronInput NeuronType = "input" // Hidden neuron NeuronHidden NeuronType = "hidden" // Output neuron NeuronOutput NeuronType = "output" )
type Phenotype ¶
type Phenotype struct {
// contains filtered or unexported fields
}
Data type representing a phenotype, a sort of compiled genotype
func (*Phenotype) ClearRecurrentMemory ¶
func (p *Phenotype) ClearRecurrentMemory()
Clear any memory retained from previous calls to `p.Forward`
type PhenotypeConnection ¶
Data type for a phenotype connection
type RecurrentPhenotypeConnection ¶
Data type for a recurrent phenotype connection
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
geno
|
|
arr
Module
|
|
floatarr
Module
|
|
neat
Module
|
|
pop
|
|
hillclimber
Module
|
|
simple
Module
|
|
speciated
Module
|
|
selec
|
|
elite
Module
|
|
tournament
Module
|