cppn

package
v0.0.0-...-8d87d8f Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

The 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 ReadCPPNfromGenomeFile

func ReadCPPNfromGenomeFile(genomePath string) (network.NetworkSolver, error)

Reads CPPN from specified genome and creates network solver

Types

type EvolvableSubstrate

type EvolvableSubstrate struct {
	// The layout of neuron nodes in this substrate
	Layout EvolvableSubstrateLayout
	// The activation function's type for neurons encoded
	NodesActivation utils.NodeActivationType
	// contains filtered or unexported fields
}

The evolvable substrate holds configuration of ANN produced by CPPN within hypecube 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 nodes locations may be arbitrary that suits the best for the task at hand.

func NewEvolvableSubstrate

func NewEvolvableSubstrate(layout EvolvableSubstrateLayout, nodesActivation utils.NodeActivationType) *EvolvableSubstrate

Creates new instance of evolvable substrate

func (*EvolvableSubstrate) CreateNetworkSolver

func (es *EvolvableSubstrate) CreateNetworkSolver(cppn network.NetworkSolver, graphBuilder GraphBuilder, context *eshyperneat.ESHyperNEATContext) (network.NetworkSolver, error)

Creates network solver based on 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 created network solver. With graph builder it is possible to save/load network configuration as well as visualize it.

type EvolvableSubstrateLayout

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

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

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

Defines layout of neurons in the substrate

type GraphBuilder

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

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

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

type GraphMLBuilder

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

The graph builder based on GraphML specification

func NewGraphMLBuilder

func NewGraphMLBuilder(description string, compact bool) *GraphMLBuilder

Creates new instance with specified description to be included into serialized graph. If compact is true than graph will be marshaled into compact form

func (*GraphMLBuilder) AddNode

func (gml *GraphMLBuilder) AddNode(nodeId int, nodeNeuronType network.NodeNeuronType, nodeActivation utils.NodeActivationType, position *PointF) (err error)

func (*GraphMLBuilder) AddWeightedEdge

func (gml *GraphMLBuilder) AddWeightedEdge(sourceId, targetId int, weight float64) (err error)

func (*GraphMLBuilder) Marshal

func (gml *GraphMLBuilder) Marshal(w io.Writer) error

func (*GraphMLBuilder) UnMarshal

func (gml *GraphMLBuilder) UnMarshal(r io.Reader) error

type GridSubstrateLayout

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

Defines grid substrate layout

func NewGridSubstrateLayout

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

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
}

The EvolvableSubstrateLayout implementation using map for binding between hidden node and its index

func NewMappedEvolvableSubstrateLayout

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

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 float64
}

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 center of this quad-tree node's square
	X, Y float64
	// The width of this quad-tree node's square
	Width float64

	// The CPPN activation level for this node
	W float64
	// The level of this node in the quad-tree
	Level int

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

Defines quad-tree node to model 4 dimensional hypercube

func NewQuadNode

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

Creates new quad-node with given parameters

func (*QuadNode) String

func (q *QuadNode) String() string

type QuadPoint

type QuadPoint struct {
	// The associated coordinates
	X1, X2, Y1, Y2 float64
	// The value for this point
	Value float64
}

Defines the quad-point in the 4 dimensional hypercube

func NewQuadPoint

func NewQuadPoint(x1, y1, x2, y2, value float64) *QuadPoint

Creates new quad point

func (*QuadPoint) String

func (q *QuadPoint) String() string

type Substrate

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

	// The activation function's type for neurons encoded
	NodesActivation utils.NodeActivationType
}

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

func NewSubstrate

func NewSubstrate(layout SubstrateLayout, nodesActivation utils.NodeActivationType) *Substrate

Creates new instance

func (*Substrate) CreateNetworkSolver

func (s *Substrate) CreateNetworkSolver(cppn network.NetworkSolver, use_leo bool, graph_builder GraphBuilder, context *hyperneat.HyperNEATContext) (network.NetworkSolver, error)

Creates network solver based on 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 created network solver. With graph builder it is possible to save/load network configuration as well as visualize it. If use_leo is True thar Link Expression Output extension to the HyperNEAT will be used instead of standard weight threshold technique of HyperNEAT to determine whether to express link between two nodes or not. With LEO the link expressed based on value of additional output of the CPPN (if > 0 then expressed)

type SubstrateLayout

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

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

Defines layout of neurons in the substrate

Jump to

Keyboard shortcuts

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