From 133804a154650e543cf9a8db553a20193e41a894 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Tue, 26 May 2026 09:02:20 +0200 Subject: [PATCH] Cleanup --- Runtime/Scripts/Core/Cluster.cs | 54 +------ Runtime/Scripts/Core/Neuron.cs | 142 ------------------ .../ScriptableObjects/ClusterPrefab.cs | 9 -- 3 files changed, 3 insertions(+), 202 deletions(-) diff --git a/Runtime/Scripts/Core/Cluster.cs b/Runtime/Scripts/Core/Cluster.cs index e588f85..e2cd174 100644 --- a/Runtime/Scripts/Core/Cluster.cs +++ b/Runtime/Scripts/Core/Cluster.cs @@ -85,8 +85,6 @@ namespace NanoBrain { this.parent = parent; this.parent?.nuclei.Add(this); ClonePrefab(); - // _ = this.inputs; - //this.sortedNuclei = TopologicalSort(this.nuclei); } /// @@ -102,8 +100,6 @@ namespace NanoBrain { this.parent = parent.cluster; ClonePrefab(); - // _ = this.inputs; - //this.sortedNuclei = TopologicalSort(this.nuclei); } /// @@ -169,15 +165,11 @@ namespace NanoBrain { } } - //if (Application.isPlaying) { - // Only create cluster siblings at runtime foreach (Nucleus clonedNucleus in clonedNuclei) { if (clonedNucleus is not Cluster clonedCluster) continue; - List siblings = new() { - clonedCluster - }; + List siblings = new() { clonedCluster }; for (int instanceIx = 1; instanceIx < clonedCluster.instanceCount; instanceIx++) { // Create another sibling Cluster sibling = new(clonedCluster.prefab, this) { @@ -186,7 +178,7 @@ namespace NanoBrain { instanceCount = this.instanceCount, }; siblings.Add(sibling); - CopyAllExternalReceivers(clonedCluster, sibling, clonedCluster.prefab, this); + CopyAllExternalReceivers(clonedCluster, sibling, this); } Cluster[] siblingClusters = siblings.ToArray(); foreach (Cluster sibling in siblings) @@ -198,7 +190,6 @@ namespace NanoBrain { if (clonedNucleus is not Cluster) clonedNucleus.UpdateStateIsolated(); } - //} } /// \copydoc NanoBrain::Nucleus::ShallowCloneTo @@ -209,13 +200,11 @@ namespace NanoBrain { parent = this.parent, instanceCount = this.instanceCount, }; - // Somehow siblingClusters should be cloned too. Believe I do this in ClonePrefab right now. return clone; } - private static void CopyAllExternalReceivers(Cluster sourceCluster, Cluster sibling, ClusterPrefab prefabParent, Cluster clonedParent) { - + private static void CopyAllExternalReceivers(Cluster sourceCluster, Cluster sibling, Cluster clonedParent) { for (int nucleusIx = 0; nucleusIx < sourceCluster.nuclei.Count; nucleusIx++) { Nucleus sourceNucleus = sourceCluster.nuclei[nucleusIx]; if (sourceNucleus is not Neuron sourceNeuron) @@ -517,43 +506,6 @@ namespace NanoBrain { return false; } - /// - /// Get a nucleus in this cluster - /// - /// The name of the nucleus to find - /// The found nucleus or null when it is not found - // public Nucleus GetNucleus(string nucleusName) { - // int dotPosition = nucleusName.IndexOf('.'); - // if (dotPosition >= 0) { - // string clusterName = nucleusName[..dotPosition]; - // string clusterName0 = clusterName + ": 0"; - // foreach (Nucleus nucleus in this.nuclei) { - // if (nucleus is Cluster cluster) { - // if (cluster.name == clusterName || cluster.name == clusterName0) { - // // cluster.CheckInstances(); - // string subNucleusName = nucleusName[(dotPosition + 1)..]; - // return cluster.GetNucleus(subNucleusName); - // } - // } - // } - // return null; - // } - // else { - // string nucleusName0 = nucleusName + ": 0"; - // foreach (Nucleus nucleus in this.nuclei) { - // if (nucleus is Cluster cluster) { - // if (nucleus.name == nucleusName || nucleus.name == nucleusName0) { - // // cluster.CheckInstances(); - // return nucleus; - // } - // } - // else if (nucleus.name == nucleusName) - // return nucleus; - // } - // return null; - // } - // } - /// /// Get a neuron in this cluster /// diff --git a/Runtime/Scripts/Core/Neuron.cs b/Runtime/Scripts/Core/Neuron.cs index e573215..97ff698 100644 --- a/Runtime/Scripts/Core/Neuron.cs +++ b/Runtime/Scripts/Core/Neuron.cs @@ -144,146 +144,6 @@ namespace NanoBrain { //this.curve = GenerateCurve(); } } - /// - /// The curve representing the activation function - /// - // [HideInInspector] - // public AnimationCurve curve; - /// - /// The maximum value of the curve - /// - // [HideInInspector] - // public float curveMax = 1.0f; - - /// - /// Generate the curve for the current activation function - /// - /// The curve - // public AnimationCurve GenerateCurve() { - // switch (this.activator) { - // case ActivationType.Linear: - // this.curveMax = 1; - // return Presets.Linear(1); - // case ActivationType.Power: - // this.curveMax = 1; - // return Presets.Power(2.0f, 1); - // case ActivationType.Sqrt: - // this.curveMax = 1; - // return Presets.Power(0.5f, 1); - // case ActivationType.Reciprocal: - // this.curveMax = 1 / 0.01f * 1; - // return Presets.Reciprocal(1); - // case ActivationType.Tanh: - // this.curveMax = 1; - // return Presets.Tanh(1); - // case ActivationType.Binary: - // this.curveMax = 1; - // return Presets.Binary(); - // case ActivationType.Normalized: - // this.curveMax = 1; - // return Presets.Binary(); - // default: - // this.curveMax = 1; - // return this.curve; - // } - // } - - /// - /// The curve presets for the activation functions - /// - public static class Presets { - /// - /// The number of samples in the curve - /// - private const int samples = 32; - /// - /// Generate a curve for the linear activation function - /// - /// The maximum value for the function - /// The curve preset - public static AnimationCurve Linear(float weight) { - return AnimationCurve.Linear(0f, 0f, 1000f, weight * 1000); - } - /// - /// Generate a curve for the power activation function - /// - /// The exponent of the power function - /// The maximum value for the function - /// The curve preset - public static AnimationCurve Power(float exponent, float weight) { - // build keyframes - Keyframe[] keys = new Keyframe[samples]; - for (int i = 0; i < samples; i++) { - float t = i / (float)(samples - 1); - float v = Mathf.Pow(t, exponent) * weight; - keys[i] = new Keyframe(t, v); - } - - AnimationCurve curve = new(keys); - - // set tangent modes for each key to Auto (smooth). Use Linear if you prefer straight segments. - for (int i = 0; i < curve.length; i++) { - AnimationUtility.SetKeyLeftTangentMode(curve, i, AnimationUtility.TangentMode.Auto); - AnimationUtility.SetKeyRightTangentMode(curve, i, AnimationUtility.TangentMode.Auto); - } - - return curve; - } - /// - /// Generate a curve for the reciprocal activation function - /// - /// The maximum value for the function - /// The curve preset - public static AnimationCurve Reciprocal(float weight) { - int samples = 128; - float xMin = 0.001f; - float xMax = 1; - var keys = new Keyframe[samples]; - for (int i = 0; i < samples; i++) { - float t = i / (float)(samples - 1); - float x = Mathf.Lerp(xMin, xMax, t); - float y = 1f / x * weight; - keys[i] = new Keyframe(x, y); - } - var curve = new AnimationCurve(keys); - for (int i = 0; i < curve.length; i++) { - AnimationUtility.SetKeyLeftTangentMode(curve, i, AnimationUtility.TangentMode.Linear); - AnimationUtility.SetKeyRightTangentMode(curve, i, AnimationUtility.TangentMode.Linear); - } - return curve; - } - /// - /// Generate a curve for the tanh activation function - /// - /// The maximum value for the function - /// The curve preset - public static AnimationCurve Tanh(float weight) { - //int samples = 128; - float xMin = 0.001f; - float xMax = 1; - var keys = new Keyframe[samples]; - for (int i = 0; i < samples; i++) { - float t = i / (float)(samples - 1); - float x = Mathf.Lerp(xMin, xMax, t); - float y = MathF.Tanh(x * weight); - keys[i] = new Keyframe(x, y); - } - var curve = new AnimationCurve(keys); - for (int i = 0; i < curve.length; i++) { - AnimationUtility.SetKeyLeftTangentMode(curve, i, AnimationUtility.TangentMode.Linear); - AnimationUtility.SetKeyRightTangentMode(curve, i, AnimationUtility.TangentMode.Linear); - } - return curve; - - } - /// - /// Generate a curve for the binary activation function - /// - /// The curve preset - public static AnimationCurve Binary() { - return AnimationCurve.Linear(0, 0, 1, 1); - } - } #endregion Serialization @@ -401,9 +261,7 @@ namespace NanoBrain { clone.bias = this.bias; clone.persistOutput = this.persistOutput; clone.combinator = this.combinator; - // clone.curve = this.curve; clone.activator = this.activator; - // clone.curveMax = this.curveMax; clone.breakOnUpdate = this.breakOnUpdate; } diff --git a/Runtime/Scripts/ScriptableObjects/ClusterPrefab.cs b/Runtime/Scripts/ScriptableObjects/ClusterPrefab.cs index b57e2dc..579c8d5 100644 --- a/Runtime/Scripts/ScriptableObjects/ClusterPrefab.cs +++ b/Runtime/Scripts/ScriptableObjects/ClusterPrefab.cs @@ -17,15 +17,6 @@ namespace NanoBrain.Unity { //[HideInInspector] public int version; - /// - /// Retrieve a nucleus in this cluster - /// - /// The name of the nucleus - /// The Nucleus with the given name or null if no such Nucleus could be found - // public Nucleus GetNucleus(string nucleusName) { - // return cluster.GetNucleus(nucleusName); - // } - /// /// Call this function to ensure that there is at least one nucleus ///