brain

package
v0.0.0-...-309fd15 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2017 License: MIT Imports: 2 Imported by: 1

Documentation

Overview

Package brain provides a real-time neural net framework.

A real-time neural network implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AcceptInput

type AcceptInput interface {
	AddInputNode(input *Node)
}

AcceptInput defines the interface that creature inputs interact with to stimulate the brain. This is a simple interface that registers the input node.

type Brain

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

* The Brain is composed of inputs, central nodes, outputs and synapses. * They are arranged as such: * * inputNodes : o o o * inSynapses : \/ \/ * centralNodes : o o * outSynapses : /\ /\ * outputs :o o o o * * Charge flows from top to bottom in the diagram. * * Each tick, the input Nodes should be charged appropriately (by the external stimuli), * and then Update() called exactly once.

func NewBrain

func NewBrain(numCentralNodes int) *Brain

Returns a pointer to a new Brain with numCentralNodes central nodes. It will have no inputs, no outputs and no synapses.

func (*Brain) AddInputNode

func (b *Brain) AddInputNode(input *Node)

Adds an input node to the brain. Automatically connects it to all central nodes with synapses.

func (*Brain) AddOutput

func (b *Brain) AddOutput(output ChargedWorker)

Adds an output node to the brain. Automatically connects it to all central nodes with synapses.

func (*Brain) GenesNeeded

func (b *Brain) GenesNeeded() int

Start-of-day function fo querying how much genetic information is required for this brain.

func (*Brain) Restore

func (b *Brain) Restore(d *genetics.Dna)

Restore a brain using genetic information. This can only occur if the structure matches that of the information.

func (*Brain) Work

func (b *Brain) Work()

Updates all the nodes in the brain. Should be called exactly once per tick.

type BrainExternal

type BrainExternal interface {
	AcceptInput
	AddOutput(output ChargedWorker)
	Restore(d *genetics.Dna)
	GenesNeeded() int
	Work()
}

BrainExternal defines the high-level methods that creatures can use to interact with its' brain.

type ChargeCarrier

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

An abstract collection of electrical ChargeCarrier. Used to commonise code between different kinds of brain elements.

func (*ChargeCarrier) Charge

func (c *ChargeCarrier) Charge(strength float64)

ChargeCarrier up this ChargeCarrier by strength ChargeUnits.

func (*ChargeCarrier) Decay

func (c *ChargeCarrier) Decay()

Decreases this ChargeCarrier by chargeDecayRate. Should be called once per time-step.

type Chargeable

type Chargeable interface {
	Charge(strength float64)
}

Chargeable defines the family of objects that participate in a neural network. Objects that implement the chargable interface accept ChargeCarrier from other objects in the neural net.

type ChargedWorker

type ChargedWorker interface {
	Charge(strength float64)
	Work()
}

ChargedWorker combines the Chargeable and Worker interfaces. (is there a better way to do this?)

type Node

type Node struct {
	ChargeCarrier
	// contains filtered or unexported fields
}

func NewNode

func NewNode() *Node

Creates a new node with default values.

func (*Node) AddOutput

func (n *Node) AddOutput(out Chargeable)

Adds a new output to this node.

func (*Node) Fire

func (n *Node) Fire()

ChargeCarrier up all outputs by our firingStrength.

func (*Node) Work

func (n *Node) Work()

Work is where a Node does all it's processing. The Node should not affect anything outside itself anywhere EXCEPT in the Work method.

type Synapse

type Synapse struct {
	ChargeCarrier
	// contains filtered or unexported fields
}

A Synapse is a channel for transferring ChargeCarrier between brain elements. It has exactly one output, and should be pointed to by exactly one input. Unlike Nodes, Synapses do not distribute ChargeCarrier in bursts, they slowly convey ChargeCarrier to their output over time.

func NewSynapse

func NewSynapse(output Chargeable, permittivity float64) *Synapse

Creates a new Synapse which points at the given output.

func (*Synapse) Work

func (s *Synapse) Work()

Work should be called once per tick. When a Synapse does work, it convey's ChargeCarrier to it's output at a rate relative to the Synapse's currentCharge.

type Worker

type Worker interface {
	Work()
}

Worker defines the family of objects which can be added to the neural worker queue and are scheduled for later work. Objects that implement the worker interface perform actions only during a work process.

Jump to

Keyboard shortcuts

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