Documentation ¶
Index ¶
- Variables
- func Activate(x float64, a Activation) float64
- func Clone[T Cloneable](obj T) T
- func SelectNGenotypes[T any](selection SelectionStrategy[T], n int) []T
- type Activation
- type Agent
- type Buildable
- type Cloneable
- type Counter
- type CrossoverMutateReproduction
- type CrossoverStrategy
- type Forwarder
- type GeneticDistance
- type MutationStrategy
- type Population
- type ReproductionStrategy
- type SelectionStrategy
Constants ¶
This section is empty.
Variables ¶
var AllActivations = []Activation{Relu, Linear, Sigmoid, Tanh, Sin, Cos, Binary, Reln, Relum, Sawtooth, Abs}
AllActivations is a list of all possible activations.
Functions ¶
func Activate ¶ added in v0.4.0
func Activate(x float64, a Activation) float64
Activate applies the activation function to the given value.
func Clone ¶ added in v0.4.2
func Clone[T Cloneable](obj T) T
Clone clones an object that implements the Cloneable interface. It also casts the child object to the type of the parent object.
func SelectNGenotypes ¶ added in v0.4.2
func SelectNGenotypes[T any](selection SelectionStrategy[T], n int) []T
SelectNGenotypes selects n genotypes from the given selection strategy, returning them in a slice.
Types ¶
type Activation ¶
type Activation int
Activation is an enum representing the different activation functions that can be used in a neural network.
const ( Relu Activation = iota Linear Sigmoid Tanh Sin Cos Binary Relum Reln Sawtooth Abs )
func (Activation) MarshalJSON ¶ added in v0.4.0
func (a Activation) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (Activation) String ¶ added in v0.4.0
func (a Activation) String() string
String returns the string representation of the activation.
func (*Activation) UnmarshalJSON ¶ added in v0.4.0
func (a *Activation) UnmarshalJSON(bs []byte) error
UnmarshalJSON implements json.Unmarshaler.
type Agent ¶ added in v0.2.0
Agent is a container for a genotype and its fitness. The genotype can be of any type.
type Buildable ¶ added in v0.4.2
type Buildable interface { // Build converts this genotype into a [Forwarder]. // This may be an expensive operation, so it should be called sparingly. Build() Forwarder }
Buildable is an interface that defines a method to build a Forwarder. If the genotype is already a Forwarder, it should return itself.
type Cloneable ¶ added in v0.4.2
type Cloneable interface {
Clone() any
}
Cloneable is an interface that must be implemented by any object that wants to be cloned. The clone method must return a new object that is a deep copy of the original object. This new method is typed as any. To clone while including the type, use Clone, which is generic so will perform the cast.
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
Counter is a simple counter that can be used to generate unique IDs.
func NewCounter ¶ added in v0.4.0
func NewCounter() *Counter
NewCounter creates a new counter, starting at 0.
type CrossoverMutateReproduction ¶ added in v0.4.3
type CrossoverMutateReproduction[T any] struct { Crossover CrossoverStrategy[T] Mutate MutationStrategy[T] }
CrossoverMutateReproduction is a ReproductionStrategy that first performs a CrossoverStrategy and then a MutationStrategy on the resulting child.
func NewCrossoverMutateReproduction ¶ added in v0.4.3
func NewCrossoverMutateReproduction[T any](crossover CrossoverStrategy[T], mutate MutationStrategy[T]) *CrossoverMutateReproduction[T]
NewCrossoverMutateReproduction creates a new CrossoverMutateReproduction with the given CrossoverStrategy and MutationStrategy.
func (*CrossoverMutateReproduction[T]) NumParents ¶ added in v0.4.3
func (r *CrossoverMutateReproduction[T]) NumParents() int
NumParents implements the ReproductionStrategy interface.
func (*CrossoverMutateReproduction[T]) Reproduce ¶ added in v0.4.3
func (r *CrossoverMutateReproduction[T]) Reproduce(parents []T) T
Reproduce implements the ReproductionStrategy interface.
type CrossoverStrategy ¶ added in v0.4.3
type CrossoverStrategy[T any] interface { // Crossover performs a crossover with this strategy on the given genotypes. // It can combine any number of genotypes (for example 1 for asexual, 2 for sexual, n for averaging of multiple?) Crossover([]T) T // NumParents returns the number of parents required for this crossover strategy NumParents() int }
CrossoverStrategy is an interface for a crossover strategy on a genotype with type T.
type Forwarder ¶ added in v0.3.0
type Forwarder interface { // Forward takes a set of inputs and returns a set of outputs. Forward([]float64) []float64 }
Forwarder is an interface for somthing that can take a set of inputs ([]float64) and return a set of outputs. It can be thought of as a function with a vector input and output.
type GeneticDistance ¶ added in v0.2.0
type GeneticDistance[T any] interface { // DistanceBetween calculates the genetic distance between two genotypes. DistanceBetween(a, b T) float64 }
GeneticDistance is an interface for calculating the genetic distance between two genotypes.
type MutationStrategy ¶ added in v0.4.3
type MutationStrategy[T any] interface { // Mutate performs a mutation in-place with this strategy on the given genotype Mutate(T) }
MutationStrategy is an interface for a mutation strategy on a genotype with type T.
type Population ¶ added in v0.4.2
type Population[T any] interface { // NextGeneration returns the population resulting from agents selected using this population's selection strategy // reproducing using this population's reproduction strategy. NextGeneration() Population[T] // All returns every [Agent] in the population. // This may have no particular order. All() []*Agent[T] }
Population is an interface for a population with genotypes with type T. It stores its genotypes wrapped in the Agent struct, to keep track of fitness. The population may also store a reference to a ReproductionStrategy and a SelectionStrategy to be used in the [NextGeneration] method.
type ReproductionStrategy ¶ added in v0.4.3
type ReproductionStrategy[T any] interface { // Reproduce takes a set of parent genotypes and returns a child genotype. Reproduce([]T) T // NumParents returns the number of parents required for this reproduction strategy NumParents() int }
ReproductionStrategy is an interface for a reproduction strategy on a genotype with type T. Most of the time, this will be a CrossoverMutateReproduction, however it is possible to imlement a custom one for more complex behaviour.
type SelectionStrategy ¶ added in v0.4.3
type SelectionStrategy[T any] interface { // SetAgents caches the [Agent]s which this selection will use until it is called again. // This is called once per generation. You may wish to perform slow operations here such as sorting by fitness. SetAgents(agents []*Agent[T]) // Select returns an [Agent] selected from the cached pool set by [SelectionStrategy.SetAgents]. Select() *Agent[T] }
SelectionStrategy is a strategy for selecting an Agent from a slice. It acts on agents of type T.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
geno
|
|
arr
Module
|
|
floatarr
Module
|
|
neat
Module
|
|
pop
|
|
hillclimber
Module
|
|
simple
Module
|
|
speciated
Module
|
|
selec
|
|
elite
Module
|
|
tournament
Module
|