cppn

package
v2.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package cppn provides implementation of Compositional Pattern Producing Network, which is a part of Hypercube-based NEAT algorithm implementation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FastSolverFromGenomeFile

func FastSolverFromGenomeFile(genomePath string) (network.Solver, error)

FastSolverFromGenomeFile Reads CPPN from specified genome and creates network solver

func NetworkFromGenomeFile

func NetworkFromGenomeFile(genomePath string) (*network.Network, error)

NetworkFromGenomeFile Reads CPPN from specified genome and creates phenotype network

Types

type EvolvableSubstrate

type EvolvableSubstrate struct {
	// Layout The layout of neuron nodes in this substrate
	Layout EvolvableSubstrateLayout
	// HiddenNodesActivation The activation function type for hidden neurons encoded
	HiddenNodesActivation neatmath.NodeActivationType
	// OutputNodesActivation The activation function type for output neurons encoded
	OutputNodesActivation neatmath.NodeActivationType
	// contains filtered or unexported fields
}

EvolvableSubstrate The evolvable substrate holds configuration of ANN produced by CPPN within the hypercube where each 4-dimensional point mark connection weight between two ANN units. The topology of ANN is not rigid as in plain substrate and can be evolved by introducing novel nodes to the ANN. This provides extra benefits that the topology of ANN should not be handcrafted by human, but produced during substrate generation from controlling CPPN, and node locations may be arbitrary that suits the best for the task at hand.

func NewEvolvableSubstrate

func NewEvolvableSubstrate(layout EvolvableSubstrateLayout, hiddenNodesActivation, outputNodesActivation neatmath.NodeActivationType) *EvolvableSubstrate

NewEvolvableSubstrate Creates new instance of evolvable substrate

func NewEvolvableSubstrateWithBias

func NewEvolvableSubstrateWithBias(layout EvolvableSubstrateLayout, hiddenNodesActivation, outputNodesActivation neatmath.NodeActivationType, cppnBias float64) *EvolvableSubstrate

NewEvolvableSubstrateWithBias creates new instance of evolvable substrate with defined cppnBias value. The cppnBias will be provided as the first value of the CPPN inputs array.

func (*EvolvableSubstrate) CreateNetworkSolver

func (es *EvolvableSubstrate) CreateNetworkSolver(cppn *network.Network, graphBuilder SubstrateGraphBuilder, options *eshyperneat.Options) (network.Solver, error)

CreateNetworkSolver Creates a network solver based on the current substrate layout and provided Compositional Pattern Producing Network, which used to define connections between network nodes. Optional graph_builder can be provided to collect graph nodes and edges of the created network solver. With graph builder it is possible to save/load network configuration as well as visualize it.

type EvolvableSubstrateLayout

type EvolvableSubstrateLayout interface {
	// NodePosition Returns coordinates of the neuron with specified index [0; count) and type
	NodePosition(index int, nType network.NodeNeuronType) (*PointF, error)

	// AddHiddenNode Adds a new hidden node to the substrate
	// Returns the index of added hidden neuron or error if failed.
	AddHiddenNode(position *PointF) (int, error)
	// IndexOfHidden Returns index of hidden node at a specified position or -1 if not fund
	IndexOfHidden(position *PointF) int

	// InputCount Returns the number of INPUT neurons in the layout
	InputCount() int
	// HiddenCount Returns the number of HIDDEN neurons in the layout
	HiddenCount() int
	// OutputCount Returns the number of OUTPUT neurons in the layout
	OutputCount() int
}

EvolvableSubstrateLayout Defines the layout of neurons in the substrate

type GridSubstrateLayout

type GridSubstrateLayout struct {
	// contains filtered or unexported fields
}

GridSubstrateLayout Defines grid substrate layout

func NewGridSubstrateLayout

func NewGridSubstrateLayout(biasCount, inputCount, outputCount, hiddenCount int) *GridSubstrateLayout

NewGridSubstrateLayout Creates new instance with specified number of nodes to create layout for

func (*GridSubstrateLayout) BiasCount

func (g *GridSubstrateLayout) BiasCount() int

func (*GridSubstrateLayout) HiddenCount

func (g *GridSubstrateLayout) HiddenCount() int

func (*GridSubstrateLayout) InputCount

func (g *GridSubstrateLayout) InputCount() int

func (*GridSubstrateLayout) NodePosition

func (g *GridSubstrateLayout) NodePosition(index int, nType network.NodeNeuronType) (*PointF, error)

func (*GridSubstrateLayout) OutputCount

func (g *GridSubstrateLayout) OutputCount() int

func (*GridSubstrateLayout) String

func (g *GridSubstrateLayout) String() string

type MappedEvolvableSubstrateLayout

type MappedEvolvableSubstrateLayout struct {
	// contains filtered or unexported fields
}

MappedEvolvableSubstrateLayout the EvolvableSubstrateLayout implementation using a map for binding between a hidden node and its index

func NewMappedEvolvableSubstrateLayout

func NewMappedEvolvableSubstrateLayout(inputCount, outputCount int) (*MappedEvolvableSubstrateLayout, error)

NewMappedEvolvableSubstrateLayout Creates new instance with given input and output neurons count

func (*MappedEvolvableSubstrateLayout) AddHiddenNode

func (m *MappedEvolvableSubstrateLayout) AddHiddenNode(position *PointF) (int, error)

func (*MappedEvolvableSubstrateLayout) BiasCount

func (m *MappedEvolvableSubstrateLayout) BiasCount() int

func (*MappedEvolvableSubstrateLayout) HiddenCount

func (m *MappedEvolvableSubstrateLayout) HiddenCount() int

func (*MappedEvolvableSubstrateLayout) IndexOfHidden

func (m *MappedEvolvableSubstrateLayout) IndexOfHidden(position *PointF) int

func (*MappedEvolvableSubstrateLayout) InputCount

func (m *MappedEvolvableSubstrateLayout) InputCount() int

func (*MappedEvolvableSubstrateLayout) NodePosition

func (m *MappedEvolvableSubstrateLayout) NodePosition(index int, nType network.NodeNeuronType) (*PointF, error)

func (*MappedEvolvableSubstrateLayout) OutputCount

func (m *MappedEvolvableSubstrateLayout) OutputCount() int

func (*MappedEvolvableSubstrateLayout) String

type PointF

type PointF struct {
	X, Y, Z float64
}

PointF Defines point with float precision coordinates

func NewPointF

func NewPointF(x, y float64) *PointF

func (*PointF) String

func (p *PointF) String() string

type QuadNode

type QuadNode struct {
	// The coordinates of the center of this quad-tree node's square
	X, Y, Z float64
	// The width of this quad-tree node's square
	Width float64
	// The height of this quad-tree node's square
	Height float64

	// The CPPN outputs for this node
	CppnOut []float64
	// The level of this node in the quad-tree
	Level int

	// The children of this node
	Nodes []*QuadNode
}

QuadNode Defines quad-tree node to model 4 dimensional hypercube

func NewQuadNode

func NewQuadNode(x, y, width, height float64, level int) *QuadNode

NewQuadNode Creates a new quad-node with given parameters

func NewQuadNodeZ

func NewQuadNodeZ(x, y, z, width, height float64, level int) *QuadNode

NewQuadNodeZ Creates a new quad-node with given parameters with Z coordinate value

func (*QuadNode) HasLeo

func (q *QuadNode) HasLeo() bool

func (*QuadNode) Leo

func (q *QuadNode) Leo() float64

func (*QuadNode) String

func (q *QuadNode) String() string

func (*QuadNode) Weight

func (q *QuadNode) Weight() float64

type QuadPoint

type QuadPoint struct {
	// The associated coordinates
	X1, X2, Y1, Y2, Z1, Z2 float64
	// Weight
	Weight float64
	// Leo
	Leo float64
}

QuadPoint Defines the quad-point in the 6-dimensional hypercube

func NewQuadPoint

func NewQuadPoint(x1, y1, z1, x2, y2, z2 float64, node *QuadNode) *QuadPoint

NewQuadPoint Creates new quad point

func (*QuadPoint) String

func (q *QuadPoint) String() string

type Substrate

type Substrate struct {
	// Layout The layout of neuron nodes in this substrate
	Layout SubstrateLayout

	// HiddenNodesActivation The activation function's type for neurons encoded
	HiddenNodesActivation neatmath.NodeActivationType
	// OutputNodesActivation The activation function type for output neurons encoded
	OutputNodesActivation neatmath.NodeActivationType
}

Substrate represents a substrate that holds configuration of ANN with weights produced by CPPN. According to the HyperNEAT method, the ANN neurons are encoded as coordinates in the hypercube presented by this substrate. By default, neurons will be placed into substrate within the grid layout.

func NewSubstrate

func NewSubstrate(layout SubstrateLayout, hiddenNodesActivation, outputNodesActivation neatmath.NodeActivationType) *Substrate

NewSubstrate creates a new instance of substrate.

func (*Substrate) CreateNetworkSolver

func (s *Substrate) CreateNetworkSolver(cppn network.Solver, useLeo bool, graphBuilder SubstrateGraphBuilder, options *hyperneat.Options) (network.Solver, error)

CreateNetworkSolver creates a network solver based on the current substrate layout and provided Compositional Pattern Producing Network, which used to define connections between network nodes. Optional graph_builder can be provided to collect graph nodes and edges of the created network solver. With graph builder it is possible to save/load network configuration as well as visualize it. If the useLeo is True, thar Link Expression Output extension to the HyperNEAT will be used instead of the standard weight threshold technique of HyperNEAT to determine whether to express a link between two nodes or not. With LEO the link is expressed based on the value of additional output of the CPPN (if > 0 then expressed)

type SubstrateGraphBuilder

type SubstrateGraphBuilder interface {
	// AddNode Adds the specified node to the graph with the provided position
	AddNode(nodeId int, nodeNeuronType network.NodeNeuronType, nodeActivation math.NodeActivationType, position *PointF) error
	// AddWeightedEdge Adds edge between two graph nodes
	AddWeightedEdge(sourceId, targetId int, weight float64) error

	// NodesCount Returns the number of nodes in the graph
	NodesCount() (int, error)
	// EdgesCount Returns the number of edges in the graph
	EdgesCount() (int, error)

	// Marshal the graph to the provided writer
	Marshal(w io.Writer) error
	// UnMarshal is to unmarshal the graph from the provided reader
	UnMarshal(r io.Reader) error
}

SubstrateGraphBuilder The graph builder able to build weighted directed graphs representing substrate networks

func NewSubstrateGraphMLBuilder

func NewSubstrateGraphMLBuilder(description string, compact bool) SubstrateGraphBuilder

NewSubstrateGraphMLBuilder Creates new instance with specified description to be included in the serialized graph. If compact is true, then the graph will be marshaled into compact form

type SubstrateLayout

type SubstrateLayout interface {
	// NodePosition Returns coordinates of the neuron with specified index [0; count) and type
	NodePosition(index int, nType network.NodeNeuronType) (*PointF, error)

	// BiasCount Returns the number of BIAS neurons in the layout
	BiasCount() int
	// InputCount Returns the number of INPUT neurons in the layout
	InputCount() int
	// HiddenCount Returns the number of HIDDEN neurons in the layout
	HiddenCount() int
	// OutputCount Returns the number of OUTPUT neurons in the layout
	OutputCount() int
}

SubstrateLayout Defines the layout of neurons in the substrate

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL