From d562c7192b3e0a4f330e7dc4e256ff58bf05f853 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Tue, 10 Feb 2026 12:55:25 +0100 Subject: [PATCH] Simplify/improve UpdateStateIsolated --- Cluster.cs | 22 +++++++++------------- Editor/NanoBrain_Editor.cs | 9 +++++++++ MemoryCell.cs | 12 ++++++------ Neuron.cs | 2 +- Nucleus.cs | 8 ++++---- Pulsar.cs | 2 +- Selector.cs | 4 ++-- 7 files changed, 32 insertions(+), 27 deletions(-) diff --git a/Cluster.cs b/Cluster.cs index d65656a..3aa1945 100644 --- a/Cluster.cs +++ b/Cluster.cs @@ -91,9 +91,10 @@ public class Cluster : Nucleus { foreach (Nucleus prefabArrayNucleus in prefabNucleus.array.nuclei) { int arrayNucleusIx = GetNucleusIndex(prefabNuclei, prefabArrayNucleus); if (arrayNucleusIx >= 0) { - Nucleus clonedArrayNucleus = clonedNuclei[arrayNucleusIx]; - clonedArray.nuclei[arrayIx] = clonedArrayNucleus; - } else { + Nucleus clonedArrayNucleus = clonedNuclei[arrayNucleusIx]; + clonedArray.nuclei[arrayIx] = clonedArrayNucleus; + } + else { Debug.LogError($" Could not find prefab nuclues {prefabNucleus.name} in the clones"); } arrayIx++; @@ -250,11 +251,7 @@ public class Cluster : Nucleus { #region Update public override void UpdateStateIsolated() { - float3 bias = new(0, 0, 0); - UpdateStateIsolated(bias); - } - public override void UpdateStateIsolated(float3 bias) { - Vector3 sum = bias; + Vector3 sum = this.bias; //Applying the weight factors foreach (Synapse synapse in this.synapses) { @@ -264,12 +261,11 @@ public class Cluster : Nucleus { } } - this.inputs[0].UpdateStateIsolated(sum); - foreach (Nucleus receptor in this.sortedNuclei) { - if (receptor is Nucleus nucleus && nucleus != this.inputs[0]) - nucleus.UpdateStateIsolated(); - } + foreach (Nucleus nucleus in this.sortedNuclei) + nucleus.UpdateStateIsolated(); + this.outputValue = this.output.outputValue; + this.stale = 0; UpdateNuclei(); } diff --git a/Editor/NanoBrain_Editor.cs b/Editor/NanoBrain_Editor.cs index 319dc2b..6c37746 100644 --- a/Editor/NanoBrain_Editor.cs +++ b/Editor/NanoBrain_Editor.cs @@ -1,4 +1,6 @@ using UnityEditor; +using UnityEditor.UIElements; + using UnityEngine; using UnityEngine.UIElements; @@ -27,6 +29,13 @@ public class NanoBrainComponent_Editor : Editor { VisualElement root = new(); + if (Application.isPlaying == false) { + PropertyField brainField = new(brainProp) { + label = "Nano Brain" + }; + root.Add(brainField); + } + ClusterInspector.CreateInspector(root, brain.prefab, brain.output, component.gameObject); if (Application.isPlaying == false) diff --git a/MemoryCell.cs b/MemoryCell.cs index dd69652..796c6d8 100644 --- a/MemoryCell.cs +++ b/MemoryCell.cs @@ -25,13 +25,13 @@ public class MemoryCell : Neuron { private float3 _memorizedValue; private float _memorizedTime; - public override void UpdateStateIsolated() { - float3 bias = new(0, 0, 0); - UpdateStateIsolated(bias); - } - public override void UpdateStateIsolated(float3 bias) { + // public override void UpdateStateIsolated() { + // float3 bias = new(0, 0, 0); + // UpdateStateIsolated(bias); + // } + public override void UpdateStateIsolated() { //float3 bias) { // A memorycell does not have an activation function - Vector3 result = bias; + Vector3 result = this.bias; int n = 0; //Applying the weight factgors diff --git a/Neuron.cs b/Neuron.cs index bc6bccd..2022a78 100644 --- a/Neuron.cs +++ b/Neuron.cs @@ -200,7 +200,7 @@ public class Neuron : Nucleus { } //public float3 bias = float3(0, 0, 0); - public override void UpdateStateIsolated(float3 bias_unused) { + public override void UpdateStateIsolated() { //float3 bias_unused) { Vector3 sum = this.bias; int n = 0; diff --git a/Nucleus.cs b/Nucleus.cs index a72b5dc..baef87e 100644 --- a/Nucleus.cs +++ b/Nucleus.cs @@ -98,11 +98,11 @@ public abstract class Nucleus { #region Update - public virtual void UpdateStateIsolated() { - UpdateStateIsolated(new float3(0, 0, 0)); - } + public abstract void UpdateStateIsolated(); + // UpdateStateIsolated(new float3(0, 0, 0)); + // } - public abstract void UpdateStateIsolated(float3 bias); + //public abstract void UpdateStateIsolated(float3 bias); // public virtual void UpdateStateIsolated(float3 bias) { // } diff --git a/Pulsar.cs b/Pulsar.cs index 889406c..d4f4104 100644 --- a/Pulsar.cs +++ b/Pulsar.cs @@ -39,7 +39,7 @@ public class Pulsar : Neuron { return clone; } - public override void UpdateStateIsolated(float3 _bias) { + public override void UpdateStateIsolated() { //float3 _bias) { float3 product = this.bias; //Applying the weight factors diff --git a/Selector.cs b/Selector.cs index d4893fe..ed7fae4 100644 --- a/Selector.cs +++ b/Selector.cs @@ -18,8 +18,8 @@ public class Selector : Neuron { return clone; } - public override void UpdateStateIsolated(float3 bias) { - float3 max = bias; + public override void UpdateStateIsolated() { //float3 bias) { + float3 max = this.bias; float maxSqrLength = lengthsq(max); //Applying the weight factors