Documentation ¶
Index ¶
- Constants
- func Average(xs []float64) float64
- func EqualsWithMaxDelta(x, y, maxDelta float64) bool
- func FixedWeights(length int, weight float64) []float64
- func Identity(x float64) float64
- func IntModuloProper(x, y int) bool
- func JsonString(v interface{}) string
- func NewUuid() string
- func NormalizeInRange(params NormalizeParams, value float64) float64
- func RandomBias() float64
- func RandomInRange(min, max float64) float64
- func RandomIntInRange(min, max int) int
- func RandomWeight() float64
- func RandomWeights(length int) []float64
- func SafeScalarInverse(x float64) float64
- func Saturate(parameter, lowerBound, upperBound float64) float64
- func SeedRandom()
- func Sigmoid(x float64) float64
- func SumOfSquaresError(expected []float64, actual []float64) float64
- func VectorEquals(xValues, yValues []float64) bool
- func WriteStringToFile(value string, filepath string) error
- type ActivationFunction
- type Actuator
- func (actuator *Actuator) CanAddInboundConnection() bool
- func (actuator *Actuator) ConnectInbound(connectable InboundConnectable) *InboundConnection
- func (actuator *Actuator) Init()
- func (actuator *Actuator) MarshalJSON() ([]byte, error)
- func (actuator *Actuator) Run()
- func (actuator *Actuator) Shutdown()
- func (actuator *Actuator) String() string
- type ActuatorBarrier
- type ActuatorFunction
- type Cortex
- func BasicCortex() *Cortex
- func NewCortexFromJSONFile(filename string) (cortex *Cortex, err error)
- func NewCortexFromJSONSBytes(jsonBytes []byte) (cortex *Cortex, err error)
- func NewCortexFromJSONString(jsonString string) (cortex *Cortex, err error)
- func XnorCortex() *Cortex
- func XnorCortexUntrained() *Cortex
- func (cortex *Cortex) ActuatorNodeIds() []*NodeId
- func (cortex *Cortex) AllNodeIds() []*NodeId
- func (cortex *Cortex) Copy() *Cortex
- func (cortex *Cortex) CreateNeuronInLayer(layerIndex float64) *Neuron
- func (cortex *Cortex) ExtraCompact() string
- func (cortex *Cortex) FindActuator(nodeId *NodeId) *Actuator
- func (cortex *Cortex) FindConnector(nodeId *NodeId) OutboundConnector
- func (cortex *Cortex) FindInboundConnector(nodeId *NodeId) InboundConnector
- func (cortex *Cortex) FindNeuron(nodeId *NodeId) *Neuron
- func (cortex *Cortex) FindSensor(nodeId *NodeId) *Sensor
- func (cortex *Cortex) Fitness(samples []*TrainingSample) float64
- func (cortex *Cortex) Init()
- func (cortex *Cortex) InitOutboundConnections()
- func (cortex *Cortex) LinkNodesToCortex()
- func (cortex *Cortex) MarshalJSON() ([]byte, error)
- func (cortex *Cortex) MarshalJSONToFile(filename string) error
- func (cortex *Cortex) NeuronLayerMap() LayerToNeuronMap
- func (cortex *Cortex) NeuronNodeIds() []*NodeId
- func (cortex *Cortex) NeuronUUIDMap() UUIDToNeuronMap
- func (cortex *Cortex) NodeIdLayerMap() LayerToNodeIdMap
- func (cortex *Cortex) RenderSVG(writer io.Writer)
- func (cortex *Cortex) RenderSVGFile(filename string)
- func (cortex *Cortex) Repair()
- func (cortex *Cortex) Run()
- func (cortex *Cortex) SensorNodeIds() []*NodeId
- func (cortex *Cortex) SetActuators(actuators []*Actuator)
- func (cortex *Cortex) SetNeurons(neurons []*Neuron)
- func (cortex *Cortex) SetSensors(sensors []*Sensor)
- func (cortex *Cortex) Shutdown()
- func (cortex *Cortex) String() string
- func (cortex *Cortex) StringCompact() string
- func (cortex *Cortex) SyncActuators()
- func (cortex *Cortex) SyncSensors()
- func (cortex *Cortex) Validate() bool
- func (cortex *Cortex) Verify(samples []*TrainingSample) bool
- type DataMessage
- type Disconnectable
- type EncodableActivation
- type InboundConnectable
- type InboundConnection
- func ConnectInbound(connector InboundConnector, connectable InboundConnectable) *InboundConnection
- func ConnectInboundWeighted(connector InboundConnector, connectable InboundConnectable, weights []float64) *InboundConnection
- func DisconnectInbound(connector InboundConnector, connectable Disconnectable) *InboundConnection
- type InboundConnector
- type LayerToNeuronMap
- type LayerToNodeIdMap
- func (l LayerToNodeIdMap) ChooseNodeIdFollowingLayer(layerIndex float64) *NodeId
- func (l LayerToNodeIdMap) ChooseNodeIdPrecedingLayer(layerIndex float64) *NodeId
- func (layerToNodeIdMap LayerToNodeIdMap) ChooseRandomLayer() float64
- func (l LayerToNodeIdMap) IntegerIndexOf(layer float64) int
- func (layerToNodeIdMap LayerToNodeIdMap) Keys() []float64
- func (l LayerToNodeIdMap) LayerBetweenOrNew(initial, final float64) float64
- func (l LayerToNodeIdMap) LayerOfIntegerIndex(layerInteger int) float64
- func (l LayerToNodeIdMap) LayersAdjacent(initial, final float64) bool
- func (l LayerToNodeIdMap) NewLayerBetween(initial, final float64) float64
- type Neuron
- func (neuron *Neuron) ConnectInboundWeighted(connectable InboundConnectable, weights []float64) *InboundConnection
- func (neuron *Neuron) ConnectOutbound(connectable OutboundConnectable) *OutboundConnection
- func (neuron *Neuron) Copy() *Neuron
- func (neuron *Neuron) InboundUUIDMap() UUIDToInboundConnection
- func (neuron *Neuron) Init()
- func (neuron *Neuron) IsConnectionRecurrent(connection *OutboundConnection) bool
- func (neuron *Neuron) IsInboundConnectionRecurrent(connection *InboundConnection) bool
- func (neuron *Neuron) MarshalJSON() ([]byte, error)
- func (neuron *Neuron) RecurrentInboundConnections() []*InboundConnection
- func (neuron *Neuron) RecurrentOutboundConnections() []*OutboundConnection
- func (neuron *Neuron) Run()
- func (neuron *Neuron) Shutdown()
- func (neuron *Neuron) String() string
- type NodeCircleSVG
- type NodeId
- type NodeType
- type NodeUUIDToCircleSVG
- type NormalizeParams
- type OutboundConnectable
- type OutboundConnection
- type OutboundConnector
- type Point
- type Sensor
- type SensorFunction
- type Trainer
- type TrainingSample
- type UUIDToInboundConnection
- type UUIDToNeuronMap
Constants ¶
const ( SENSOR = "SENSOR" NEURON = "NEURON" ACTUATOR = "ACTUATOR" CORTEX = "CORTEX" )
const FITNESS_THRESHOLD = 1e8
Variables ¶
This section is empty.
Functions ¶
func EqualsWithMaxDelta ¶
func FixedWeights ¶
func IntModuloProper ¶
func JsonString ¶
func JsonString(v interface{}) string
func NormalizeInRange ¶
func NormalizeInRange(params NormalizeParams, value float64) float64
func RandomBias ¶
func RandomBias() float64
func RandomInRange ¶
func RandomIntInRange ¶
return a random number between min and max - 1 eg, if you call it with 0,1 it will always return 0 if you call it between 0,2 it will return 0 or 1
func RandomWeight ¶
func RandomWeight() float64
func RandomWeights ¶
func SafeScalarInverse ¶
func SeedRandom ¶
func SeedRandom()
func SumOfSquaresError ¶
func VectorEquals ¶
func WriteStringToFile ¶
Types ¶
type ActivationFunction ¶
type Actuator ¶
type Actuator struct { NodeId *NodeId Inbound []*InboundConnection Closing chan chan bool DataChan chan *DataMessage VectorLength int ActuatorFunction ActuatorFunction Cortex *Cortex // contains filtered or unexported fields }
func (*Actuator) CanAddInboundConnection ¶
func (*Actuator) ConnectInbound ¶
func (actuator *Actuator) ConnectInbound(connectable InboundConnectable) *InboundConnection
func (*Actuator) MarshalJSON ¶
type ActuatorBarrier ¶
type ActuatorFunction ¶
type ActuatorFunction func(outputs []float64)
type Cortex ¶
type Cortex struct { NodeId *NodeId Sensors []*Sensor Neurons []*Neuron Actuators []*Actuator SyncChan chan *NodeId // TODO: rename to ActuatorBarrier }
func BasicCortex ¶
func BasicCortex() *Cortex
func NewCortexFromJSONFile ¶
TODO: rename to have "unmarshal" in the name
func NewCortexFromJSONSBytes ¶
func NewCortexFromJSONString ¶
func XnorCortex ¶
func XnorCortex() *Cortex
func XnorCortexUntrained ¶
func XnorCortexUntrained() *Cortex
func (*Cortex) ActuatorNodeIds ¶
func (*Cortex) AllNodeIds ¶
func (*Cortex) CreateNeuronInLayer ¶
func (*Cortex) ExtraCompact ¶
func (*Cortex) FindActuator ¶
func (*Cortex) FindConnector ¶
func (cortex *Cortex) FindConnector(nodeId *NodeId) OutboundConnector
TODO: rename to FindOutboundConnector
func (*Cortex) FindInboundConnector ¶
func (cortex *Cortex) FindInboundConnector(nodeId *NodeId) InboundConnector
func (*Cortex) FindNeuron ¶
func (*Cortex) FindSensor ¶
func (*Cortex) Fitness ¶
func (cortex *Cortex) Fitness(samples []*TrainingSample) float64
func (*Cortex) InitOutboundConnections ¶
func (cortex *Cortex) InitOutboundConnections()
We may be in a state where the outbound connections do not have data channels associated with them, even though the data channels exist. (eg, when deserializing from json). Fix this by seeking out those outbound connections and setting the data channels.
func (*Cortex) LinkNodesToCortex ¶
func (cortex *Cortex) LinkNodesToCortex()
func (*Cortex) MarshalJSON ¶
func (*Cortex) MarshalJSONToFile ¶
func (*Cortex) NeuronLayerMap ¶
func (cortex *Cortex) NeuronLayerMap() LayerToNeuronMap
func (*Cortex) NeuronNodeIds ¶
func (*Cortex) NeuronUUIDMap ¶
func (cortex *Cortex) NeuronUUIDMap() UUIDToNeuronMap
func (*Cortex) NodeIdLayerMap ¶
func (cortex *Cortex) NodeIdLayerMap() LayerToNodeIdMap
func (*Cortex) RenderSVGFile ¶
func (*Cortex) SensorNodeIds ¶
func (*Cortex) SetActuators ¶
func (*Cortex) SetNeurons ¶
func (*Cortex) SetSensors ¶
func (*Cortex) StringCompact ¶
func (*Cortex) SyncActuators ¶
func (cortex *Cortex) SyncActuators()
func (*Cortex) SyncSensors ¶
func (cortex *Cortex) SyncSensors()
func (*Cortex) Verify ¶
func (cortex *Cortex) Verify(samples []*TrainingSample) bool
type DataMessage ¶
func (*DataMessage) String ¶
func (dataMessage *DataMessage) String() string
type Disconnectable ¶
type Disconnectable interface {
// contains filtered or unexported methods
}
type EncodableActivation ¶
type EncodableActivation struct { Name string ActivationFunction ActivationFunction }
func AllEncodableActivations ¶
func AllEncodableActivations() []*EncodableActivation
func EncodableIdentity ¶
func EncodableIdentity() *EncodableActivation
func EncodableSigmoid ¶
func EncodableSigmoid() *EncodableActivation
func EncodableTanh ¶
func EncodableTanh() *EncodableActivation
func RandomEncodableActivation ¶
func RandomEncodableActivation() *EncodableActivation
func (*EncodableActivation) MarshalJSON ¶
func (activation *EncodableActivation) MarshalJSON() ([]byte, error)
func (*EncodableActivation) String ¶
func (activation *EncodableActivation) String() string
func (*EncodableActivation) UnmarshalJSON ¶
func (activation *EncodableActivation) UnmarshalJSON(bytes []byte) error
type InboundConnectable ¶
type InboundConnectable interface {
// contains filtered or unexported methods
}
type InboundConnection ¶
func ConnectInbound ¶
func ConnectInbound(connector InboundConnector, connectable InboundConnectable) *InboundConnection
func ConnectInboundWeighted ¶
func ConnectInboundWeighted(connector InboundConnector, connectable InboundConnectable, weights []float64) *InboundConnection
func DisconnectInbound ¶
func DisconnectInbound(connector InboundConnector, connectable Disconnectable) *InboundConnection
func (*InboundConnection) MarshalJSON ¶
func (connection *InboundConnection) MarshalJSON() ([]byte, error)
func (*InboundConnection) String ¶
func (connection *InboundConnection) String() string
type InboundConnector ¶
type InboundConnector interface {
// contains filtered or unexported methods
}
type LayerToNeuronMap ¶
LayerToNeuronMap ..
func (LayerToNeuronMap) ChooseRandomLayer ¶
func (layerToNeuronMap LayerToNeuronMap) ChooseRandomLayer() float64
func (LayerToNeuronMap) Keys ¶
func (layerToNeuronMap LayerToNeuronMap) Keys() []float64
type LayerToNodeIdMap ¶
func (LayerToNodeIdMap) ChooseNodeIdFollowingLayer ¶
func (l LayerToNodeIdMap) ChooseNodeIdFollowingLayer(layerIndex float64) *NodeId
func (LayerToNodeIdMap) ChooseNodeIdPrecedingLayer ¶
func (l LayerToNodeIdMap) ChooseNodeIdPrecedingLayer(layerIndex float64) *NodeId
func (LayerToNodeIdMap) ChooseRandomLayer ¶
func (layerToNodeIdMap LayerToNodeIdMap) ChooseRandomLayer() float64
func (LayerToNodeIdMap) IntegerIndexOf ¶
func (l LayerToNodeIdMap) IntegerIndexOf(layer float64) int
func (LayerToNodeIdMap) Keys ¶
func (layerToNodeIdMap LayerToNodeIdMap) Keys() []float64
func (LayerToNodeIdMap) LayerBetweenOrNew ¶
func (l LayerToNodeIdMap) LayerBetweenOrNew(initial, final float64) float64
func (LayerToNodeIdMap) LayerOfIntegerIndex ¶
func (l LayerToNodeIdMap) LayerOfIntegerIndex(layerInteger int) float64
func (LayerToNodeIdMap) LayersAdjacent ¶
func (l LayerToNodeIdMap) LayersAdjacent(initial, final float64) bool
func (LayerToNodeIdMap) NewLayerBetween ¶
func (l LayerToNodeIdMap) NewLayerBetween(initial, final float64) float64
type Neuron ¶
type Neuron struct { NodeId *NodeId Bias float64 Inbound []*InboundConnection Outbound []*OutboundConnection Closing chan chan bool DataChan chan *DataMessage ActivationFunction *EncodableActivation Cortex *Cortex // contains filtered or unexported fields }
func (*Neuron) ConnectInboundWeighted ¶
func (neuron *Neuron) ConnectInboundWeighted(connectable InboundConnectable, weights []float64) *InboundConnection
func (*Neuron) ConnectOutbound ¶
func (neuron *Neuron) ConnectOutbound(connectable OutboundConnectable) *OutboundConnection
func (*Neuron) InboundUUIDMap ¶
func (neuron *Neuron) InboundUUIDMap() UUIDToInboundConnection
func (*Neuron) IsConnectionRecurrent ¶
func (neuron *Neuron) IsConnectionRecurrent(connection *OutboundConnection) bool
a connection is considered recurrent if it has a connection to itself or to a node in a previous layer. Previous meaning if you look at a feedForward from left to right, with the input layer being on the far left, and output layer on the far right, then any layer to the left is considered previous.
func (*Neuron) IsInboundConnectionRecurrent ¶
func (neuron *Neuron) IsInboundConnectionRecurrent(connection *InboundConnection) bool
same as isConnectionRecurrent, but for inbound connections TODO: use interfaces to eliminate code duplication
func (*Neuron) MarshalJSON ¶
func (*Neuron) RecurrentInboundConnections ¶
func (neuron *Neuron) RecurrentInboundConnections() []*InboundConnection
func (*Neuron) RecurrentOutboundConnections ¶
func (neuron *Neuron) RecurrentOutboundConnections() []*OutboundConnection
Find the subset of outbound connections which are "recurrent" - meaning that the connection is to this neuron itself, or to a neuron in a previous (eg, to the left) layer.
type NodeCircleSVG ¶
type NodeCircleSVG struct { Point // contains filtered or unexported fields }
type NodeUUIDToCircleSVG ¶
type NodeUUIDToCircleSVG map[string]NodeCircleSVG
type NormalizeParams ¶
type OutboundConnectable ¶
type OutboundConnectable interface {
// contains filtered or unexported methods
}
type OutboundConnection ¶
type OutboundConnection struct { NodeId *NodeId DataChan chan *DataMessage }
func ConnectOutbound ¶
func ConnectOutbound(connector OutboundConnector, connectable OutboundConnectable) *OutboundConnection
func DisconnectOutbound ¶
func DisconnectOutbound(connector OutboundConnector, connectable Disconnectable) *OutboundConnection
func (*OutboundConnection) MarshalJSON ¶
func (connection *OutboundConnection) MarshalJSON() ([]byte, error)
func (*OutboundConnection) String ¶
func (connection *OutboundConnection) String() string
type OutboundConnector ¶
type OutboundConnector interface {
// contains filtered or unexported methods
}
type Sensor ¶
type Sensor struct { NodeId *NodeId Outbound []*OutboundConnection VectorLength int Closing chan chan bool SyncChan chan bool SensorFunction SensorFunction Cortex *Cortex // contains filtered or unexported fields }
func (*Sensor) ConnectOutbound ¶
func (s *Sensor) ConnectOutbound(connectable OutboundConnectable) *OutboundConnection
func (*Sensor) MarshalJSON ¶
type SensorFunction ¶
type Trainer ¶
type Trainer interface {
Train(cortex *Cortex, examples []*TrainingSample) *Cortex
}
type TrainingSample ¶
type TrainingSample struct { // for each sensor in the network, provide a sample input vector SampleInputs [][]float64 // for each actuator in the network, provide an expected output vector ExpectedOutputs [][]float64 }
func XnorTrainingSamples ¶
func XnorTrainingSamples() []*TrainingSample
func (*TrainingSample) String ¶
func (t *TrainingSample) String() string
type UUIDToInboundConnection ¶
type UUIDToInboundConnection map[string]*InboundConnection