diff --git a/Cluster.cs b/Cluster.cs index 521a75c..22c52db 100644 --- a/Cluster.cs +++ b/Cluster.cs @@ -339,10 +339,18 @@ public class Cluster : Nucleus { } public Nucleus GetNucleus(string nucleusName) { - foreach (Nucleus receptor in this.nuclei) { - if (receptor is Nucleus nucleus) - if (nucleus.name == nucleusName) - return nucleus; + foreach (Nucleus nucleus in this.nuclei) { + if (nucleus.name == nucleusName) + return nucleus; + } + return null; + } + + public Receptor GetReceptor(string receptorName) { + foreach (Nucleus nucleus in this.nuclei) { + if (nucleus is Receptor receptor) + if (receptor.name == receptorName) + return receptor; } return null; } diff --git a/Neuron.cs b/Neuron.cs index e32a081..315fc21 100644 --- a/Neuron.cs +++ b/Neuron.cs @@ -45,12 +45,6 @@ public class Neuron : Nucleus { public CurvePresets curvePreset { get { return _curvePreset; } set { - // if (this.array != null && this.array.nuclei != null) { - // foreach (Neuron nucleus in this.array.nuclei.Cast()) { - // nucleus._curvePreset = value; - // nucleus.curve = GenerateCurve(); - // } - // } _curvePreset = value; this.curve = GenerateCurve(); } @@ -196,7 +190,6 @@ public class Neuron : Nucleus { foreach (Synapse synapse in this.synapses) sum += synapse.weight * synapse.nucleus.outputValue; return sum; - //this.outputValue = Activation(sum); } public float3 CombinatorProduct() { @@ -204,7 +197,6 @@ public class Neuron : Nucleus { foreach (Synapse synapse in this.synapses) product *= synapse.weight * synapse.nucleus.outputValue; return product; - //this.outputValue = Activation(product); } public float3 CombinatorMax() { diff --git a/Nucleus.cs b/Nucleus.cs index 6ce9900..57ad5f4 100644 --- a/Nucleus.cs +++ b/Nucleus.cs @@ -90,44 +90,19 @@ public abstract class Nucleus { #endregion Receivers - // [SerializeReference] - // private NucleusArray _array; - // public NucleusArray array { - // get { return _array; } - // set { _array = value; } - // } - #region Update public abstract void UpdateStateIsolated(); public virtual void UpdateNuclei() { - // if (this.array == null || this.array.nuclei == null || this.array.nuclei.Length <= 1) - return; - - // this.stale++; - // if (this.stale > staleValueForSleep) { - // //Debug.Log($"{this.name} goes to sleep, stale = {this.stale}"); - // _outputValue = Vector3.zero; - // } } - public virtual void ProcessStimulus(Vector3 inputValue, int thingId = 0, string thingName = null) { - //this.array.ProcessStimulus(thingId, inputValue, thingName); - // this.ProcessStimulus(inputValue); + public virtual void SetBias(Vector3 inputValue) { this.stale = 0; this.bias = inputValue; this.parent.UpdateFromNucleus(this); } - // public virtual void ProcessStimulus(int thingId, Vector3 inputValue, string thingName = null) { - // // this.array.ProcessStimulus(thingId, inputValue, thingName); - // // this.ProcessStimulus(inputValue); - // this.stale = 0; - // this.bias = inputValue; - // this.parent.UpdateFromNucleus(this); - // } - #endregion Update } \ No newline at end of file diff --git a/NucleusArray.cs b/NucleusArray.cs index 5ff9876..48595b5 100644 --- a/NucleusArray.cs +++ b/NucleusArray.cs @@ -130,7 +130,7 @@ public class NucleusArray { // Remove a thing-receiver connection when the nucleus is inactive List receiversToRemove = new(); foreach (KeyValuePair item in thingReceivers) { - if (item.Value.isSleeping) + if (item.Value != null && item.Value.isSleeping) receiversToRemove.Add(item.Key); } foreach (int thingId in receiversToRemove) { diff --git a/Receptor.cs b/Receptor.cs index bc92f57..34c511c 100644 --- a/Receptor.cs +++ b/Receptor.cs @@ -30,7 +30,6 @@ public class Receptor : Neuron { set { _array = value; } } - public override void UpdateStateIsolated() { this.outputValue = this.bias; } @@ -43,7 +42,8 @@ public class Receptor : Neuron { } } - public override void ProcessStimulus(Vector3 inputValue, int thingId = 0, string thingName = null) { - this.array.ProcessStimulus(thingId, inputValue, thingName); + public virtual void ProcessStimulus(Vector3 inputValue, int thingId = 0, string thingName = null) { + this.array ??= new NucleusArray(this.parent); + this.array.ProcessStimulus(thingId, inputValue, thingName); } } \ No newline at end of file diff --git a/ReceptorArray.cs b/ReceptorArray.cs index 1c7edeb..3ac96aa 100644 --- a/ReceptorArray.cs +++ b/ReceptorArray.cs @@ -141,7 +141,7 @@ public class ReceptorArray : Nucleus { // public override void ProcessStimulus(int thingId, Vector3 inputValue, string thingName = null) { // ProcessStimulus(inputValue, thingId, thingName); // } - public override void ProcessStimulus(Vector3 inputValue, int thingId = 0, string thingName = null) { + public virtual void ProcessStimulus(Vector3 inputValue, int thingId = 0, string thingName = null) { CleanupReceivers(); if (!thingReceivers.TryGetValue(thingId, out Nucleus selectedReceiver)) { //Debug.Log($" no receiver found for {thingId}"); diff --git a/Scripts/Experimental/SelectorBrain.cs b/Scripts/Experimental/SelectorBrain.cs index 282305a..08b21f6 100644 --- a/Scripts/Experimental/SelectorBrain.cs +++ b/Scripts/Experimental/SelectorBrain.cs @@ -5,11 +5,11 @@ public class SelectorBrain : NanoBrain { public Vector3 input2; public Vector3 output; - public Nucleus receptor; + public Receptor receptor; //public Nucleus receptor2; protected void Awake() { - receptor = this.brain.GetNucleus("Selector"); + receptor = this.brain.GetReceptor("Selector"); //receptor2 = this.brain.GetNucleus("Selector"); }