Nano Brain for Unity

AUTHOR
Version v0.1

Table of Contents

Table of contents

Nano Brain for Unity

Table of Contents

Installation 

Package Installation
You can import the NanoBrain Ant package in Unity directly with the Package Manager git package importer.
See Unity: Installing from a Git URL
Use the link from 'Clone with HTTP' (for example: https://git.passer.life/CreatureControl/Ant.git) In this way you can always retrieve the latest version by pressing the Update button in the Package Manager.
Optionally, you can use a tag to retrieve a specific version. For example: https://git.passer.life/CreatureControl/Ant.git#0.1.0. This will give you a stable version which does not change. Updating can be done by retrieving the package with a link to a new release.
Samples Installation
In the Unity Package manager, select the NanoBrain Ant package and look for the Samples  tab in the details pane on the right. There you can import the Models . 

NanoBrain
 Documentation is found in the Documentation folder 

Hierarchical Index
Class Hierarchy
This inheritance list is sorted roughly, but not completely, alphabetically:
ClusterPrefab	pagenum
Motor	pagenum
Nucleus	pagenum
Cluster	pagenum
Neuron	pagenum
MemoryCell	pagenum

Sensor	pagenum
LightSensor	pagenum
TouchSensor	pagenum

Synapse	pagenum
Vehicle	pagenum

Class Index
Class List
Here are the classes, structs, unions and interfaces with brief descriptions:
Cluster (A Cluster combines a collection of Nuclei to implement reusable behaviour ) 	pagenum
ClusterPrefab (The Unity ScriptableObject to implement re-usable Cluster Prefabs ) 	pagenum
LightSensor (A light sensor ) 	pagenum
MemoryCell (A MemoryCell stored its value for one update ) 	pagenum
Motor (A powered wheel collider, controlled by a NanoBrain::Neuron ) 	pagenum
Neuron (A neuron is a basic Nucleus ) 	pagenum
Nucleus (A Nucleus is a basic element in a brain cluster ) 	pagenum
Sensor (A non-directional sensor ) 	pagenum
Synapse (A Synapse connects the ouput of a Neuron to another Neuron ) 	pagenum
TouchSensor (A sensor which can detect contacts with static GameObjects or Rigidbodies ) 	pagenum
Vehicle (A Braitenberg style vehicle with two sensors and two motors, powered by a Nanobrain ) 	pagenum

Namespace Documentation
NanoBrain Namespace Reference

The Nanobrain namespace. 
Classes
class ClusterA Cluster combines a collection of Nuclei to implement reusable behaviour. 
class MemoryCellA MemoryCell stored its value for one update. 
class NeuronA neuron is a basic Nucleus. 
class NucleusA Nucleus is a basic element in a brain cluster. 
class SynapseA Synapse connects the ouput of a Neuron to another Neuron. 

Detailed Description
The Nanobrain namespace. 

NanoBrain.Unity Namespace Reference
Classes
class ClusterPrefabThe Unity ScriptableObject to implement re-usable Cluster Prefabs. 

NanoBrain.Unity.Braitenberg Namespace Reference
Classes
class LightSensorA light sensor. 
class MotorA powered wheel collider, controlled by a NanoBrain::Neuron. 
class SensorA non-directional sensor. 
class TouchSensorA sensor which can detect contacts with static GameObjects or Rigidbodies. 
class VehicleA Braitenberg style vehicle with two sensors and two motors, powered by a Nanobrain. 

Passer Namespace Reference

Class Documentation
Cluster Class Reference

Description
A Cluster combines a collection of Nuclei to implement reusable behaviour. 
A Cluster is an instantiation of a ClusterPrefab. Clusters can be nested inside other clusters. 
Inheritance diagram for Cluster:
IMAGE
Public Types
enum Type { None, Neuron, MemoryCell, Cluster }
The types of Nucleus. 
Public Member Functions
Cluster (ClusterPrefab prefab, Cluster parent)
Instantiate a new copy of a ClusterPrefab in the given parent. 

Cluster (ClusterPrefab prefab, ClusterPrefab parent=null)
Add a new cluster to a ClusterPrefab. 

override Nucleus ShallowCloneTo (Cluster parent)
Function to make a partial clone of this nucleus.   

void AddInstance ()
Increase the number of instances in an multi-cluster. 

void AddInstance (ClusterPrefab prefab)
Create an new instance in a multi-cluster. 

void RemoveInstance ()
Decrease the number of instance in a multi-cluster. 

void RefreshComputeOrders ()
Refresh the order in which neurons should be computed. 

void RefreshOutputs ()
Reset the list of outputs such that they will be re-determined. 

bool TryGetNucleus (string nucleusName, out Nucleus foundNucleus)
Try to find a nucleus in this cluster. 

Neuron GetNeuron (string neuronName)
Get a neuron in this cluster. 

Cluster GetCluster (string clusterName)
Get a subcluster in this cluster. 

Neuron GetNeuron (int thingId, string neuronName, string thingName=null)
Get a neuron in an instance of a multi-cluster. 

bool DeleteNucleus (Nucleus nucleus)
Delete a nucleus from this clsuter. 

virtual List< Nucleus > CollectReceivers (bool removeDuplicates=false)
Collect all receiving nuclei of signals from this cluster. 

List< Synapse > CollectSynapsesTo (Cluster otherCluster)
Collect all synapses of senders in another cluster of signals to this cluster. 

void UpdateFromNucleus (Nucleus startNucleus)
Update the state of the nucleus and all nuclei receiving from it. 

override void UpdateStateIsolated ()
Update the state without updating other Nuclei.   

void Refresh ()
Recalculate derived properties. 

Static Public Member Functions
static int GetNucleusIndex (List< Nucleus > nuclei, Nucleus nucleus)
Get the index of a nucleus in a list of nuclei. 

static int GetNucleusIndex (List< Nucleus > nuclei, string nucleusName)
Get the index of a nucleus with the given name in a list of nuclei. 

Public Attributes
ClusterPrefab prefab
The prefab used to create this cluster. 

int version
The version number of this cluster instance. 

Cluster[] instances
All cluster instance of a multi-cluster. 

int instanceCount = 1
The number of cluster instances in a multi-cluster. 

Dictionary< int, Cluster > thingClusters = new()
The mapping from things to cluster instances. 

List< Nucleus > nuclei = new()
All nuclei in this cluster. 

string name
The name of the Nucleus. 

Cluster parent
The cluster instance in which the nucleus is located. 

Protected Attributes
List< Neuron > _outputs = null
The neurons without outgoing connections. 

Properties
string baseName [get]
The base name of the cluster. I don't think this is actively used at this moment. 

Dictionary< Nucleus, List< Nucleus > > computeOrders [get]
This gives the order in which nuclei should be computed when a nucleus is updated. 

virtual Neuron defaultOutput [get]
The first nucleus in a cluster is the default output. 

List< Neuron > outputs [get]
The neurons without outgoing connections. 

Constructor & Destructor Documentation
Cluster (ClusterPrefab  prefab, Cluster  parent)

Instantiate a new copy of a ClusterPrefab in the given parent. 

Parameters
prefab 	The prefab to use	
parent 	The cluster in which this new cluster will be placed	
Cluster (ClusterPrefab  prefab, ClusterPrefab  parent = null)

Add a new cluster to a ClusterPrefab. 

Parameters
prefab 	The prefab to copy	
parent 	The prefab in which the new copy is placed	

Member Function Documentation
override Nucleus ShallowCloneTo (Cluster  parent)

Function to make a partial clone of this nucleus.   

Parameters
parent 	The cluster in which the cloned nucleus should be placed	
Returns

static int GetNucleusIndex (List< Nucleus >  nuclei, Nucleus  nucleus)[static]

Get the index of a nucleus in a list of nuclei. 

Parameters
nuclei 	The list of nuclei to search	
nucleus 	The nucleus to find	
Returns
The index of the nucleus in the list or -1 when it has not been found
static int GetNucleusIndex (List< Nucleus >  nuclei, string  nucleusName)[static]

Get the index of a nucleus with the given name in a list of nuclei. 

Parameters
nuclei 	The list of nuclei to search	
nucleusName 	The name of the nucleus to find	
Returns
The index of the nucleus in the list or -1 when it has not been found
void AddInstance ()

Increase the number of instances in an multi-cluster. 
/remark Note this does not create the instances. This is only intended to be used for prefabs. 
void AddInstance (ClusterPrefab  prefab)

Create an new instance in a multi-cluster. 

Parameters
prefab 	The prefab to use to create the new instance	
/remark This does not change the instanceCount. It should only be used at runtime. 
bool TryGetNucleus (string  nucleusName, out Nucleus  foundNucleus)

Try to find a nucleus in this cluster. 

Parameters
nucleusName 	The name of the nucleus to find	
foundNucleus 	The found nucleus or null if it is not found	
Returns
True when the nucleus is found, false otherwise
Neuron GetNeuron (string  neuronName)

Get a neuron in this cluster. 

Parameters
neuronName 	The name of the neuron to find	
Returns
The found neuron or null when it is not found
Cluster GetCluster (string  clusterName)

Get a subcluster in this cluster. 

Parameters
clusterName 	The name of the cluster to find	
Returns
The found cluster or null when it is not found
Neuron GetNeuron (int  thingId, string  neuronName, string  thingName = null)

Get a neuron in an instance of a multi-cluster. 

Parameters
thingId 	The id of the thing mapped to the cluster instance	
neuronName 	The name of the neuron to find	
thingName 	The name of the thing mapped to the cluster instance	
Returns
The found neuron or null when it is not found
The cluster instance mapped to the thing will be neuron.parent if a neuron is found. 
bool DeleteNucleus (Nucleus  nucleus)

Delete a nucleus from this clsuter. 

Parameters
nucleus 	The nucleus to delete	
Returns
True if a nucleus was deleted, false if the nucleus could not be found
virtual List< Nucleus > CollectReceivers (bool  removeDuplicates = false)[virtual]

Collect all receiving nuclei of signals from this cluster. 

Parameters
removeDuplicates 	Ensure that a receiver is only listed once in the result	
Returns
The list of receivers
List< Synapse > CollectSynapsesTo (Cluster  otherCluster)

Collect all synapses of senders in another cluster of signals to this cluster. 

Parameters
otherCluster 	The other cluster with sending neurons	
Returns
A list of synapses to the neurons in the other clusters
void UpdateFromNucleus (Nucleus  startNucleus)

Update the state of the nucleus and all nuclei receiving from it. 

Parameters
startNucleus 	The nucleus to start updating	
override void UpdateStateIsolated ()

Update the state without updating other Nuclei.   

void Refresh ()

Recalculate derived properties. 
This can be used to recalculate derived properties after the set of nuclei has been changed 

Member Data Documentation
ClusterPrefab prefab

The prefab used to create this cluster. 
Cluster should always be created from prefabs 
int version

The version number of this cluster instance. 
This is used to detect changes in the prefab which require this Cluster instance to be updated 
Cluster [] instances

All cluster instance of a multi-cluster. 
A cluster is a multi-cluster when there is more than one instance. The actual instances are only created at runtime. The value instanceCount determines how many instances will be present at runtime. 
int instanceCount = 1

The number of cluster instances in a multi-cluster. 
A cluster is a multi-clsuter when there is more than one instance. 
Dictionary<int, Cluster> thingClusters = new()

The mapping from things to cluster instances. 
In a multi-cluster each instance can be used for a thing. Cluster instance may also not (yet) be mapped to a thing. 
List<Neuron> _outputs = null[protected]

The neurons without outgoing connections. 
These neurons can potentially be connected to neurons in other clusters 

Property Documentation
List<Neuron> outputs[get]

The neurons without outgoing connections. 
These neurons can potentially be connected to neurons in other clusters 

ClusterPrefab Class Reference

Description
The Unity ScriptableObject to implement re-usable Cluster Prefabs. 

Inherits ScriptableObject.
Public Attributes
Cluster cluster
The cluster data. 

int version
The version number of this Prefab. 

Member Data Documentation
int version

The version number of this Prefab. 
This is used to detect changes in the prefab which require Cluster instances to be updated 

LightSensor Class Reference

Description
A light sensor. 
Inheritance diagram for LightSensor:
IMAGE
Public Attributes
bool useOcclusion = true
If true, perform occlusion checks with raycasts. 

float sensitivityAngle = 180f
Angle in degrees for directional sensitivity; >= 180: omnidirectional. 

float sensorRange = 10f
Maximum distance the sensor detects anything. 

float sampleInterval = 0.1f
Time between samples in seconds. 

LayerMask senseLayer
Unity Layer for the light objects. 

Neuron sensoryNeuron
The NanoBrain::Neuron which is stimulated by this sensor. 

Protected Member Functions
override float SampleSensor ()
Performs a sampling function to retrieve a new sensor output value. 

virtual void Awake ()
Unity calls Awake when loading an instance of a script component. 

Properties
float output [get, protected set]
Output value of the sensor. 

Member Function Documentation
override float SampleSensor ()[protected], [virtual]

Performs a sampling function to retrieve a new sensor output value. 

Returns
Sensor output value
Reimplemented from Sensor.

Member Data Documentation
LayerMask senseLayer[inherited]

Unity Layer for the light objects. 
This is used to improve performance 

MemoryCell Class Reference

Description
A MemoryCell stored its value for one update. 
When the input for a Memory Cell changes, it will output the previous value 
 
Inheritance diagram for MemoryCell:
IMAGE
Public Types
enum CombinatorType { Sum, Product }
The type of combinators. 
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
MemoryCell (Cluster parent, string name)
Create a new memory cell. 

override Nucleus ShallowCloneTo (Cluster parent)
Function to make a partial clone of this nucleus.   

override void UpdateStateIsolated ()
Update the state without updating other Nuclei.   

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. 

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 Vector3 CombinatorSum (Vector3 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 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. 

Vector3 Activator (Vector3 inputValue)
Apply the activation function to the input. 

float3 ActivatorLinear (float3 input)
Linear activation function. 

Vector3 ActivatorLinear (Vector3 input)
Linear activation function. 

float3 ActivatorSqrt (float3 input)
Square root activation function. 

Vector3 ActivatorSqrt (Vector3 input)
Square root activation function. 

float3 ActivatorPower (float3 input)
Power activation function. 

Vector3 ActivatorPower (Vector3 input)
Power activation function. 

float3 ActivatorReciprocal (float3 input)
Reciprocal activation function. 

Vector3 ActivatorReciprocal (Vector3 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. 

Protected Attributes
float3 _outputValue
The output value of the neuron. 

Vector3 _outputValue
The output value of the neuron. 

Properties
List< Synapse > synapses [get]
The synapses of the nucleus. 

ActivationType activator [get, set]
The activation funtion. 

virtual float3 outputValue [get, set]
The output value of the neuron. 

virtual Vector3 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. 

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< Nucleus > receivers [get, set]
The nuclei which have a synapse to this neuron. 

Member Enumeration Documentation
enum CombinatorType[inherited]

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
MemoryCell (Cluster  parent, string  name)

Create a new memory cell. 

Parameters
parent 	The cluster in which the memorycell shoud be created	
name 	The name of the memory cell	

Member Function Documentation
override Nucleus ShallowCloneTo (Cluster  parent)

Function to make a partial clone of this nucleus.   

Parameters
parent 	The cluster in which the cloned nucleus should be placed	
Returns

override void UpdateStateIsolated ()

Update the state without updating other Nuclei.   

Synapse AddSynapse (Neuron  sendingNucleus, float  weight = 1)[inherited]

Add a new synapse to this nuclues. 

Parameters
sendingNucleus 	The nucleus from which the signals may originate	
weight 	The 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. 
Synapse GetSynapse (Nucleus  sender)[inherited]

Find a synapse. 

Parameters
sender 	The sender of the input to the Synapse	
Returns
The found Synapse or null when the sender has no synapse to this nucleus.
void RemoveSynapse (Nucleus  sendingNucleus)[inherited]

Remove a synapse from a Nucleus. 

Parameters
sendingNucleus 	Remote the synapse connecting to this Nucleus	
virtual void SetBias (Vector3  inputValue)[virtual], [inherited]

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

Parameters
inputValue 		
void SleepCheck ()[inherited]

Check if the neuron is sleeping. 
This will reset the output value if it is sleeping 
virtual void CloneFields (Neuron  clone)[protected], [virtual], [inherited]

Copy relevant fields of this neuron to the given neuron. 

Parameters
clone 		
static void Delete (Nucleus  nucleus)[static], [inherited]

Delete the give neuron. 

Parameters
nucleus 	The neuron to delete	
float3 Combinator (float3  bias, List< Synapse >  synapses)[protected], [inherited]

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

Parameters
bias 	The bias of the neuron	
synapses 	The synapses of the neuron	
Returns

Vector3 Combinator (Vector3  bias, List< Synapse >  synapses)[protected], [inherited]

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

Parameters
bias 	The bias of the neuron	
synapses 	The synapses of the neuron	
Returns

static float3 CombinatorSum (float3  bias, List< Synapse >  synapses)[static], [inherited]

Sum the bias and synpase outputs together. 

Parameters
bias 	The bias of the neuron	
synapses 	The synapses of the neuron	
Returns

static Vector3 CombinatorSum (Vector3  bias, List< Synapse >  synapses)[static], [inherited]

Sum the bias and synpase outputs together. 

Parameters
bias 	The bias of the neuron	
synapses 	The synapses of the neuron	
Returns

static float3 CombinatorProduct (float3  bias, List< Synapse >  synapses)[static], [inherited]

Multiply the synapse outputs together. 

Parameters
bias 	The bias of the neuron	
synapses 	The synapses of the neuron	
Returns
The result of the multiplication
static Vector3 CombinatorProduct (Vector3  bias, List< Synapse >  synapses)[static], [inherited]

Multiply the synapse outputs together. 

Parameters
bias 	The bias of the neuron	
synapses 	The synapses of the neuron	
Returns
The result of the multiplication
float3 Activator (float3  inputValue)[protected], [inherited]

Apply the activation function to the input. 

Parameters
inputValue 		
Returns
The result of applying the activation function
Vector3 Activator (Vector3  inputValue)[protected], [inherited]

Apply the activation function to the input. 

Parameters
inputValue 		
Returns
The result of applying the activation function
float3 ActivatorLinear (float3  input)[protected], [inherited]

Linear activation function. 

Parameters
input 	Input value	
Returns
The unchanged value
Vector3 ActivatorLinear (Vector3  input)[protected], [inherited]

Linear activation function. 

Parameters
input 	Input value	
Returns
The unchanged value
float3 ActivatorSqrt (float3  input)[protected], [inherited]

Square root activation function. 

Parameters
input 	Input value	
Returns
The square root of the input
Vector3 ActivatorSqrt (Vector3  input)[protected], [inherited]

Square root activation function. 

Parameters
input 	Input value	
Returns
The square root of the input
float3 ActivatorPower (float3  input)[protected], [inherited]

Power activation function. 

Parameters
input 	Input value	
Returns
The input to the power of 2
Vector3 ActivatorPower (Vector3  input)[protected], [inherited]

Power activation function. 

Parameters
input 	Input value	
Returns
The input to the power of 2
float3 ActivatorReciprocal (float3  input)[protected], [inherited]

Reciprocal activation function. 

Parameters
input 	Input value	
Returns
1/input value
Vector3 ActivatorReciprocal (Vector3  input)[protected], [inherited]

Reciprocal activation function. 

Parameters
input 	Input value	
Returns
1/input value
float3 ActivatorTanh (float3  input)[protected], [inherited]

Tanh activation function. 

Parameters
input 	Input value	
Returns
Tanh(input value)
float3 ActivatorBinary (float3  input)[protected], [inherited]

Binary activation function. 

Parameters
input 	Input value	
Returns
An uniform vector with magnitude between 0 and 1
float3 ActivatorNormalized (float3  input)[protected], [inherited]

Normalize activation function. 

Parameters
input 	Input value	
Returns
The normalized vector
virtual void AddReceiver (Nucleus  receiverToAdd, float  weight = 1)[virtual], [inherited]

Add a new receiver to this neuron. 

Parameters
receiverToAdd 	The receiver to add	
weight 	The weight to use for the synapse to his neuron	
virtual void RemoveReceiver (Nucleus  receiverToRemove)[virtual], [inherited]

Remove a receiver to this neuron. 

Parameters
receiverToRemove 	The receiver to remove	
virtual void ProcessStimulus (Vector3  inputValue)[virtual], [inherited]

Process an external stimulus. 

Parameters
inputValue 	The value of the stimulus	

Member Data Documentation
Vector3 bias = Vector3.zero[inherited]

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 
bool breakOnUpdate = false[inherited]

When true, Unity will pause exection when this neuron is updated. 
Pausing is implemented using Debug.Break() 

Motor Class Reference

Description
A powered wheel collider, controlled by a NanoBrain::Neuron. 

Inherits MonoBehaviour.
Public Attributes
string outputNeuronName
The name of the NanoBrain::Neuron to control this wheel. 

float maxTorque = 1
The maximum torque used to drive the wheel collider. 

WheelCollider wheelCollider
The wheel collider used to drive the car. 

Neuron motorNeuron
The NanoBrain::Neuron to control this wheel. 

Protected Member Functions
virtual void Awake ()
Unity calls Awake when loading an instance of a script component. 

Properties
float speed [get, protected set]
The speed of the motor in rotations per second. 

Member Data Documentation
string outputNeuronName

The name of the NanoBrain::Neuron to control this wheel. 
This is used to connect the motor to the right output neuron of the Vehicle::brain 
WheelCollider wheelCollider

The wheel collider used to drive the car. 

See also
Unity WheelCollider 

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);
 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:
IMAGE
Public Types
enum CombinatorType { Sum, Product }
The type of combinators. 
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< Synapse > synapses [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< Nucleus > receivers [get, set]
The nuclei which have a synapse to this neuron. 

Member Enumeration Documentation
enum 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 (Cluster  parent, string  name)

Create a new Neuron in a Cluster instance. 

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

Member Function Documentation
Synapse AddSynapse (Neuron  sendingNucleus, float  weight = 1)

Add a new synapse to this nuclues. 

Parameters
sendingNucleus 	The nucleus from which the signals may originate	
weight 	The 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. 
Synapse GetSynapse (Nucleus  sender)

Find a synapse. 

Parameters
sender 	The sender of the input to the Synapse	
Returns
The found Synapse or null when the sender has no synapse to this nucleus.
void RemoveSynapse (Nucleus  sendingNucleus)

Remove a synapse from a Nucleus. 

Parameters
sendingNucleus 	Remote the synapse connecting to this Nucleus	
virtual void SetBias (Vector3  inputValue)[virtual]

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

Parameters
inputValue 		
void SleepCheck ()

Check if the neuron is sleeping. 
This will reset the output value if it is sleeping 
override Nucleus ShallowCloneTo (Cluster  parent)

Function to make a partial clone of this nucleus.   

Parameters
parent 	The cluster in which the cloned nucleus should be placed	
Returns

virtual void CloneFields (Neuron  clone)[protected], [virtual]

Copy relevant fields of this neuron to the given neuron. 

Parameters
clone 		
static void Delete (Nucleus  nucleus)[static]

Delete the give neuron. 

Parameters
nucleus 	The neuron to delete	
override void UpdateStateIsolated ()

Update the state without updating other Nuclei.   

float3 Combinator (float3  bias, List< Synapse >  synapses)[protected]

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

Parameters
bias 	The bias of the neuron	
synapses 	The synapses of the neuron	
Returns

static float3 CombinatorSum (float3  bias, List< Synapse >  synapses)[static]

Sum the bias and synpase outputs together. 

Parameters
bias 	The bias of the neuron	
synapses 	The synapses of the neuron	
Returns

static float3 CombinatorProduct (float3  bias, List< Synapse >  synapses)[static]

Multiply the synapse outputs together. 

Parameters
bias 	The bias of the neuron	
synapses 	The synapses of the neuron	
Returns
The result of the multiplication
Vector3 Combinator (Vector3  bias, List< Synapse >  synapses)[protected]

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

Parameters
bias 	The bias of the neuron	
synapses 	The synapses of the neuron	
Returns

static Vector3 CombinatorSum (Vector3  bias, List< Synapse >  synapses)[static]

Sum the bias and synpase outputs together. 

Parameters
bias 	The bias of the neuron	
synapses 	The synapses of the neuron	
Returns

static Vector3 CombinatorProduct (Vector3  bias, List< Synapse >  synapses)[static]

Multiply the synapse outputs together. 

Parameters
bias 	The bias of the neuron	
synapses 	The synapses of the neuron	
Returns
The result of the multiplication
float3 Activator (float3  inputValue)[protected]

Apply the activation function to the input. 

Parameters
inputValue 		
Returns
The result of applying the activation function
float3 ActivatorLinear (float3  input)[protected]

Linear activation function. 

Parameters
input 	Input value	
Returns
The unchanged value
float3 ActivatorSqrt (float3  input)[protected]

Square root activation function. 

Parameters
input 	Input value	
Returns
The square root of the input
float3 ActivatorPower (float3  input)[protected]

Power activation function. 

Parameters
input 	Input value	
Returns
The input to the power of 2
float3 ActivatorReciprocal (float3  input)[protected]

Reciprocal activation function. 

Parameters
input 	Input value	
Returns
1/input value
float3 ActivatorTanh (float3  input)[protected]

Tanh activation function. 

Parameters
input 	Input value	
Returns
Tanh(input value)
float3 ActivatorBinary (float3  input)[protected]

Binary activation function. 

Parameters
input 	Input value	
Returns
An uniform vector with magnitude between 0 and 1
float3 ActivatorNormalized (float3  input)[protected]

Normalize activation function. 

Parameters
input 	Input value	
Returns
The normalized vector
Vector3 Activator (Vector3  inputValue)[protected]

Apply the activation function to the input. 

Parameters
inputValue 		
Returns
The result of applying the activation function
Vector3 ActivatorLinear (Vector3  input)[protected]

Linear activation function. 

Parameters
input 	Input value	
Returns
The unchanged value
Vector3 ActivatorSqrt (Vector3  input)[protected]

Square root activation function. 

Parameters
input 	Input value	
Returns
The square root of the input
Vector3 ActivatorPower (Vector3  input)[protected]

Power activation function. 

Parameters
input 	Input value	
Returns
The input to the power of 2
Vector3 ActivatorReciprocal (Vector3  input)[protected]

Reciprocal activation function. 

Parameters
input 	Input value	
Returns
1/input value
virtual void AddReceiver (Nucleus  receiverToAdd, float  weight = 1)[virtual]

Add a new receiver to this neuron. 

Parameters
receiverToAdd 	The receiver to add	
weight 	The weight to use for the synapse to his neuron	
virtual void RemoveReceiver (Nucleus  receiverToRemove)[virtual]

Remove a receiver to this neuron. 

Parameters
receiverToRemove 	The receiver to remove	
virtual void ProcessStimulus (Vector3  inputValue)[virtual]

Process an external stimulus. 

Parameters
inputValue 	The value of the stimulus	

Member Data Documentation
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 
bool breakOnUpdate = false

When true, Unity will pause exection when this neuron is updated. 
Pausing is implemented using Debug.Break() 

Nucleus Class Reference

Description
A Nucleus is a basic element in a brain cluster. 
Inheritance diagram for Nucleus:
IMAGE
Public Types
enum Type { None, Neuron, MemoryCell, Cluster }
The types of Nucleus. 
Public Member Functions
Nucleus ShallowCloneTo (Cluster parent)
Function to make a partial clone of this nucleus. 

void UpdateStateIsolated ()
Update the state without updating other Nuclei. 

Public Attributes
string name
The name of the Nucleus. 

Cluster parent
The cluster instance in which the nucleus is located. 

Member Function Documentation
Nucleus ShallowCloneTo (Cluster  parent)[abstract]

Function to make a partial clone of this nucleus. 

Parameters
parent 	The cluster in which the cloned nucleus should be placed	
Returns

Sensor Class Reference

Description
A non-directional sensor. 
The sensor has a field of view, but the signal returned does not include a direction 
Inheritance diagram for Sensor:
IMAGE
Public Attributes
float sensorRange = 10f
Maximum distance the sensor detects anything. 

float sampleInterval = 0.1f
Time between samples in seconds. 

LayerMask senseLayer
Unity Layer for the light objects. 

Neuron sensoryNeuron
The NanoBrain::Neuron which is stimulated by this sensor. 

Protected Member Functions
virtual void Awake ()
Unity calls Awake when loading an instance of a script component. 

virtual float SampleSensor ()
Performs a sampling function to retrieve a new sensor output value. 

Properties
float output [get, protected set]
Output value of the sensor. 

Member Function Documentation
virtual float SampleSensor ()[protected], [virtual]

Performs a sampling function to retrieve a new sensor output value. 

Returns
Sensor output value
Reimplemented in LightSensor, and TouchSensor.

Member Data Documentation
LayerMask senseLayer

Unity Layer for the light objects. 
This is used to improve performance 

Synapse Class Reference

Description
A Synapse connects the ouput of a Neuron to another Neuron. 
Public Member Functions
Synapse (Neuron nucleus, float weight=1.0f)
Create a new Synapse. 

Public Attributes
Neuron neuron
The neuron from which input is received. 

float weight
The weight value to apply to the Neuron input. 

Constructor & Destructor Documentation
Synapse (Neuron  nucleus, float  weight = 1::0f)

Create a new Synapse. 

Parameters
nucleus 	The neuron from which input is received	
weight 	The weight value to apply to the Neuron input	

TouchSensor Class Reference

Description
A sensor which can detect contacts with static GameObjects or Rigidbodies. 
Inheritance diagram for TouchSensor:
IMAGE
Public Attributes
float sensorRange = 10f
Maximum distance the sensor detects anything. 

float sampleInterval = 0.1f
Time between samples in seconds. 

LayerMask senseLayer
Unity Layer for the light objects. 

Neuron sensoryNeuron
The NanoBrain::Neuron which is stimulated by this sensor. 

Protected Member Functions
override float SampleSensor ()
Returns the current touching state. 

virtual void Awake ()
Unity calls Awake when loading an instance of a script component. 

Properties
bool touching [get, protected set]
Is the sensor touching something? 

float output [get, protected set]
Output value of the sensor. 

Member Function Documentation
override float SampleSensor ()[protected], [virtual]

Returns the current touching state. 

Returns
1.0 when touching something, 0.0 otherwise
Reimplemented from Sensor.

Member Data Documentation
LayerMask senseLayer[inherited]

Unity Layer for the light objects. 
This is used to improve performance 

Vehicle Class Reference

Description
A Braitenberg style vehicle with two sensors and two motors, powered by a Nanobrain. 

Inherits MonoBehaviour.
Public Attributes
Cluster brain
The NanoBrain::Cluster controlling the vehicle. 

Motor motorLeft
The left motor. 

Motor motorRight
The right motor. 

Sensor sensorLeft
The front-left sensor. 

Sensor sensorRight
The front-right sensor. 

Member Data Documentation
Sensor sensorLeft

The front-left sensor. 
When the vehicle has only one sensor, this can be used as the single sensor 
Sensor sensorRight

The front-right sensor. 
When the vehicle has only one sensor, this can be set to null 

Index
INDEX