GetNeuron/Cluster instead of GetNucleus

This commit is contained in:
Pascal Serrarens 2026-05-22 17:15:18 +02:00
parent 923a5fafe3
commit f8a6f579ea
7 changed files with 78 additions and 43 deletions

View File

@ -445,7 +445,7 @@ namespace NanoBrain.Unity {
float maxValue = 0;
foreach (Cluster sibling in nucleus.parent.instances) {
Neuron siblingNeuron = sibling.GetNucleus(nucleus.name) as Neuron;
Neuron siblingNeuron = sibling.GetNeuron(nucleus.name);
float value = siblingNeuron.outputMagnitude; // no need to add weight as they are all the same
if (value > maxValue)
maxValue = value;
@ -458,7 +458,7 @@ namespace NanoBrain.Unity {
int row = 0;
Vector3 position = Vector3.zero;
foreach (Cluster sibling in nucleus.parent.instances) {
Neuron siblingNeuron = sibling.GetNucleus(nucleus.name) as Neuron;
Neuron siblingNeuron = sibling.GetNeuron(nucleus.name);
position = new(250, margin + row * spacing, 0.0f);
DrawEdge(parentPos, position);
Color color = Color.black;

View File

@ -94,7 +94,7 @@ namespace NanoBrain.Unity {
object parent = SerializedPropertyUtility.GetParentObjectAndMember(targetObject, property.propertyPath, out var memberInfo, out int outIndex);
if (parent != null && memberInfo is FieldInfo fieldInfo) {
fieldInfo.SetValue(parent, cluster);
//EditorUtility.SetDirty(targetObject);
EditorUtility.SetDirty(targetObject);
}
clusterView.initialized = true;
}
@ -136,7 +136,7 @@ namespace NanoBrain.Unity {
Handles.color = Color.yellow;
if (Cluster_Drawer.clusterView.selectedSynapseNeuron != null) {
foreach (Cluster sibling in Cluster_Drawer.clusterView.selectedSynapseNeuron.parent.instances) {
Neuron siblingNeuron = sibling.GetNucleus(Cluster_Drawer.clusterView.selectedSynapseNeuron.name) as Neuron;
Neuron siblingNeuron = sibling.GetNeuron(Cluster_Drawer.clusterView.selectedSynapseNeuron.name);
Vector3 worldVector = gameObject.transform.TransformVector(siblingNeuron.outputValue);
Handles.DrawLine(gameObject.transform.position, gameObject.transform.position + worldVector);
}

View File

@ -522,37 +522,37 @@ namespace NanoBrain {
/// </summary>
/// <param name="nucleusName">The name of the nucleus to find</param>
/// <returns>The found nucleus or null when it is not found</returns>
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;
}
}
// 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;
// }
// }
/// <summary>
/// Get a neuron in this cluster
@ -570,6 +570,41 @@ namespace NanoBrain {
return null;
}
/// <summary>
/// Get a subcluster in this cluster
/// </summary>
/// <param name="clusterName">The name of the cluster to find</param>
/// <returns>The found cluster or null when it is not found</returns>
public Cluster GetCluster(string clusterName) {
int dotPosition = clusterName.IndexOf('.');
if (dotPosition >= 0) {
string clusterBaseName = clusterName[..dotPosition];
string clusterName0 = clusterBaseName + ": 0";
foreach (Nucleus nucleus in this.nuclei) {
if (nucleus is Cluster cluster) {
if (cluster.name == clusterBaseName || cluster.name == clusterName0) {
// cluster.CheckInstances();
string subNucleusName = clusterName[(dotPosition + 1)..];
return cluster.GetCluster(subNucleusName);
}
}
}
return null;
}
else {
string nucleusName0 = clusterName + ": 0";
foreach (Nucleus nucleus in this.nuclei) {
if (nucleus is Cluster cluster) {
if (nucleus.name == clusterName || nucleus.name == nucleusName0) {
// cluster.CheckInstances();
return cluster;
}
}
}
return null;
}
}
/// <summary>
/// Get a neuron in an instance of a multi-cluster
/// </summary>

View File

@ -22,9 +22,9 @@ namespace NanoBrain.Unity {
/// </summary>
/// <param name="nucleusName">The name of the nucleus</param>
/// <returns>The Nucleus with the given name or null if no such Nucleus could be found</returns>
public Nucleus GetNucleus(string nucleusName) {
return cluster.GetNucleus(nucleusName);
}
// public Nucleus GetNucleus(string nucleusName) {
// return cluster.GetNucleus(nucleusName);
// }
/// <summary>
/// Call this function to ensure that there is at least one nucleus

View File

@ -10,7 +10,7 @@ namespace NanoBrain.Braitenberg {
public WheelCollider wheelCollider;
protected ClusterPrefab brain;
protected Cluster brain;
public Neuron motorNeuron;
protected virtual void Awake() {
@ -18,7 +18,7 @@ namespace NanoBrain.Braitenberg {
if (vehicle != null)
brain = vehicle.brain;
if (brain != null)
motorNeuron = brain.GetNucleus(outputNeuronName) as Neuron;
motorNeuron = brain.GetNeuron(outputNeuronName);
wheelCollider = GetComponent<WheelCollider>();
}

View File

@ -25,7 +25,7 @@ namespace NanoBrain.Braitenberg {
public float _output;
protected Vehicle vehicle;
protected ClusterPrefab brain;
protected Cluster brain;
public Neuron sensoryNeuron;
protected virtual void Awake() {
@ -34,7 +34,7 @@ namespace NanoBrain.Braitenberg {
if (vehicle != null)
brain = vehicle.brain;
if (brain != null)
sensoryNeuron = brain.GetNucleus(this.name) as Neuron;
sensoryNeuron = brain.GetNeuron(this.name);
}
void OnEnable() => StartCoroutine(SampleRoutine());

View File

@ -4,7 +4,7 @@ namespace NanoBrain.Braitenberg {
[RequireComponent(typeof(Rigidbody))]
public class Vehicle : MonoBehaviour {
public Unity.ClusterPrefab brain;
public Cluster brain;
[Header("Motors")]
public Motor motorLeft;