From 8a414816e51ab5d5aed3c220cfb51e0a342ad2e9 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Fri, 30 Jan 2026 11:05:00 +0100 Subject: [PATCH] subcluster seems to work --- Cluster.cs | 21 +++++++++++++++------ INucleus.cs | 2 +- Neuron.cs | 10 ++++------ Receptor.cs | 6 +++--- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/Cluster.cs b/Cluster.cs index 6bc11aa..9d92c1c 100644 --- a/Cluster.cs +++ b/Cluster.cs @@ -110,12 +110,12 @@ public class Cluster : INucleus { // Now clone the connections for (int nucleusIx = 0; nucleusIx < nucleiArray.Length; nucleusIx++) { IReceptor receptor = nucleiArray[nucleusIx]; - IReceptor clonedReceptor = clonedNuclei[nucleusIx]; - if (clonedReceptor == null) + IReceptor clonedSender = clonedNuclei[nucleusIx]; + if (clonedSender == null) continue; // Copy the receivers, which will also create the synapses - foreach (INucleus receiver in nucleiArray[nucleusIx].receivers) { + foreach (INucleus receiver in receptor.receivers) { int ix = GetNucleusIndex(nucleiArray, receiver); if (ix < 0) continue; @@ -123,7 +123,16 @@ public class Cluster : INucleus { if (clonedNuclei[ix] is not INucleus clonedReceiver) continue; - clonedReceptor.AddReceiver(clonedReceiver); + // Find the synapse for the weight + float weight = 1; + foreach (Synapse synapse in receiver.synapses) { + if (synapse.nucleus == receptor) { + weight = synapse.weight; + break; + } + } + + clonedSender.AddReceiver(clonedReceiver, weight); } } } @@ -287,9 +296,9 @@ public class Cluster : INucleus { set { _receivers = value; } } - public virtual void AddReceiver(INucleus receivingNucleus) { + public virtual void AddReceiver(INucleus receivingNucleus, float weight = 1) { this._receivers.Add(receivingNucleus); - receivingNucleus.AddSynapse(this); + receivingNucleus.AddSynapse(this, weight); } public void RemoveReceiver(INucleus receiverNucleus) { diff --git a/INucleus.cs b/INucleus.cs index cd4ba50..13590a1 100644 --- a/INucleus.cs +++ b/INucleus.cs @@ -33,7 +33,7 @@ public interface IReceptor { // Receivers public List receivers { get; set; } - public void AddReceiver(INucleus receiver); + public void AddReceiver(INucleus receiver, float weight = 1); public void RemoveReceiver(INucleus receiverNucleus); #endregion static diff --git a/Neuron.cs b/Neuron.cs index 9c153ef..db67206 100644 --- a/Neuron.cs +++ b/Neuron.cs @@ -181,10 +181,6 @@ public class Neuron : INucleus { // Debug.LogError("No neuroid network"); } - // public Neuron(string name) { - // this._name = name; - // } - // this clone the nucleus without the synapses and receivers public virtual IReceptor ShallowCloneTo(Cluster newParent) { Neuron clone = new(newParent, this.name) { @@ -246,9 +242,9 @@ public class Neuron : INucleus { return clone; } - public virtual void AddReceiver(INucleus receivingNucleus) { + public virtual void AddReceiver(INucleus receivingNucleus, float weight = 1) { this._receivers.Add(receivingNucleus); - receivingNucleus.AddSynapse(this); + receivingNucleus.AddSynapse(this, weight); } public void RemoveReceiver(INucleus receiverNucleus) { @@ -294,6 +290,7 @@ public class Neuron : INucleus { float3 sum = inputValue;//new(0, 0, 0); int n = 0; + Debug.Log($"{this.parent.name}.{this.name}: {inputValue}"); //Applying the weight factgors foreach (Synapse synapse in this.synapses) { if (synapse.nucleus == this) { @@ -301,6 +298,7 @@ public class Neuron : INucleus { synapse.weight = deltaTime; } sum += synapse.weight * synapse.nucleus.outputValue; + Debug.Log($" {synapse.weight} * {synapse.nucleus.outputValue}"); // Perhaps synapses should be removed when the output value goes to 0.... if (lengthsq(synapse.nucleus.outputValue) != 0) n++; diff --git a/Receptor.cs b/Receptor.cs index 0baec36..d7321bc 100644 --- a/Receptor.cs +++ b/Receptor.cs @@ -102,9 +102,9 @@ public class Receptor : IReceptor { protected int[] thingIds; // every receiver can handle a thing with this id - public virtual void AddReceiver(INucleus receivingNucleus) { + public virtual void AddReceiver(INucleus receivingNucleus, float weight = 1) { this._receivers.Add(receivingNucleus); - receivingNucleus.AddSynapse(this); + receivingNucleus.AddSynapse(this, weight); } public void RemoveReceiver(INucleus receiverNucleus) { @@ -142,7 +142,7 @@ public class Receptor : IReceptor { this.localPosition = newLocalPositionVector; if (this._receivers == null) return; - + thingIds ??= new int[this._receivers.Count]; int receiverIx = 0;