Simplify/improve UpdateStateIsolated

This commit is contained in:
Pascal Serrarens 2026-02-10 12:55:25 +01:00
parent 6f67def8e6
commit d562c7192b
7 changed files with 32 additions and 27 deletions

View File

@ -91,9 +91,10 @@ public class Cluster : Nucleus {
foreach (Nucleus prefabArrayNucleus in prefabNucleus.array.nuclei) { foreach (Nucleus prefabArrayNucleus in prefabNucleus.array.nuclei) {
int arrayNucleusIx = GetNucleusIndex(prefabNuclei, prefabArrayNucleus); int arrayNucleusIx = GetNucleusIndex(prefabNuclei, prefabArrayNucleus);
if (arrayNucleusIx >= 0) { if (arrayNucleusIx >= 0) {
Nucleus clonedArrayNucleus = clonedNuclei[arrayNucleusIx]; Nucleus clonedArrayNucleus = clonedNuclei[arrayNucleusIx];
clonedArray.nuclei[arrayIx] = clonedArrayNucleus; clonedArray.nuclei[arrayIx] = clonedArrayNucleus;
} else { }
else {
Debug.LogError($" Could not find prefab nuclues {prefabNucleus.name} in the clones"); Debug.LogError($" Could not find prefab nuclues {prefabNucleus.name} in the clones");
} }
arrayIx++; arrayIx++;
@ -250,11 +251,7 @@ public class Cluster : Nucleus {
#region Update #region Update
public override void UpdateStateIsolated() { public override void UpdateStateIsolated() {
float3 bias = new(0, 0, 0); Vector3 sum = this.bias;
UpdateStateIsolated(bias);
}
public override void UpdateStateIsolated(float3 bias) {
Vector3 sum = bias;
//Applying the weight factors //Applying the weight factors
foreach (Synapse synapse in this.synapses) { foreach (Synapse synapse in this.synapses) {
@ -264,12 +261,11 @@ public class Cluster : Nucleus {
} }
} }
this.inputs[0].UpdateStateIsolated(sum); foreach (Nucleus nucleus in this.sortedNuclei)
foreach (Nucleus receptor in this.sortedNuclei) { nucleus.UpdateStateIsolated();
if (receptor is Nucleus nucleus && nucleus != this.inputs[0])
nucleus.UpdateStateIsolated();
}
this.outputValue = this.output.outputValue; this.outputValue = this.output.outputValue;
this.stale = 0;
UpdateNuclei(); UpdateNuclei();
} }

View File

@ -1,4 +1,6 @@
using UnityEditor; using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine; using UnityEngine;
using UnityEngine.UIElements; using UnityEngine.UIElements;
@ -27,6 +29,13 @@ public class NanoBrainComponent_Editor : Editor {
VisualElement root = new(); VisualElement root = new();
if (Application.isPlaying == false) {
PropertyField brainField = new(brainProp) {
label = "Nano Brain"
};
root.Add(brainField);
}
ClusterInspector.CreateInspector(root, brain.prefab, brain.output, component.gameObject); ClusterInspector.CreateInspector(root, brain.prefab, brain.output, component.gameObject);
if (Application.isPlaying == false) if (Application.isPlaying == false)

View File

@ -25,13 +25,13 @@ public class MemoryCell : Neuron {
private float3 _memorizedValue; private float3 _memorizedValue;
private float _memorizedTime; private float _memorizedTime;
public override void UpdateStateIsolated() { // public override void UpdateStateIsolated() {
float3 bias = new(0, 0, 0); // float3 bias = new(0, 0, 0);
UpdateStateIsolated(bias); // UpdateStateIsolated(bias);
} // }
public override void UpdateStateIsolated(float3 bias) { public override void UpdateStateIsolated() { //float3 bias) {
// A memorycell does not have an activation function // A memorycell does not have an activation function
Vector3 result = bias; Vector3 result = this.bias;
int n = 0; int n = 0;
//Applying the weight factgors //Applying the weight factgors

View File

@ -200,7 +200,7 @@ public class Neuron : Nucleus {
} }
//public float3 bias = float3(0, 0, 0); //public float3 bias = float3(0, 0, 0);
public override void UpdateStateIsolated(float3 bias_unused) { public override void UpdateStateIsolated() { //float3 bias_unused) {
Vector3 sum = this.bias; Vector3 sum = this.bias;
int n = 0; int n = 0;

View File

@ -98,11 +98,11 @@ public abstract class Nucleus {
#region Update #region Update
public virtual void UpdateStateIsolated() { public abstract void UpdateStateIsolated();
UpdateStateIsolated(new float3(0, 0, 0)); // UpdateStateIsolated(new float3(0, 0, 0));
} // }
public abstract void UpdateStateIsolated(float3 bias); //public abstract void UpdateStateIsolated(float3 bias);
// public virtual void UpdateStateIsolated(float3 bias) { // public virtual void UpdateStateIsolated(float3 bias) {
// } // }

View File

@ -39,7 +39,7 @@ public class Pulsar : Neuron {
return clone; return clone;
} }
public override void UpdateStateIsolated(float3 _bias) { public override void UpdateStateIsolated() { //float3 _bias) {
float3 product = this.bias; float3 product = this.bias;
//Applying the weight factors //Applying the weight factors

View File

@ -18,8 +18,8 @@ public class Selector : Neuron {
return clone; return clone;
} }
public override void UpdateStateIsolated(float3 bias) { public override void UpdateStateIsolated() { //float3 bias) {
float3 max = bias; float3 max = this.bias;
float maxSqrLength = lengthsq(max); float maxSqrLength = lengthsq(max);
//Applying the weight factors //Applying the weight factors