GetNeuron/Cluster instead of GetNucleus
This commit is contained in:
parent
923a5fafe3
commit
f8a6f579ea
@ -445,7 +445,7 @@ namespace NanoBrain.Unity {
|
|||||||
|
|
||||||
float maxValue = 0;
|
float maxValue = 0;
|
||||||
foreach (Cluster sibling in nucleus.parent.instances) {
|
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
|
float value = siblingNeuron.outputMagnitude; // no need to add weight as they are all the same
|
||||||
if (value > maxValue)
|
if (value > maxValue)
|
||||||
maxValue = value;
|
maxValue = value;
|
||||||
@ -458,7 +458,7 @@ namespace NanoBrain.Unity {
|
|||||||
int row = 0;
|
int row = 0;
|
||||||
Vector3 position = Vector3.zero;
|
Vector3 position = Vector3.zero;
|
||||||
foreach (Cluster sibling in nucleus.parent.instances) {
|
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);
|
position = new(250, margin + row * spacing, 0.0f);
|
||||||
DrawEdge(parentPos, position);
|
DrawEdge(parentPos, position);
|
||||||
Color color = Color.black;
|
Color color = Color.black;
|
||||||
|
|||||||
@ -94,7 +94,7 @@ namespace NanoBrain.Unity {
|
|||||||
object parent = SerializedPropertyUtility.GetParentObjectAndMember(targetObject, property.propertyPath, out var memberInfo, out int outIndex);
|
object parent = SerializedPropertyUtility.GetParentObjectAndMember(targetObject, property.propertyPath, out var memberInfo, out int outIndex);
|
||||||
if (parent != null && memberInfo is FieldInfo fieldInfo) {
|
if (parent != null && memberInfo is FieldInfo fieldInfo) {
|
||||||
fieldInfo.SetValue(parent, cluster);
|
fieldInfo.SetValue(parent, cluster);
|
||||||
//EditorUtility.SetDirty(targetObject);
|
EditorUtility.SetDirty(targetObject);
|
||||||
}
|
}
|
||||||
clusterView.initialized = true;
|
clusterView.initialized = true;
|
||||||
}
|
}
|
||||||
@ -136,7 +136,7 @@ namespace NanoBrain.Unity {
|
|||||||
Handles.color = Color.yellow;
|
Handles.color = Color.yellow;
|
||||||
if (Cluster_Drawer.clusterView.selectedSynapseNeuron != null) {
|
if (Cluster_Drawer.clusterView.selectedSynapseNeuron != null) {
|
||||||
foreach (Cluster sibling in Cluster_Drawer.clusterView.selectedSynapseNeuron.parent.instances) {
|
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);
|
Vector3 worldVector = gameObject.transform.TransformVector(siblingNeuron.outputValue);
|
||||||
Handles.DrawLine(gameObject.transform.position, gameObject.transform.position + worldVector);
|
Handles.DrawLine(gameObject.transform.position, gameObject.transform.position + worldVector);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -522,37 +522,37 @@ namespace NanoBrain {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="nucleusName">The name of the nucleus to find</param>
|
/// <param name="nucleusName">The name of the nucleus to find</param>
|
||||||
/// <returns>The found nucleus or null when it is not found</returns>
|
/// <returns>The found nucleus or null when it is not found</returns>
|
||||||
public Nucleus GetNucleus(string nucleusName) {
|
// public Nucleus GetNucleus(string nucleusName) {
|
||||||
int dotPosition = nucleusName.IndexOf('.');
|
// int dotPosition = nucleusName.IndexOf('.');
|
||||||
if (dotPosition >= 0) {
|
// if (dotPosition >= 0) {
|
||||||
string clusterName = nucleusName[..dotPosition];
|
// string clusterName = nucleusName[..dotPosition];
|
||||||
string clusterName0 = clusterName + ": 0";
|
// string clusterName0 = clusterName + ": 0";
|
||||||
foreach (Nucleus nucleus in this.nuclei) {
|
// foreach (Nucleus nucleus in this.nuclei) {
|
||||||
if (nucleus is Cluster cluster) {
|
// if (nucleus is Cluster cluster) {
|
||||||
if (cluster.name == clusterName || cluster.name == clusterName0) {
|
// if (cluster.name == clusterName || cluster.name == clusterName0) {
|
||||||
// cluster.CheckInstances();
|
// // cluster.CheckInstances();
|
||||||
string subNucleusName = nucleusName[(dotPosition + 1)..];
|
// string subNucleusName = nucleusName[(dotPosition + 1)..];
|
||||||
return cluster.GetNucleus(subNucleusName);
|
// return cluster.GetNucleus(subNucleusName);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
else {
|
// else {
|
||||||
string nucleusName0 = nucleusName + ": 0";
|
// string nucleusName0 = nucleusName + ": 0";
|
||||||
foreach (Nucleus nucleus in this.nuclei) {
|
// foreach (Nucleus nucleus in this.nuclei) {
|
||||||
if (nucleus is Cluster cluster) {
|
// if (nucleus is Cluster cluster) {
|
||||||
if (nucleus.name == nucleusName || nucleus.name == nucleusName0) {
|
// if (nucleus.name == nucleusName || nucleus.name == nucleusName0) {
|
||||||
// cluster.CheckInstances();
|
// // cluster.CheckInstances();
|
||||||
return nucleus;
|
// return nucleus;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else if (nucleus.name == nucleusName)
|
// else if (nucleus.name == nucleusName)
|
||||||
return nucleus;
|
// return nucleus;
|
||||||
}
|
// }
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a neuron in this cluster
|
/// Get a neuron in this cluster
|
||||||
@ -570,6 +570,41 @@ namespace NanoBrain {
|
|||||||
return null;
|
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>
|
/// <summary>
|
||||||
/// Get a neuron in an instance of a multi-cluster
|
/// Get a neuron in an instance of a multi-cluster
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -22,9 +22,9 @@ namespace NanoBrain.Unity {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="nucleusName">The name of the nucleus</param>
|
/// <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>
|
/// <returns>The Nucleus with the given name or null if no such Nucleus could be found</returns>
|
||||||
public Nucleus GetNucleus(string nucleusName) {
|
// public Nucleus GetNucleus(string nucleusName) {
|
||||||
return cluster.GetNucleus(nucleusName);
|
// return cluster.GetNucleus(nucleusName);
|
||||||
}
|
// }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Call this function to ensure that there is at least one nucleus
|
/// Call this function to ensure that there is at least one nucleus
|
||||||
|
|||||||
@ -10,7 +10,7 @@ namespace NanoBrain.Braitenberg {
|
|||||||
|
|
||||||
public WheelCollider wheelCollider;
|
public WheelCollider wheelCollider;
|
||||||
|
|
||||||
protected ClusterPrefab brain;
|
protected Cluster brain;
|
||||||
public Neuron motorNeuron;
|
public Neuron motorNeuron;
|
||||||
|
|
||||||
protected virtual void Awake() {
|
protected virtual void Awake() {
|
||||||
@ -18,7 +18,7 @@ namespace NanoBrain.Braitenberg {
|
|||||||
if (vehicle != null)
|
if (vehicle != null)
|
||||||
brain = vehicle.brain;
|
brain = vehicle.brain;
|
||||||
if (brain != null)
|
if (brain != null)
|
||||||
motorNeuron = brain.GetNucleus(outputNeuronName) as Neuron;
|
motorNeuron = brain.GetNeuron(outputNeuronName);
|
||||||
wheelCollider = GetComponent<WheelCollider>();
|
wheelCollider = GetComponent<WheelCollider>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -25,7 +25,7 @@ namespace NanoBrain.Braitenberg {
|
|||||||
public float _output;
|
public float _output;
|
||||||
|
|
||||||
protected Vehicle vehicle;
|
protected Vehicle vehicle;
|
||||||
protected ClusterPrefab brain;
|
protected Cluster brain;
|
||||||
public Neuron sensoryNeuron;
|
public Neuron sensoryNeuron;
|
||||||
|
|
||||||
protected virtual void Awake() {
|
protected virtual void Awake() {
|
||||||
@ -34,7 +34,7 @@ namespace NanoBrain.Braitenberg {
|
|||||||
if (vehicle != null)
|
if (vehicle != null)
|
||||||
brain = vehicle.brain;
|
brain = vehicle.brain;
|
||||||
if (brain != null)
|
if (brain != null)
|
||||||
sensoryNeuron = brain.GetNucleus(this.name) as Neuron;
|
sensoryNeuron = brain.GetNeuron(this.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnEnable() => StartCoroutine(SampleRoutine());
|
void OnEnable() => StartCoroutine(SampleRoutine());
|
||||||
|
|||||||
@ -4,7 +4,7 @@ namespace NanoBrain.Braitenberg {
|
|||||||
|
|
||||||
[RequireComponent(typeof(Rigidbody))]
|
[RequireComponent(typeof(Rigidbody))]
|
||||||
public class Vehicle : MonoBehaviour {
|
public class Vehicle : MonoBehaviour {
|
||||||
public Unity.ClusterPrefab brain;
|
public Cluster brain;
|
||||||
|
|
||||||
[Header("Motors")]
|
[Header("Motors")]
|
||||||
public Motor motorLeft;
|
public Motor motorLeft;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user