Pheromones WIP

This commit is contained in:
Pascal Serrarens 2026-05-05 17:37:59 +02:00
parent 551b4d9cea
commit baa7defef0
3 changed files with 27 additions and 29 deletions

View File

@ -81,6 +81,7 @@ namespace NanoBrain {
// So we create a temporary instance // So we create a temporary instance
//this.currentCluster = new(prefab); //this.currentCluster = new(prefab);
this.currentCluster = prefab.cluster; this.currentCluster = prefab.cluster;
this.currentCluster.Refresh();
} }
public void SetGraph(GameObject gameObject, VisualElement inspectorContainer) { public void SetGraph(GameObject gameObject, VisualElement inspectorContainer) {
@ -227,10 +228,8 @@ namespace NanoBrain {
bool connecting = GUILayout.Button("Add Output Neuron"); bool connecting = GUILayout.Button("Add Output Neuron");
if (connecting) { if (connecting) {
Nucleus newOutput = new Neuron(this.prefab.cluster, "New Output"); Nucleus newOutput = new Neuron(this.currentCluster, "New Output");
// Regenerate the temporary clsuter instance this.currentCluster.Refresh();
// See also the constructor
this.currentCluster = new(this.prefab);
this.currentNucleus = newOutput; this.currentNucleus = newOutput;
this.selectedOutput = this.currentNucleus; this.selectedOutput = this.currentNucleus;
} }
@ -358,8 +357,6 @@ namespace NanoBrain {
int selectedIndex = System.Array.IndexOf(options, synapse.neuron.name); int selectedIndex = System.Array.IndexOf(options, synapse.neuron.name);
int newIndex = EditorGUILayout.Popup(selectedIndex, options); int newIndex = EditorGUILayout.Popup(selectedIndex, options);
if (newIndex != selectedIndex) { if (newIndex != selectedIndex) {
// Nucleus selectedNucleus = synapse.neuron.parent.clusterNuclei[newIndex];
// Neuron newNeuron = selectedNucleus as Neuron;
Neuron newNeuron = synapse.neuron.parent.prefab.cluster.nuclei[newIndex] as Neuron; Neuron newNeuron = synapse.neuron.parent.prefab.cluster.nuclei[newIndex] as Neuron;
ChangeSynapse(synapse, newNeuron); ChangeSynapse(synapse, newNeuron);
} }
@ -523,22 +520,6 @@ namespace NanoBrain {
return connecting; return connecting;
} }
// protected virtual void DisconnectNucleus(Neuron nucleus) {
// if (this.currentNucleus.parent.prefab == null)
// return;
// Neuron currentNeuron = this.currentNucleus as Neuron;
// string[] names = currentNeuron.synapses.Select(synapse => synapse.neuron.name).ToArray();
// int selectedIndex = -1;
// selectedIndex = EditorGUILayout.Popup("Disconnect from", selectedIndex, names);
// if (selectedIndex >= 0 && selectedIndex < this.currentNucleus.parent.prefab.cluster.nuclei.Count) {
// Synapse synapse = currentNeuron.synapses[selectedIndex];
// synapse.neuron.RemoveReceiver(this.currentNucleus);
// // synapse = currentNeuron.synapses[selectedIndex];
// // synapse.neuron.RemoveReceiver(this.currentPrefabNucleus);
// }
// }
protected virtual void DeleteNucleus(Nucleus nucleus) { protected virtual void DeleteNucleus(Nucleus nucleus) {
if (nucleus == null) if (nucleus == null)
return; return;

View File

@ -766,6 +766,14 @@ namespace NanoBrain {
} }
} }
public Neuron GetNeuron(string neuronName) {
foreach (Nucleus nucleus in this.nuclei) {
if (nucleus is Neuron neuron && neuron.name == neuronName)
return neuron;
}
return null;
}
public bool DeleteNucleus(Nucleus nucleus) { public bool DeleteNucleus(Nucleus nucleus) {
if (this.nuclei.Contains(nucleus) == false) { if (this.nuclei.Contains(nucleus) == false) {
// Try to find the nucleus by name // Try to find the nucleus by name
@ -875,12 +883,12 @@ namespace NanoBrain {
List<Nucleus> computeOrder = this.computeOrders[startNucleus]; List<Nucleus> computeOrder = this.computeOrders[startNucleus];
//if (startNucleus.trace) //if (startNucleus.trace)
Debug.Log($"Update from {startNucleus.name}"); // Debug.Log($"Update from {startNucleus.name}");
foreach (Nucleus nucleus in computeOrder) { foreach (Nucleus nucleus in computeOrder) {
if (nucleus is not Cluster) { if (nucleus is not Cluster) {
nucleus.UpdateStateIsolated(); nucleus.UpdateStateIsolated();
//if (startNucleus.trace && nucleus is Neuron neuron) //if (startNucleus.trace && nucleus is Neuron neuron)
Debug.Log($" {nucleus.name}"); // Debug.Log($" {nucleus.name}");
if (nucleus is Neuron neuron) { if (nucleus is Neuron neuron) {
foreach (Nucleus receiver in neuron.receivers) { foreach (Nucleus receiver in neuron.receivers) {
if (receiver.parent != this) { if (receiver.parent != this) {
@ -910,6 +918,12 @@ namespace NanoBrain {
#endregion Update #endregion Update
public void Refresh() { 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;
neuron.parent = this;
}
RefreshOutputs(); RefreshOutputs();
RefreshComputeOrders(); RefreshComputeOrders();
} }

View File

@ -104,6 +104,7 @@ namespace NanoBrain {
/// <param name="inputValue"></param> /// <param name="inputValue"></param>
public virtual void SetBias(Vector3 inputValue) { public virtual void SetBias(Vector3 inputValue) {
this.bias = inputValue; this.bias = inputValue;
this.lastUpdate = Time.time;
this.parent?.UpdateFromNucleus(this); this.parent?.UpdateFromNucleus(this);
} }
@ -277,7 +278,7 @@ namespace NanoBrain {
#endif #endif
public bool isFiring { public bool isFiring {
get { get {
SleepCheck(); //SleepCheck();
return this.outputMagnitude > 0.5f; return this.outputMagnitude > 0.5f;
} }
} }
@ -384,13 +385,15 @@ namespace NanoBrain {
var result = Combinator(); var result = Combinator();
this.outputValue = Activator(result); this.outputValue = Activator(result);
this.lastUpdate = Time.time; this.lastUpdate = Time.time;
// Debug.Log($"Update Neuron {this.name}");
} }
protected void CheckSleepingSynapses() { protected void CheckSleepingSynapses() {
foreach (Synapse synapse in this.synapses) { foreach (Synapse synapse in this.synapses) {
if (synapse.isSleeping) { synapse.neuron.SleepCheck();
synapse.neuron.outputValue = Vector3.zero; // if (synapse.isSleeping) {
} // synapse.neuron.outputValue = Vector3.zero;
// }
} }
} }