From 4235f260b4a8f29da4530c5c6dcbd5614bfcd0cd Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Fri, 8 May 2026 08:58:07 +0200 Subject: [PATCH] Removed commented out code --- Runtime/Scripts/Core/Cluster.cs | 201 -------------------------------- Runtime/Scripts/Core/Neuron.cs | 38 ------ Runtime/Scripts/Core/Nucleus.cs | 167 ++++++-------------------- 3 files changed, 37 insertions(+), 369 deletions(-) diff --git a/Runtime/Scripts/Core/Cluster.cs b/Runtime/Scripts/Core/Cluster.cs index e672bf0..e883575 100644 --- a/Runtime/Scripts/Core/Cluster.cs +++ b/Runtime/Scripts/Core/Cluster.cs @@ -194,87 +194,6 @@ namespace NanoBrain { } } - // /// - // /// Sort the nuclei in a correct evaluation order - // /// - // /// - // /// - // /// - // private List TopologicalSort(List nodes) { - // Dictionary inDegree = new(); - // foreach (Nucleus node in nodes) - // inDegree[node] = 0; // Initialize in-degree to zero - - // // Calculate in-degrees - // foreach (Nucleus node in nodes) { - // if (node is Cluster cluster) { - // foreach (Nucleus receiver in cluster.CollectReceivers()) - // inDegree[receiver]++; - // } - // else if (node is Neuron neuron) { - // foreach (Nucleus receiver in neuron.receivers) - // inDegree[receiver]++; - // } - // } - - // Queue queue = new(); - // foreach (Nucleus node in nodes) { - // if (inDegree[node] == 0) // Nodes with no dependencies - // queue.Enqueue(node); - // } - // // The queue basically stores all input nuclei? - - // List sortedOrder = new(); - // while (queue.Count > 0) { - // Nucleus current = queue.Dequeue(); - // sortedOrder.Add(current); // Process the node - - // if (current is Neuron neuron) { - // foreach (Nucleus receiver in neuron.receivers) { - // inDegree[receiver]--; - // if (inDegree[receiver] == 0) // If all dependencies resolved - // queue.Enqueue(receiver); - // } - // } - // else if (current is Cluster cluster) { - // foreach (Nucleus receiver in cluster.CollectReceivers()) { - // inDegree[receiver]--; - // if (inDegree[receiver] == 0) // If all dependencies resolved - // queue.Enqueue(receiver); - // } - // } - // } - - // // Check for cycles in the graph - // if (sortedOrder.Count != nodes.Count) - // throw new InvalidOperationException("Graph is not a DAG; a cycle exists."); - - // return sortedOrder; - // } - - - // public override Nucleus Clone(ClusterPrefab parent) { - // Cluster clone = new(this.prefab, parent); - - // foreach (Nucleus nucleus in this.nuclei) { - // if (nucleus is Neuron output) { - // foreach (Nucleus receiver in output.receivers) { - // int ix = GetNucleusIndex(this.nuclei, output); - // Debug.Log($"{output.name} -> {receiver.name}: {ix}"); - // if (ix < 0) - // continue; - - // if (clone.nuclei[ix] is not Neuron clonedOutput) - // continue; - - // clonedOutput.AddReceiver(receiver); - // } - // } - // } - - // return clone; - // } - /// \copydoc NanoBrain::Nucleus::ShallowCloneTo public override Nucleus ShallowCloneTo(Cluster parent) { // Clusters should not be cloned, but instantiated from the prefab.... @@ -442,46 +361,8 @@ namespace NanoBrain { thingClusters.Remove(thingId); } - // public bool SameSiblingsAs(Cluster[] otherSiblingClusters) { - // if (this.siblingClusters == null) - // return false; - // for (int ix = 0; ix < this.siblingClusters.Length; ix++) { - // if (this.siblingClusters[ix] != otherSiblingClusters[ix]) - // return false; - // } - // return true; - // } - - // public void AddArrayReceiver(Nucleus receiverToAdd, float weight = 1) { - // this.defaultOutput.AddReceiver(receiverToAdd, weight); - // // foreach (Cluster cluster in this.siblingClusters) { - // // cluster.defaultOutput.AddReceiver(receiverToAdd, weight); - // // } - - // } - #endregion ClusterArray - - // private List _inputs = null; - // public virtual List inputs { - // get { - // if (this._inputs == null) { - // this._inputs = new(); - // foreach (Nucleus nucleus in this.nuclei) { - // if (nucleus is not Neuron neuron) - // continue; - - // // inputs have no synapses - // if (neuron.synapses.Count == 0) - // this._inputs.Add(nucleus); - // } - // RefreshComputeOrders(); - // } - // return this._inputs; - // } - // } - /// /// This gives the order in which nuclei should be computed when a nucleus is updated /// @@ -700,30 +581,6 @@ namespace NanoBrain { selectedCluster.name = baseName + ": " + thingName; thingClusters[thingId] = selectedCluster; return lowestNeuron; - /* - // Find a sleeping cluster - // foreach (Cluster cluster in this.siblingClusters) { - // if (cluster.defaultOutput.isSleeping) { - // RemoveThingCluster(cluster); - // return cluster; - // } - // } - - // Find longest unused cluster - // Note this uses the default output... - Cluster unusedCluster = this.siblingClusters[0]; - for (int ix = 1; ix < this.siblingClusters.Length; ix++) { - if (this.siblingClusters[ix].defaultOutput.lastUpdate < unusedCluster.defaultOutput.lastUpdate) - unusedCluster = this.siblingClusters[ix]; - } - - RemoveThingCluster(unusedCluster); - //return unusedCluster; - - Cluster cluster = GetThingCluster(thingId, thingName); - Neuron neuron = cluster?.GetNeuron(neuronName); - return neuron; - */ } /// @@ -774,26 +631,6 @@ namespace NanoBrain { return receivers; } - /// - /// Collect all connections to receivers of signals from this cluster - /// - /// A list of pairs of the sending neuron in this cluster and the matching receiving nucleus - // public List<(Neuron, Nucleus)> CollectConnections() { - // List<(Neuron, Nucleus)> connections = new(); - - // foreach (Nucleus outputNucleus in this.nuclei) { - // if (outputNucleus is not Neuron output) - // continue; - - // foreach (Nucleus receiver in output.receivers) { - // // Only add receivers outside this cluster - // if (receiver.parent.prefab != this.prefab) - // connections.Add((output, receiver)); - // } - // } - // return connections; - // } - /// /// Collect all synapses of senders in another cluster of signals to this cluster /// @@ -813,35 +650,6 @@ namespace NanoBrain { return collectedSynapses; } - - // public void MoveReceivers(Cluster newCluster) { - // Debug.Log($"Move receivers for {this.name} to {newCluster.name}"); - // foreach (Nucleus outputNucleus in this.nuclei) { - // if (outputNucleus is not Neuron output) - // continue; - - // // Find the existing output in the new cluster - // if (newCluster.GetNucleus(output.name) is not Neuron newOutput) { - // Debug.LogWarning($"Could not find output {this.name}.{output.name} in {newCluster.name}"); - // continue; - // } - // Debug.Log($"Check {this.name}.{output.name} receivers"); - // Nucleus[] receivers = output.receivers.ToArray(); - // foreach (Nucleus receiver in receivers) { - // if (receiver.parent.prefab != this.prefab) { - // // Replace synapse with new synapse - // // to the new cluster - // Debug.Log($"move {receiver.name} from {this.name}.{output.name} to {newCluster.name}.{newOutput.name}"); - // if (receiver is not Neuron receiverNeuron) - // continue; - // Synapse synapse = receiverNeuron.GetSynapse(output); - // newOutput.AddReceiver(receiver, synapse.weight); - // output.RemoveReceiver(receiver); - // } - // } - // } - // } - #endregion Receivers #region Update @@ -872,7 +680,6 @@ namespace NanoBrain { } } } - //UpdateNuclei(); } /// \copydoc NanoBrain::Nucleus::UpdateStateIsolated @@ -880,12 +687,6 @@ namespace NanoBrain { throw new Exception("Cluster should not be updated!"); } - // Don't think this does anything anymore... - // public override void UpdateNuclei() { - // foreach (Nucleus nucleus in this.nuclei) - // nucleus.UpdateNuclei(); - // } - #endregion Update /// @@ -895,8 +696,6 @@ namespace NanoBrain { public void Refresh() { // This should not be needed, but somehow somewhere the parent is changed... foreach (Nucleus nucleus in this.nuclei) { - // if (nucleus is not Neuron neuron) - // continue; nucleus.parent = this; } RefreshOutputs(); diff --git a/Runtime/Scripts/Core/Neuron.cs b/Runtime/Scripts/Core/Neuron.cs index 2fe073b..eba9d43 100644 --- a/Runtime/Scripts/Core/Neuron.cs +++ b/Runtime/Scripts/Core/Neuron.cs @@ -25,21 +25,6 @@ namespace NanoBrain { this.name = name; this.parent?.nuclei.Add(this); } - /// - /// Create a new Neuron in a Cluster Prefab - /// - /// The Cluster Preafb in which the new Neuron should be created - /// The name of the new Neuron - // public Neuron(ClusterPrefab prefab, string name) { - // this.clusterPrefab = prefab; - // this.name = name; - // if (this.clusterPrefab != null) { - // this.clusterPrefab.cluster.nuclei.Add(this); - // this.clusterPrefab.cluster.RefreshOutputs(); - // } - // else - // Debug.LogError("No prefab when adding neuron to prefab"); - // } #region Serialization @@ -72,10 +57,6 @@ namespace NanoBrain { return synapse; } - // public Synapse AddSynapse(ClusterPrefab clusterPrefab, string neuronName, float weight = 1) { - - // } - /// /// Find a synapse /// @@ -394,20 +375,6 @@ namespace NanoBrain { return clone; } - // \copydoc NanoBrain::Nucleus::Clone - // public override Nucleus Clone(ClusterPrefab prefab) { - // Neuron clone = new(prefab.cluster, this.name); - // CloneFields(clone); - // foreach (Synapse synapse in this.synapses) { - // Synapse clonedSynapse = clone.AddSynapse(synapse.neuron); - // clonedSynapse.weight = synapse.weight; - // } - // foreach (Nucleus receiver in this.receivers) { - // clone.AddReceiver(receiver); - // } - // return clone; - // } - /// /// Copy relevant fields of this neuron to the given neuron /// @@ -474,11 +441,6 @@ namespace NanoBrain { this.lastUpdate = Time.time; } - // protected void CheckSleepingSynapses() { - // foreach (Synapse synapse in this.synapses) - // synapse.neuron.SleepCheck(); - // } - #region Combinator #if UNITY_MATHEMATICS diff --git a/Runtime/Scripts/Core/Nucleus.cs b/Runtime/Scripts/Core/Nucleus.cs index 4864165..5302c19 100644 --- a/Runtime/Scripts/Core/Nucleus.cs +++ b/Runtime/Scripts/Core/Nucleus.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using UnityEngine; /// @@ -7,143 +6,51 @@ using UnityEngine; /// namespace NanoBrain { -/// -/// A Nucleus is a basic element in a brain cluster -/// -[Serializable] -public abstract class Nucleus { /// - /// The name of the Nucleus + /// A Nucleus is a basic element in a brain cluster /// - public string name; + [Serializable] + public abstract class Nucleus { + /// + /// The name of the Nucleus + /// + public string name; - // [NonSerialized] - // public Nucleus prefabNucleus; + /// + /// The cluster instance in which the nucleus is located + /// + [SerializeReference] + public Cluster parent; - /// - /// The cluster prefab in which the nucleus is located - /// - // [SerializeReference] - // public ClusterPrefab clusterPrefab; + /// + /// Function to make a partial clone of this nucleus + /// + /// The cluster in which the cloned nucleus should be placed + /// + public abstract Nucleus ShallowCloneTo(Cluster parent); - /// - /// The cluster instance in which the nucleus is located - /// - [SerializeReference] - public Cluster parent; + /// + /// The types of Nucleus + /// + public enum Type { + None, + Neuron, + MemoryCell, + Cluster, + //Receptor, + //ClusterReceptor, + //ClusterArray, + } - /// - /// Toggle for printing debugging trace data - /// - //public bool trace = false; + #region Update - /// - /// Function to make a partial clone of this nucleus - /// - /// The cluster in which the cloned nucleus should be placed - /// - public abstract Nucleus ShallowCloneTo(Cluster parent); - /// - /// Function to clone a nucleus to a Cluster prefab - /// - /// - /// - // public abstract Nucleus Clone(ClusterPrefab prefab); + /// + /// Update the state without updating other Nuclei + /// + public abstract void UpdateStateIsolated(); + + #endregion Update - /// - /// The types of Nucleus - /// - public enum Type { - None, - Neuron, - MemoryCell, - Cluster, - //Receptor, - //ClusterReceptor, - //ClusterArray, } - // public virtual void Initialize() {} - - // #region Synapses - - // /// - // /// The bias of the nucleus - // /// - // /// The bias which a value which is always added to the combined value of the nucleus - // /// It does not have a synapse and therefore no weight of source nucleus - // //public Vector3 bias = Vector3.zero; - - // [SerializeField] - // private List _synapses = new(); - // /// - // /// The synapses of the nucleus - // /// - // public List synapses => _synapses; - - // /// - // /// Add a new synapse to this nuclues - // /// - // /// The nucleus from which the signals may originate - // /// The weight applied to the input. Default value = 1 - // /// The created Synapse - // /// This will add a new input to this nucleus with the given weight. - // public Synapse AddSynapse(Neuron sendingNucleus, float weight = 1) { - // Synapse synapse = new(sendingNucleus, weight); - // this.synapses.Add(synapse); - // return synapse; - // } - - // // public Synapse AddSynapse(ClusterPrefab clusterPrefab, string neuronName, float weight = 1) { - - // // } - - // /// - // /// Find a synapse - // /// - // /// The sender of the input to the Synapse - // /// The found Synapse or null when the sender has no synapse to this nucleus. - // public Synapse GetSynapse(Nucleus sender) { - // foreach (Synapse synapse in this.synapses) - // if (synapse.neuron == sender) - // return synapse; - // return null; - // } - - // /// - // /// Remove a synapse from a Nucleus - // /// - // /// Remote the synapse connecting to this Nucleus - // public void RemoveSynapse(Nucleus sendingNucleus) { - // this.synapses.RemoveAll(synapse => synapse.neuron == sendingNucleus); - // } - - // #endregion Synapses - - #region Update - - /// - /// Update the state without updating other Nuclei - /// - public abstract void UpdateStateIsolated(); - - /// - /// Update the state and recursively all Nuclei receiving data from this Nucleus - /// - public virtual void UpdateNuclei() { - } - - // /// - // /// Set the bias, recalculate the output and update all Nuclei receiving from this Nucleus - // /// - // /// - // public virtual void SetBias(Vector3 inputValue) { - // this.bias = inputValue; - // this.parent.UpdateFromNucleus(this); - // } - - #endregion Update - -} - } \ No newline at end of file