From 14a786246c8700f83ee22fcbb806138845831a0e Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Mon, 5 Jan 2026 17:55:09 +0100 Subject: [PATCH] Simplifying stale nuclei --- Assets/NanoBrain/Neuroid.cs | 3 +- Assets/NanoBrain/Nucleus.cs | 30 ++++++++++++++----- Assets/NanoBrain/Perceptoid.cs | 6 ++-- Assets/NanoBrain/SensoryNeuroid.cs | 6 ++-- Assets/NanoBrain/VisualEditor/NanoBrainObj.cs | 6 ++-- Assets/Scenes/Boids/Prefabs/Boid.prefab | 2 +- .../Scenes/Boids/Scripts/SwarmingNucleus.cs | 2 +- 7 files changed, 39 insertions(+), 16 deletions(-) diff --git a/Assets/NanoBrain/Neuroid.cs b/Assets/NanoBrain/Neuroid.cs index d7cd1ac..0bd9c90 100644 --- a/Assets/NanoBrain/Neuroid.cs +++ b/Assets/NanoBrain/Neuroid.cs @@ -93,7 +93,8 @@ public class Neuroid : Nucleus { result /= this.synapses.Count; this.outputValue = Spherical.FromVector3(result); - this.stale = 0; + //this.stale = 0; + this.Refresh(); foreach (Receiver receiver in this.receivers) { if (receiver.nucleus is Neuroid neuroid) diff --git a/Assets/NanoBrain/Nucleus.cs b/Assets/NanoBrain/Nucleus.cs index 9c195ca..b114911 100644 --- a/Assets/NanoBrain/Nucleus.cs +++ b/Assets/NanoBrain/Nucleus.cs @@ -64,10 +64,26 @@ public class Nucleus { public NanoBrainObj brain { get; set; } - public virtual Spherical outputValue { get; set; } + private Spherical _outputValue; + public Spherical outputValue //{ get; set; } + { + get { return _outputValue; } + set { + //Refresh(); + this.stale = 0; + _outputValue = value; + } + } [System.NonSerialized] - public int stale = 0; + private int stale = 0; + public bool isSleeping => this.stale > 2; + public void Refresh() { + //this.stale = 0; + } + public void IncreaseAge() { + this.stale++; + } [System.NonSerialized] public int layerIx; @@ -122,11 +138,11 @@ public class Nucleus { this.SetWeight(input, weight); } - public bool isSleeping { - get { - return this.stale > 2; - } - } + // public bool isSleeping { + // get { + // return this.stale > 2; + // } + // } public bool SynapseExists(Nucleus nucleus) { foreach (Synapse synapse in synapses) { diff --git a/Assets/NanoBrain/Perceptoid.cs b/Assets/NanoBrain/Perceptoid.cs index c2acb1f..75fd6e2 100644 --- a/Assets/NanoBrain/Perceptoid.cs +++ b/Assets/NanoBrain/Perceptoid.cs @@ -118,7 +118,8 @@ public class Perceptoid : Neuroid { foreach (Receiver receiver in this.receivers) if (receiver.nucleus is Neuroid neuroid) neuroid.SetInput(this); - this.stale = 0; + //this.stale = 0; + this.Refresh(); } public void UpdateState(int thingId, Spherical receptorValue) { @@ -142,7 +143,8 @@ public class Perceptoid : Neuroid { foreach (Receiver receiver in this.receivers) if (receiver.nucleus is Neuroid neuroid) neuroid.SetInput(this); - this.stale = 0; + //this.stale = 0; + this.Refresh(); } diff --git a/Assets/NanoBrain/SensoryNeuroid.cs b/Assets/NanoBrain/SensoryNeuroid.cs index aad0936..1c12129 100644 --- a/Assets/NanoBrain/SensoryNeuroid.cs +++ b/Assets/NanoBrain/SensoryNeuroid.cs @@ -87,7 +87,8 @@ public class SensoryNeuroid : Neuroid { foreach (Receiver receiver in this.receivers) if (receiver.nucleus is Neuroid neuroid) neuroid.SetInput(this); - this.stale = 0; + //this.stale = 0; + this.Refresh(); } } @@ -120,7 +121,8 @@ public class VelocityNeuroid : Neuroid { // No activation function... this.outputValue = Spherical.FromVector3(velocity); - this.stale = 0; + //this.stale = 0; + this.Refresh(); foreach (Receiver receiver in receivers) { if (receiver.nucleus is Neuroid neuroid) diff --git a/Assets/NanoBrain/VisualEditor/NanoBrainObj.cs b/Assets/NanoBrain/VisualEditor/NanoBrainObj.cs index 096ff4b..970a2ac 100644 --- a/Assets/NanoBrain/VisualEditor/NanoBrainObj.cs +++ b/Assets/NanoBrain/VisualEditor/NanoBrainObj.cs @@ -32,12 +32,14 @@ public class NanoBrainObj : ScriptableObject, ISerializationCallbackReceiver { public void UpdateNuclei() { foreach (Nucleus nucleus in nuclei) { - nucleus.stale++; + //nucleus.stale++; + nucleus.IncreaseAge(); if (nucleus.isSleeping) nucleus.outputValue = Spherical.zero; } foreach (Perceptoid perception in perceptei) { - perception.stale++; + //perception.stale++; + perception.IncreaseAge(); if (perception.isSleeping) perception.outputValue = Spherical.zero; } diff --git a/Assets/Scenes/Boids/Prefabs/Boid.prefab b/Assets/Scenes/Boids/Prefabs/Boid.prefab index 82bf014..37277d0 100644 --- a/Assets/Scenes/Boids/Prefabs/Boid.prefab +++ b/Assets/Scenes/Boids/Prefabs/Boid.prefab @@ -179,4 +179,4 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 92f34a5e4027a1dc39efd8ce63cf6aba, type: 3} m_Name: m_EditorClassIdentifier: Assembly-CSharp::NanoBrainComponent - defaultBrain: {fileID: 11400000, guid: af8d90b8b4b9dcad7837130c4143d91c, type: 2} + defaultBrain: {fileID: 11400000, guid: fc1a4800a8c531eb4855b436bc9084ae, type: 2} diff --git a/Assets/Scenes/Boids/Scripts/SwarmingNucleus.cs b/Assets/Scenes/Boids/Scripts/SwarmingNucleus.cs index bbe6200..a269b01 100644 --- a/Assets/Scenes/Boids/Scripts/SwarmingNucleus.cs +++ b/Assets/Scenes/Boids/Scripts/SwarmingNucleus.cs @@ -9,7 +9,7 @@ public class Swarming : Nucleus { public Neuroid output; - public override Spherical outputValue { get => output.outputValue; set => output.outputValue = value; } + //public override Spherical outputValue { get => output.outputValue; set => output.outputValue = value; } public Swarming(NanoBrainObj brain, Perception perception, SwarmControl sc) : base("Swarming Nucleus") { this.cohesion = new(brain, "Cohesion") { inverse = false };