From 00dea149f3f15e71a15e600b19c0f14b7b507a15 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Thu, 5 Feb 2026 17:38:10 +0100 Subject: [PATCH] Cleanup --- Cluster.cs | 117 +------------------------------- Editor/NanoBrain_Editor.cs | 24 ------- INucleus.cs | 59 ---------------- INucleus.cs.meta | 2 - MemoryCell.cs | 39 ----------- NanoBrain.cs | 12 ---- Neuron.cs | 133 ------------------------------------- 7 files changed, 2 insertions(+), 384 deletions(-) delete mode 100644 INucleus.cs delete mode 100644 INucleus.cs.meta diff --git a/Cluster.cs b/Cluster.cs index 351176e..9d29581 100644 --- a/Cluster.cs +++ b/Cluster.cs @@ -7,14 +7,6 @@ using static Unity.Mathematics.math; [Serializable] public class Cluster : Nucleus { - // The ScriptableObject asset from which the runtime object has been created - - // [SerializeField] - // protected string _name; - // public virtual string name { - // get => _name; - // set => _name = value; - // } #region Init @@ -181,8 +173,6 @@ public class Cluster : Nucleus { public ClusterPrefab prefab; - // public ClusterPrefab cluster { get; set; } - // public Cluster parent { get; set; } [SerializeReference] public List nuclei = new(); @@ -215,14 +205,6 @@ public class Cluster : Nucleus { } } - // Not sure if this belongs here... - // [SerializeReference] - // private NucleusArray _array; - // public NucleusArray array { - // get { return _array; } - // set { _array = value; } - // } - public bool TryGetNucleus(string nucleusName, out Nucleus foundNucleus) { foreach (Nucleus receptor in this.nuclei) { if (receptor is Nucleus nucleus) @@ -244,92 +226,14 @@ public class Cluster : Nucleus { return null; } - #region Synapses - - // [SerializeField] - // private List _synapses = new(); - // public List synapses => _synapses; - - // public Synapse AddSynapse(Nucleus sendingNucleus, float weight = 1.0f) { - // Synapse synapse = new(sendingNucleus, weight); - // this._synapses.Add(synapse); - // return synapse; - // } - - // Does this even exist already? - public void RemoveSynapse() { - - } - - #endregion Synapses - - #region Receivers - - // [SerializeReference] - // private List _receivers = new(); - // public List receivers { - // get { return _receivers; } - // set { _receivers = value; } - // } - - // public virtual void AddReceiver(Nucleus receivingNucleus, float weight = 1) { - // this._receivers.Add(receivingNucleus); - // receivingNucleus.AddSynapse(this, weight); - // } - - // public void RemoveReceiver(Nucleus receiverNucleus) { - // this._receivers.RemoveAll(receiver => receiver == receiverNucleus); - // receiverNucleus.synapses.RemoveAll(synapse => synapse.nucleus == this); - // } - - #endregion Receivers - - #region Runtime - - // [NonSerialized] - // private int stale = 1000; - // public bool isSleeping => lengthsq(this.outputValue) == 0; - - // [NonSerialized] - // protected float3 _outputValue; - // public virtual float3 outputValue { - // get { return _outputValue; } - // set { - // this.stale = 0; - // _outputValue = value; - // } - // } - #region Update - // public virtual void UpdateState() { - // UpdateState(new float3(0, 0, 0)); - // } - - // public void UpdateState(float3 bias) { - // float3 sum = bias; // new(0, 0, 0); - - // //Applying the weight factors - // foreach (Synapse synapse in this.synapses) { - // sum += synapse.weight * synapse.nucleus.outputValue; - // } - - // //this.inputs[0].UpdateState(sum); - // this.inputs[0].UpdateStateIsolated(sum); - // foreach (IReceptor receptor in this.sortedNuclei) { - // if (receptor is Nucleus nucleus && nucleus != this.inputs[0]) - // nucleus.UpdateStateIsolated(); - // } - - // UpdateResult(this.output.outputValue); - // } - public override void UpdateStateIsolated() { float3 bias = new(0, 0, 0); UpdateStateIsolated(bias); } public override void UpdateStateIsolated(float3 bias) { - float3 sum = bias; // new(0, 0, 0); + float3 sum = bias; //Applying the weight factors foreach (Synapse synapse in this.synapses) { @@ -339,42 +243,25 @@ public class Cluster : Nucleus { } } - //this.inputs[0].UpdateState(sum); this.inputs[0].UpdateStateIsolated(sum); foreach (Nucleus receptor in this.sortedNuclei) { - if (receptor is Nucleus nucleus && nucleus != this.inputs[0]) { - //if (nucleus.isSleeping == false) + if (receptor is Nucleus nucleus && nucleus != this.inputs[0]) nucleus.UpdateStateIsolated(); - } } this.outputValue = this.output.outputValue; UpdateNuclei(); } - // public virtual void UpdateResult(Vector3 result) { - // // float d = Vector3.Distance(result, this.outputValue); - // // if (d < 0.5f) { - // // //Debug.Log($"insignificant update: {d}"); - // // return; - // // } - - // this.outputValue = result; - // foreach (Nucleus receiver in this.receivers) - // receiver.UpdateState(); - // } - public override void UpdateNuclei() { this.stale++; if (this.stale > 5) _outputValue = Vector3.zero; - //foreach (IReceptor nucleus in this.prefab.nuclei) foreach (Nucleus nucleus in this.nuclei) nucleus.UpdateNuclei(); } #endregion Update - #endregion Runtime } diff --git a/Editor/NanoBrain_Editor.cs b/Editor/NanoBrain_Editor.cs index f4cd22b..646f384 100644 --- a/Editor/NanoBrain_Editor.cs +++ b/Editor/NanoBrain_Editor.cs @@ -87,30 +87,6 @@ public class NanoBrainComponent_Editor : Editor { return root; } - // void OnSceneGUI() { - // if (Application.isPlaying && board != null) - // board.OnIMGUI(); - // } - - // void OnSceneGui(SceneView sv) { - // if (Application.isPlaying == false) - // return; - // // May need some throttling here... - // if (board != null) { - // Debug.Log("."); - // board.OnIMGUI(); - // } - - // // EditorApplication.delayCall = UpdateInspectorUI; - // } - - // void UpdateInspectorUI() { - // if (board != null) { - // Debug.Log("."); - // board.OnIMGUI(); - // } - // } - private void UpdateLayout(float containerWidth) { // if (containerWidth > 800f) { mainContainer.style.flexDirection = FlexDirection.Row; diff --git a/INucleus.cs b/INucleus.cs deleted file mode 100644 index 17199fc..0000000 --- a/INucleus.cs +++ /dev/null @@ -1,59 +0,0 @@ -/* -using System.Collections.Generic; -using Unity.Mathematics; - -public interface INucleus { - - #region static struct - - // Cluster - public ClusterPrefab cluster { get; } - public Cluster parent { get; } - - // Senders - public List synapses { get; } - public Synapse AddSynapse(Nucleus sender, float weight = 1.0f); - - public NucleusArray array { get; set; } - - #endregion static struct - - #region dynamic state - - // public void UpdateState(); - // public void UpdateState(float3 inputValue); - // public void UpdateStateIsolated(); - // public void UpdateStateIsolated(float3 inputValue); - - #endregion dynamic state - - #region static - - public string name { get; set; } - - // Receivers - // public List receivers { get; set; } - - // public void AddReceiver(Nucleus receiver, float weight = 1); - // public void RemoveReceiver(Nucleus receiverNucleus); - - #endregion static - - #region dynamic - - // float3 to prepare for SIMD - public float3 outputValue { get; } - - public void UpdateNuclei(); - public bool isSleeping { get; } - - #endregion dynamic - - // public INucleus ShallowCloneTo(Cluster parent); - // public INucleus Clone(); -} - -// public interface IReceptor { -// } - -*/ \ No newline at end of file diff --git a/INucleus.cs.meta b/INucleus.cs.meta deleted file mode 100644 index aed95bb..0000000 --- a/INucleus.cs.meta +++ /dev/null @@ -1,2 +0,0 @@ -fileFormatVersion: 2 -guid: 6a8a0e8965cea660abff254cab8a4723 \ No newline at end of file diff --git a/MemoryCell.cs b/MemoryCell.cs index 5341220..7da9ed1 100644 --- a/MemoryCell.cs +++ b/MemoryCell.cs @@ -8,10 +8,6 @@ public class MemoryCell : Neuron { public MemoryCell(ClusterPrefab cluster, string name) : base(cluster, name) { } public MemoryCell(Cluster parent, string name) : base(parent, name) { } - // this.parent = parent; - // this.name = name; - // this.parent?.nuclei.Add(this); - // } public override Nucleus ShallowCloneTo(Cluster newParent) { MemoryCell clone = new(newParent, this.name) { @@ -29,24 +25,6 @@ public class MemoryCell : Neuron { private float3 _memorizedValue; private float _memorizedTime; - // public override void UpdateState(float3 bias) { - // // A memorycell does not have an activation function - // float3 result = bias; - // int n = 0; - - // //Applying the weight factgors - // foreach (Synapse synapse in this.synapses) { - // result += synapse.weight * synapse.nucleus.outputValue; - // if (lengthsq(synapse.nucleus.outputValue) != 0) - // n++; - // } - - // if (this.average) - // result /= n; - - // UpdateResult(result); - // } - public override void UpdateStateIsolated() { float3 bias = new(0, 0, 0); UpdateStateIsolated(bias); @@ -73,22 +51,5 @@ public class MemoryCell : Neuron { this._memorizedTime = Time.time; } - // public override void UpdateResult(Vector3 result) { - // // output value is the previous value - // // if (this.deltaValue) { - // // float deltaTime = Time.time - this._memorizedTime; - // // this._outputValue = this._memorizedValue * deltaTime; - // // } - // //else - // this.outputValue = this._memorizedValue; - - // // Store the result for the next time - // this._memorizedValue = result; - // this._memorizedTime = Time.time; - - // foreach (INucleus receiver in this.receivers) - // receiver.UpdateState(); - // } - #endregion State } diff --git a/NanoBrain.cs b/NanoBrain.cs index 930c6a1..3e3ee21 100644 --- a/NanoBrain.cs +++ b/NanoBrain.cs @@ -13,22 +13,10 @@ public class NanoBrain : MonoBehaviour { name = defaultBrain.name + " (Instance)" }; } - // SwarmControl sc = FindFirstObjectByType(); - // if (sc != null) { - // UpdateWeight(brainInstance, "Containment", sc.containmentForce); - // UpdateWeight(brainInstance, "Cohesion", sc.cohesionForce); - // UpdateWeight(brainInstance, "Separation", sc.separationForce); - // UpdateWeight(brainInstance, "Alignment", sc.alignmentForce); - // } return brainInstance; } } - // public void Awake() { - // brainInstance = new Cluster(defaultBrain); - // } - - public static void UpdateWeight(Cluster brain, string name, float weight) { Nucleus root = brain.output; foreach (Synapse synapse in root.synapses) { diff --git a/Neuron.cs b/Neuron.cs index 41b41e8..aa62c72 100644 --- a/Neuron.cs +++ b/Neuron.cs @@ -24,31 +24,6 @@ public class Neuron : Nucleus { // Debug.LogError("No neuroid network"); } - // [SerializeField] - // protected string _name; - // public virtual string name { - // get => _name; - // set => _name = value; - // } - - // [SerializeField] - // private List _synapses = new(); - // public List synapses => _synapses; - - // [SerializeReference] - // private List _receivers = new(); - // public List receivers { - // get { return _receivers; } - // set { _receivers = value; } - // } - - // [SerializeReference] - // private NucleusArray _array; - // public NucleusArray array { - // get { return _array; } - // set { _array = value; } - // } - #region Serialization public enum CurvePresets { @@ -102,9 +77,6 @@ public class Neuron : Nucleus { #region Runtime state (not serialized) - // public ClusterPrefab cluster { get; set; } - // public Cluster parent { get; set; } - #region Activation public static class Presets { @@ -153,31 +125,6 @@ public class Neuron : Nucleus { #endregion Activation - // protected float3 _outputValue; - // public virtual float3 outputValue { - // get { return _outputValue; } - // set { - // this.stale = 0; - // // this._isSleeping = false; - // _outputValue = value; - // } - // } - - // [NonSerialized] - // private int stale = 1000; - - // private bool _isSleeping = false; - // public bool isSleeping => _isSleeping; - // public bool isSleeping => lengthsq(this.outputValue) == 0; - - // public void UpdateNuclei() { - // this.stale++; - // // this._isSleeping = this.stale > 2; - // // if (isSleeping) - // if (this.stale > 2) - // _outputValue = Vector3.zero; - // } - #endregion Runtime state // this clone the nucleus without the synapses and receivers @@ -214,16 +161,6 @@ public class Neuron : Nucleus { return clone; } - // public virtual void AddReceiver(INucleus receivingNucleus, float weight = 1) { - // this._receivers.Add(receivingNucleus); - // receivingNucleus.AddSynapse(this, weight); - // } - - // public void RemoveReceiver(INucleus receiverNucleus) { - // this._receivers.RemoveAll(receiver => receiver == receiverNucleus); - // receiverNucleus.synapses.RemoveAll(synapse => synapse.nucleus == this); - // } - public static void Delete(Nucleus nucleus) { foreach (Synapse synapse in nucleus.synapses) { if (synapse.nucleus is Neuron synapse_nucleus) { @@ -248,59 +185,6 @@ public class Neuron : Nucleus { } } - // public Synapse AddSynapse(IReceptor sendingNucleus, float weight = 1.0f) { - // Synapse synapse = new(sendingNucleus, weight); - // this.synapses.Add(synapse); - // return synapse; - // } - - // public virtual void UpdateState() { - // //UpdateState(new float3(0, 0, 0)); - // this.parent?.UpdateState(); - // } - - // public virtual void UpdateState(float3 inputValue) { - // float3 sum = inputValue; - // int n = 0; - - // //Applying the weight factgors - // foreach (Synapse synapse in this.synapses) { - // sum += synapse.weight * synapse.nucleus.outputValue; - - // // Perhaps synapses should be removed when the output value goes to 0.... - // if (lengthsq(synapse.nucleus.outputValue) != 0) - // n++; - // } - // if (this.average && n > 0) - // sum /= n; - - // // Activation function - // Vector3 result; - // switch (this.curvePreset) { - // case CurvePresets.Linear: - // result = sum; - // break; - // case CurvePresets.Sqrt: - // result = normalize(sum) * System.MathF.Sqrt(length(sum)); - // break; - // case CurvePresets.Power: - // result = normalize(sum) * System.MathF.Pow(length(sum), 2); - // break; - // case CurvePresets.Reciprocal: - // result = normalize(sum) * (1 / length(sum)); - // break; - // default: - // float activatedValue = this.curve.Evaluate(length(sum)); - // result = normalize(sum) * activatedValue; - // break; - // } - // UpdateResult(result); - // } - - // public virtual void UpdateStateIsolated() { - // UpdateStateIsolated(new float3(0, 0, 0)); - // } - public float3 bias = float3(0, 0, 0); public override void UpdateStateIsolated(float3 bias_unused) { float3 sum = this.bias; @@ -354,21 +238,4 @@ public class Neuron : Nucleus { //Debug.Log($"{this.name} processed stimulus"); this.bias = inputValue; } - - // public virtual void UpdateResult(Vector3 result) { - // // float d = Vector3.Distance(result, this.outputValue); - // // if (d < 0.5f) { - // // //Debug.Log($"insignificant update: {d}"); - // // return; - // // } - - // this.outputValue = result; - // if (lengthsq(outputValue) != 0) { - // Debug.Log($"{this.parent.name}.{this.name}: {this.outputValue}"); - // } - - // foreach (INucleus receiver in this.receivers) - // receiver.UpdateState(); - - // } } \ No newline at end of file