Nano Brain for Unity v0.1
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | Properties | List of all members
Neuron Class Reference

Description

A neuron is a basic Nucleus.

A neuron combines the weighted input from other neurons and applies an activation function to it to compute the output value:

Vector3 combination = NanoBrain::Neuron::Combinator(bias, synapses);
Vector3 output = NanoBrain::Neuron::Activator(combination);
float3 Combinator(float3 bias, List< Synapse > synapses)
The combinator which combines the bias with the values from all synapses.
Definition Neuron.cs:341
float3 Activator(float3 inputValue)
Apply the activation function to the input.
Definition Neuron.cs:441

The synapses are connections to other neurons. Each connection has a weight which is used to multiply the output of that other neuron before it is used by the combinator.

Inheritance diagram for Neuron:
Nucleus MemoryCell

Public Types

enum  CombinatorType { Sum , Product }
 The type of combinators. More...
 
enum  ActivationType {
  Linear , Power , Sqrt , Reciprocal ,
  Tanh , Binary , Normalized , Custom
}
 The type of.
 
enum  Type { None , Neuron , MemoryCell , Cluster }
 The types of Nucleus.
 

Public Member Functions

 Neuron (Cluster parent, string name)
 Create a new Neuron in a Cluster instance.
 
Synapse AddSynapse (Neuron sendingNucleus, float weight=1)
 Add a new synapse to this nuclues.
 
Synapse GetSynapse (Nucleus sender)
 Find a synapse.
 
void RemoveSynapse (Nucleus sendingNucleus)
 Remove a synapse from a Nucleus.
 
virtual void SetBias (Vector3 inputValue)
 Set the bias, recalculate the output and update all Nuclei receiving from this Nucleus.
 
void SleepCheck ()
 Check if the neuron is sleeping.
 
override Nucleus ShallowCloneTo (Cluster parent)
 Function to make a partial clone of this nucleus.
 
override void UpdateStateIsolated ()
 Update the state without updating other Nuclei.
 
virtual void AddReceiver (Nucleus receiverToAdd, float weight=1)
 Add a new receiver to this neuron.
 
virtual void RemoveReceiver (Nucleus receiverToRemove)
 Remove a receiver to this neuron.
 
virtual void ProcessStimulus (Vector3 inputValue)
 Process an external stimulus.
 

Static Public Member Functions

static void Delete (Nucleus nucleus)
 Delete the give neuron.
 
static float3 CombinatorSum (float3 bias, List< Synapse > synapses)
 Sum the bias and synpase outputs together.
 
static float3 CombinatorProduct (float3 bias, List< Synapse > synapses)
 Multiply the synapse outputs together.
 
static Vector3 CombinatorSum (Vector3 bias, List< Synapse > synapses)
 Sum the bias and synpase outputs together.
 
static Vector3 CombinatorProduct (Vector3 bias, List< Synapse > synapses)
 Multiply the synapse outputs together.
 

Public Attributes

Vector3 bias = Vector3.zero
 The bias.
 
CombinatorType combinator = CombinatorType.Sum
 The type of combinator used for this Neuron.
 
ActivationType _activator
 The activation function.
 
Action WhenFiring
 An action which is called every time the neuron is updated and is firing.
 
bool persistOutput = false
 When true, the value will not be reset after timeToSleep.
 
float lastUpdate = 0
 The time at which the last update has been done.
 
bool breakOnUpdate = false
 When true, Unity will pause exection when this neuron is updated.
 
string name
 The name of the Nucleus.
 
Cluster parent
 The cluster instance in which the nucleus is located.
 

Static Public Attributes

static readonly float timeToSleep = 0.5f
 Time in seconds after the last update the neuron can go to sleep.
 

Protected Member Functions

virtual void CloneFields (Neuron clone)
 Copy relevant fields of this neuron to the given neuron.
 
float3 Combinator (float3 bias, List< Synapse > synapses)
 The combinator which combines the bias with the values from all synapses.
 
Vector3 Combinator (Vector3 bias, List< Synapse > synapses)
 The combinator which combines the bias with the values from all synapses.
 
float3 Activator (float3 inputValue)
 Apply the activation function to the input.
 
float3 ActivatorLinear (float3 input)
 Linear activation function.
 
float3 ActivatorSqrt (float3 input)
 Square root activation function.
 
float3 ActivatorPower (float3 input)
 Power activation function.
 
float3 ActivatorReciprocal (float3 input)
 Reciprocal activation function.
 
float3 ActivatorTanh (float3 input)
 Tanh activation function.
 
float3 ActivatorBinary (float3 input)
 Binary activation function.
 
float3 ActivatorNormalized (float3 input)
 Normalize activation function.
 
Vector3 Activator (Vector3 inputValue)
 Apply the activation function to the input.
 
Vector3 ActivatorLinear (Vector3 input)
 Linear activation function.
 
Vector3 ActivatorSqrt (Vector3 input)
 Square root activation function.
 
Vector3 ActivatorPower (Vector3 input)
 Power activation function.
 
Vector3 ActivatorReciprocal (Vector3 input)
 Reciprocal activation function.
 

Protected Attributes

float3 _outputValue
 The output value of the neuron.
 
Vector3 _outputValue
 The output value of the neuron.
 

Properties

List< Synapsesynapses [get]
 The synapses of the nucleus.
 
ActivationType activator [get, set]
 The activation funtion.
 
virtual float3 outputValue [get, set]
 The output value of the neuron.
 
float outputMagnitude [get]
 The magnitude of the neuron output.
 
float outputSqrMagnitude [get]
 The squared magnitude of the neuron output.
 
virtual Vector3 outputValue [get, set]
 The output value of the neuron.
 
bool isFiring [get]
 True if the neuron have a positive value with magnitude > 0.5.
 
virtual bool isSleeping [get]
 True when the neuron is not persisting and has not be updated for timeToSleep seconds.
 
virtual List< Nucleusreceivers [get, set]
 The nuclei which have a synapse to this neuron.
 

Member Enumeration Documentation

◆ CombinatorType

The type of combinators.

A combinator combines the weighted values of the synapses to a single value

Enumerator
Sum 

Add the weighted values together.

Product 

Multiply the weighted values.

Constructor & Destructor Documentation

◆ Neuron()

Neuron ( Cluster  parent,
string  name 
)

Create a new Neuron in a Cluster instance.

Parameters
parentThe parent cluster in which the new Neuron should be created
nameThe name of the new Neuron

Member Function Documentation

◆ AddSynapse()

Synapse AddSynapse ( Neuron  sendingNucleus,
float  weight = 1 
)

Add a new synapse to this nuclues.

Parameters
sendingNucleusThe nucleus from which the signals may originate
weightThe weight applied to the input. Default value = 1
Returns
The created Synapse

This will add a new input to this nucleus with the given weight.

◆ GetSynapse()

Synapse GetSynapse ( Nucleus  sender)

Find a synapse.

Parameters
senderThe sender of the input to the Synapse
Returns
The found Synapse or null when the sender has no synapse to this nucleus.

◆ RemoveSynapse()

void RemoveSynapse ( Nucleus  sendingNucleus)

Remove a synapse from a Nucleus.

Parameters
sendingNucleusRemote the synapse connecting to this Nucleus

◆ SetBias()

virtual void SetBias ( Vector3  inputValue)
virtual

Set the bias, recalculate the output and update all Nuclei receiving from this Nucleus.

Parameters
inputValue

◆ SleepCheck()

void SleepCheck ( )

Check if the neuron is sleeping.

This will reset the output value if it is sleeping

◆ ShallowCloneTo()

override Nucleus ShallowCloneTo ( Cluster  parent)

Function to make a partial clone of this nucleus.

Parameters
parentThe cluster in which the cloned nucleus should be placed
Returns

◆ CloneFields()

virtual void CloneFields ( Neuron  clone)
protectedvirtual

Copy relevant fields of this neuron to the given neuron.

Parameters
clone

◆ Delete()

static void Delete ( Nucleus  nucleus)
static

Delete the give neuron.

Parameters
nucleusThe neuron to delete

◆ UpdateStateIsolated()

override void UpdateStateIsolated ( )

Update the state without updating other Nuclei.

◆ Combinator() [1/2]

float3 Combinator ( float3  bias,
List< Synapse synapses 
)
protected

The combinator which combines the bias with the values from all synapses.

Parameters
biasThe bias of the neuron
synapsesThe synapses of the neuron
Returns

◆ CombinatorSum() [1/2]

static float3 CombinatorSum ( float3  bias,
List< Synapse synapses 
)
static

Sum the bias and synpase outputs together.

Parameters
biasThe bias of the neuron
synapsesThe synapses of the neuron
Returns

◆ CombinatorProduct() [1/2]

static float3 CombinatorProduct ( float3  bias,
List< Synapse synapses 
)
static

Multiply the synapse outputs together.

Parameters
biasThe bias of the neuron
synapsesThe synapses of the neuron
Returns
The result of the multiplication

◆ Combinator() [2/2]

Vector3 Combinator ( Vector3  bias,
List< Synapse synapses 
)
protected

The combinator which combines the bias with the values from all synapses.

Parameters
biasThe bias of the neuron
synapsesThe synapses of the neuron
Returns

◆ CombinatorSum() [2/2]

static Vector3 CombinatorSum ( Vector3  bias,
List< Synapse synapses 
)
static

Sum the bias and synpase outputs together.

Parameters
biasThe bias of the neuron
synapsesThe synapses of the neuron
Returns

◆ CombinatorProduct() [2/2]

static Vector3 CombinatorProduct ( Vector3  bias,
List< Synapse synapses 
)
static

Multiply the synapse outputs together.

Parameters
biasThe bias of the neuron
synapsesThe synapses of the neuron
Returns
The result of the multiplication

◆ Activator() [1/2]

float3 Activator ( float3  inputValue)
protected

Apply the activation function to the input.

Parameters
inputValue
Returns
The result of applying the activation function

◆ ActivatorLinear() [1/2]

float3 ActivatorLinear ( float3  input)
protected

Linear activation function.

Parameters
inputInput value
Returns
The unchanged value

◆ ActivatorSqrt() [1/2]

float3 ActivatorSqrt ( float3  input)
protected

Square root activation function.

Parameters
inputInput value
Returns
The square root of the input

◆ ActivatorPower() [1/2]

float3 ActivatorPower ( float3  input)
protected

Power activation function.

Parameters
inputInput value
Returns
The input to the power of 2

◆ ActivatorReciprocal() [1/2]

float3 ActivatorReciprocal ( float3  input)
protected

Reciprocal activation function.

Parameters
inputInput value
Returns
1/input value

◆ ActivatorTanh()

float3 ActivatorTanh ( float3  input)
protected

Tanh activation function.

Parameters
inputInput value
Returns
Tanh(input value)

◆ ActivatorBinary()

float3 ActivatorBinary ( float3  input)
protected

Binary activation function.

Parameters
inputInput value
Returns
An uniform vector with magnitude between 0 and 1

◆ ActivatorNormalized()

float3 ActivatorNormalized ( float3  input)
protected

Normalize activation function.

Parameters
inputInput value
Returns
The normalized vector

◆ Activator() [2/2]

Vector3 Activator ( Vector3  inputValue)
protected

Apply the activation function to the input.

Parameters
inputValue
Returns
The result of applying the activation function

◆ ActivatorLinear() [2/2]

Vector3 ActivatorLinear ( Vector3  input)
protected

Linear activation function.

Parameters
inputInput value
Returns
The unchanged value

◆ ActivatorSqrt() [2/2]

Vector3 ActivatorSqrt ( Vector3  input)
protected

Square root activation function.

Parameters
inputInput value
Returns
The square root of the input

◆ ActivatorPower() [2/2]

Vector3 ActivatorPower ( Vector3  input)
protected

Power activation function.

Parameters
inputInput value
Returns
The input to the power of 2

◆ ActivatorReciprocal() [2/2]

Vector3 ActivatorReciprocal ( Vector3  input)
protected

Reciprocal activation function.

Parameters
inputInput value
Returns
1/input value

◆ AddReceiver()

virtual void AddReceiver ( Nucleus  receiverToAdd,
float  weight = 1 
)
virtual

Add a new receiver to this neuron.

Parameters
receiverToAddThe receiver to add
weightThe weight to use for the synapse to his neuron

◆ RemoveReceiver()

virtual void RemoveReceiver ( Nucleus  receiverToRemove)
virtual

Remove a receiver to this neuron.

Parameters
receiverToRemoveThe receiver to remove

◆ ProcessStimulus()

virtual void ProcessStimulus ( Vector3  inputValue)
virtual

Process an external stimulus.

Parameters
inputValueThe value of the stimulus

Member Data Documentation

◆ bias

Vector3 bias = Vector3.zero

The bias.

The bias which a value which is always added to the combined value of the neuron It does not have a synapse and therefore no weight of source nucleus

◆ breakOnUpdate

bool breakOnUpdate = false

When true, Unity will pause exection when this neuron is updated.

Pausing is implemented using Debug.Break()