cc9a845 Fix sleeping for product combinator e4ba7f8 Better cross-cluster monitoring 4f8a6ab Improved (but not fixed) cross-cluster monitoring b12616b Fix neuron output visualisation 96439cc Visualize all outputs d583e67 WIP cluster references/instance 04bab92 Fix links to multiple cluster neurons & cleanup e17a249 Cross-cluster editor links 0ab2d21 Migrating and cleaning up b6630ad First steps to using instanceCount for clusters 8801fa2 Cluster reimport fixes befb69d full graph with collapsed clusters 1a1919f Fix expansion of clsuter arrays c708f4d Improved clusterarray support c2e4e1b Fix Cluster array extension 02047a4 Adde full graph scrollbar 471ed36 Completed full graph integration 830e3e7 Added full graph view mode 249e888 Improve full graph view 308a6a1 The Entities are battling 75d9d1c Cleanup c8f0f0c Fix aging of neurons e2e169c small fixes 619ced6 Removed the use of Receptors 19f9296 Simplifications bc0a796 Integrated clusterarray in cluster e40dd23 Fixed clusterViewer for clusterarrays b0f4b41 Status quo adding clusterArrays 1fc75a8 Added ClusterArray 0023920 Cover seeking(-ish) behaviour 1c7b8e7 Added Tanh Activation a99d40c BrainViewer added db43655 Pew pew! 18ef4cd Merge commit '89017475984bbbf1899fb38846c5bb0e7775dedd' into NanoBrain git-subtree-dir: NanoBrain git-subtree-split: cc9a845b643ffb4a9abe4f7da787ac5c5b14dae8
154 lines
4.7 KiB
C#
154 lines
4.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// The Nanobrain namespace
|
|
/// </summary>
|
|
namespace NanoBrain {
|
|
|
|
/// <summary>
|
|
/// A Nucleus is a basic element in a brain cluster
|
|
/// </summary>
|
|
[Serializable]
|
|
public abstract class Nucleus {
|
|
/// <summary>
|
|
/// The name of the Nucleus
|
|
/// </summary>
|
|
public string name;
|
|
|
|
/// <summary>
|
|
/// The cluster prefab in which the nucleus is located
|
|
/// </summary>
|
|
[SerializeReference]
|
|
public ClusterPrefab clusterPrefab;
|
|
/// <summary>
|
|
/// The cluster instance in which the nucleus is located
|
|
/// </summary>
|
|
[SerializeReference]
|
|
public Cluster parent;
|
|
|
|
/// <summary>
|
|
/// Toggle for printing debugging trace data
|
|
/// </summary>
|
|
public bool trace = false;
|
|
|
|
/// <summary>
|
|
/// Function to make a partial clone of this nucleus
|
|
/// </summary>
|
|
/// <param name="parent">The cluster in which the cloned nucleus should be placed</param>
|
|
/// <returns></returns>
|
|
public abstract Nucleus ShallowCloneTo(Cluster parent);
|
|
/// <summary>
|
|
/// Function to clone a nucleus to a Cluster prefab
|
|
/// </summary>
|
|
/// <param name="prefab"></param>
|
|
/// <returns></returns>
|
|
public abstract Nucleus Clone(ClusterPrefab prefab);
|
|
|
|
/// <summary>
|
|
/// The types of Nucleus
|
|
/// </summary>
|
|
public enum Type {
|
|
None,
|
|
Neuron,
|
|
MemoryCell,
|
|
Cluster,
|
|
//Receptor,
|
|
//ClusterReceptor,
|
|
//ClusterArray,
|
|
}
|
|
|
|
public virtual void Initialize() {}
|
|
|
|
#region Synapses
|
|
|
|
/// <summary>
|
|
/// The bias of the nucleus
|
|
/// </summary>
|
|
/// The bias which a value which is always added to the combined value of the nucleus
|
|
/// It does not have a synapse and therefore no weight of source nucleus
|
|
public Vector3 bias = Vector3.zero;
|
|
|
|
[SerializeField]
|
|
private List<Synapse> _synapses = new();
|
|
/// <summary>
|
|
/// The synapses of the nucleus
|
|
/// </summary>
|
|
public List<Synapse> synapses => _synapses;
|
|
|
|
/// <summary>
|
|
/// Add a new synapse to this nuclues
|
|
/// </summary>
|
|
/// <param name="sendingNucleus">The nucleus from which the signals may originate</param>
|
|
/// <param name="weight">The weight applied to the input. Default value = 1</param>
|
|
/// <returns>The created Synapse</returns>
|
|
/// This will add a new input to this nucleus with the given weight.
|
|
public Synapse AddSynapse(Neuron sendingNucleus, float weight = 1) {
|
|
Synapse synapse = new(sendingNucleus, weight);
|
|
this.synapses.Add(synapse);
|
|
return synapse;
|
|
}
|
|
|
|
// public Synapse AddSynapse(ClusterPrefab clusterPrefab, string neuronName, float weight = 1) {
|
|
|
|
// }
|
|
|
|
/// <summary>
|
|
/// Find a synapse
|
|
/// </summary>
|
|
/// <param name="sender">The sender of the input to the Synapse</param>
|
|
/// <returns>The found Synapse or null when the sender has no synapse to this nucleus.</returns>
|
|
public Synapse GetSynapse(Nucleus sender) {
|
|
foreach (Synapse synapse in this.synapses)
|
|
if (synapse.neuron == sender)
|
|
return synapse;
|
|
return null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove a synapse from a Nucleus
|
|
/// </summary>
|
|
/// <param name="sendingNucleus">Remote the synapse connecting to this Nucleus</param>
|
|
public void RemoveSynapse(Nucleus sendingNucleus) {
|
|
this.synapses.RemoveAll(synapse => synapse.neuron == sendingNucleus);
|
|
}
|
|
|
|
#endregion Synapses
|
|
|
|
#region Update
|
|
|
|
/// <summary>
|
|
/// Update the state without updating other Nuclei
|
|
/// </summary>
|
|
public abstract void UpdateStateIsolated();
|
|
|
|
/// <summary>
|
|
/// Update the state and recursively all Nuclei receiving data from this Nucleus
|
|
/// </summary>
|
|
public virtual void UpdateNuclei() {
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set the bias, recalculate the output and update all Nuclei receiving from this Nucleus
|
|
/// </summary>
|
|
/// <param name="inputValue"></param>
|
|
public virtual void SetBias(Vector3 inputValue) {
|
|
this.bias = inputValue;
|
|
this.parent.UpdateFromNucleus(this);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Process an external stimulus
|
|
/// </summary>
|
|
/// <param name="inputValue">The value of the stimulus</param>
|
|
/// <param name="thingId">The id of the thing causing the stimulus</param>
|
|
/// <param name="thingName">The name of the thing causing the stimulus</param>
|
|
public virtual void ProcessStimulus(Vector3 inputValue) { //, int thingId = 0, string thingName = "") {
|
|
}
|
|
|
|
#endregion Update
|
|
|
|
}
|
|
|
|
} |