diff --git a/Editor/ClusterEditor.cs b/Editor/ClusterEditor.cs index 868297d..3086b0a 100644 --- a/Editor/ClusterEditor.cs +++ b/Editor/ClusterEditor.cs @@ -180,12 +180,7 @@ namespace NanoBrain { else { string newName = EditorGUILayout.TextField(this.currentNucleus.name, boldTextFieldStyle); if (newName != this.currentNucleus.name) { - Nucleus prefabNucleus = this.prefab.GetNucleus(this.currentNucleus.name); - prefabNucleus.name = newName; - // This changes it in the temporary cluster instance this.currentNucleus.name = newName; - this.prefab.cluster.RefreshOutputs(); - // outputsPopup.choices = this.prefab.outputs.Select(output => output.name).ToList(); anythingChanged = true; } } diff --git a/Runtime/Scripts/Core/Cluster.cs b/Runtime/Scripts/Core/Cluster.cs index b25222c..9106984 100644 --- a/Runtime/Scripts/Core/Cluster.cs +++ b/Runtime/Scripts/Core/Cluster.cs @@ -188,6 +188,11 @@ namespace NanoBrain { foreach (Cluster sibling in siblings) sibling.siblingClusters = siblingClusters; } + + // Ensure that all neurons are computed to initialize bias + foreach (Nucleus clonedNucleus in clonedNuclei) { + clonedNucleus.UpdateStateIsolated(); + } } /* for (int nucleusIx = 0; nucleusIx < clonedNuclei.Length; nucleusIx++) { @@ -613,31 +618,26 @@ namespace NanoBrain { if (neuron.synapses.Count == 0) this._inputs.Add(nucleus); } - ComputeOrders(); + RefreshComputeOrders(); } return this._inputs; } } - public Dictionary> computeOrders = new(); - private void ComputeOrders() { - foreach (Nucleus nucleus in this.nuclei) { - // if (nucleus is Cluster cluster) { - // List synapses = this.CollectSynapsesTo(cluster); - // foreach (Synapse synapse in synapses) { - // computeOrders[synapse.neuron] = TopologicalSort2(synapse.neuron); - // Debug.Log($"{this.baseName}: Order for {cluster.baseName}.{synapse.neuron.name}"); - // } - // // List receivers = cluster.CollectReceivers(); - // // foreach (Nucleus receiver in receivers) - // // computeOrders[receiver] = TopologicalSort2(receiver); - // } - // else { - computeOrders[nucleus] = TopologicalSort2(nucleus); - //Debug.Log($"{this.baseName} Order for {nucleus.name}"); - // } + private Dictionary> _computeOrders; + public Dictionary> computeOrders { + get { + if (_computeOrders == null || _computeOrders.Count == 0) { + _computeOrders = new(); + foreach (Nucleus nucleus in this.nuclei) + _computeOrders[nucleus] = TopologicalSort2(nucleus); + } + return _computeOrders; } } + public void RefreshComputeOrders() { + this._computeOrders = null; + } private List TopologicalSort2(Nucleus startNode) { Dictionary inDegree = new(); @@ -711,7 +711,7 @@ namespace NanoBrain { protected List _outputs = null; public List outputs { get { - if (this._outputs == null) { + if (this._outputs == null || this._outputs.Count == 0) { this._outputs = new(); foreach (Nucleus nucleus in this.nuclei) { if (nucleus is Neuron neuron && neuron.receivers.Count == 0) @@ -911,6 +911,7 @@ namespace NanoBrain { public void Refresh() { RefreshOutputs(); + RefreshComputeOrders(); } } diff --git a/Runtime/Scripts/Core/Neuron.cs b/Runtime/Scripts/Core/Neuron.cs index 1c2144f..02fa2df 100644 --- a/Runtime/Scripts/Core/Neuron.cs +++ b/Runtime/Scripts/Core/Neuron.cs @@ -50,7 +50,6 @@ namespace NanoBrain { /// It does not have a synapse and therefore no weight of source nucleus public Vector3 bias = Vector3.zero; - #region Synapses [SerializeField] @@ -329,7 +328,6 @@ namespace NanoBrain { } protected virtual void CloneFields(Neuron clone) { - clone.parent = this.parent; clone.bias = this.bias; clone.combinator = this.combinator; clone.curve = this.curve;