Pheromones WIP
This commit is contained in:
parent
551b4d9cea
commit
baa7defef0
@ -81,6 +81,7 @@ namespace NanoBrain {
|
||||
// So we create a temporary instance
|
||||
//this.currentCluster = new(prefab);
|
||||
this.currentCluster = prefab.cluster;
|
||||
this.currentCluster.Refresh();
|
||||
}
|
||||
|
||||
public void SetGraph(GameObject gameObject, VisualElement inspectorContainer) {
|
||||
@ -227,10 +228,8 @@ namespace NanoBrain {
|
||||
|
||||
bool connecting = GUILayout.Button("Add Output Neuron");
|
||||
if (connecting) {
|
||||
Nucleus newOutput = new Neuron(this.prefab.cluster, "New Output");
|
||||
// Regenerate the temporary clsuter instance
|
||||
// See also the constructor
|
||||
this.currentCluster = new(this.prefab);
|
||||
Nucleus newOutput = new Neuron(this.currentCluster, "New Output");
|
||||
this.currentCluster.Refresh();
|
||||
this.currentNucleus = newOutput;
|
||||
this.selectedOutput = this.currentNucleus;
|
||||
}
|
||||
@ -358,8 +357,6 @@ namespace NanoBrain {
|
||||
int selectedIndex = System.Array.IndexOf(options, synapse.neuron.name);
|
||||
int newIndex = EditorGUILayout.Popup(selectedIndex, options);
|
||||
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;
|
||||
ChangeSynapse(synapse, newNeuron);
|
||||
}
|
||||
@ -523,22 +520,6 @@ namespace NanoBrain {
|
||||
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) {
|
||||
if (nucleus == null)
|
||||
return;
|
||||
|
||||
@ -618,7 +618,7 @@ namespace NanoBrain {
|
||||
if (neuron.synapses.Count == 0)
|
||||
this._inputs.Add(nucleus);
|
||||
}
|
||||
RefreshComputeOrders();
|
||||
RefreshComputeOrders();
|
||||
}
|
||||
return this._inputs;
|
||||
}
|
||||
@ -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) {
|
||||
if (this.nuclei.Contains(nucleus) == false) {
|
||||
// Try to find the nucleus by name
|
||||
@ -875,12 +883,12 @@ namespace NanoBrain {
|
||||
|
||||
List<Nucleus> computeOrder = this.computeOrders[startNucleus];
|
||||
//if (startNucleus.trace)
|
||||
Debug.Log($"Update from {startNucleus.name}");
|
||||
// Debug.Log($"Update from {startNucleus.name}");
|
||||
foreach (Nucleus nucleus in computeOrder) {
|
||||
if (nucleus is not Cluster) {
|
||||
nucleus.UpdateStateIsolated();
|
||||
//if (startNucleus.trace && nucleus is Neuron neuron)
|
||||
Debug.Log($" {nucleus.name}");
|
||||
// Debug.Log($" {nucleus.name}");
|
||||
if (nucleus is Neuron neuron) {
|
||||
foreach (Nucleus receiver in neuron.receivers) {
|
||||
if (receiver.parent != this) {
|
||||
@ -910,6 +918,12 @@ namespace NanoBrain {
|
||||
#endregion Update
|
||||
|
||||
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();
|
||||
RefreshComputeOrders();
|
||||
}
|
||||
|
||||
@ -104,6 +104,7 @@ namespace NanoBrain {
|
||||
/// <param name="inputValue"></param>
|
||||
public virtual void SetBias(Vector3 inputValue) {
|
||||
this.bias = inputValue;
|
||||
this.lastUpdate = Time.time;
|
||||
this.parent?.UpdateFromNucleus(this);
|
||||
}
|
||||
|
||||
@ -277,7 +278,7 @@ namespace NanoBrain {
|
||||
#endif
|
||||
public bool isFiring {
|
||||
get {
|
||||
SleepCheck();
|
||||
//SleepCheck();
|
||||
return this.outputMagnitude > 0.5f;
|
||||
}
|
||||
}
|
||||
@ -384,13 +385,15 @@ namespace NanoBrain {
|
||||
var result = Combinator();
|
||||
this.outputValue = Activator(result);
|
||||
this.lastUpdate = Time.time;
|
||||
// Debug.Log($"Update Neuron {this.name}");
|
||||
}
|
||||
|
||||
protected void CheckSleepingSynapses() {
|
||||
foreach (Synapse synapse in this.synapses) {
|
||||
if (synapse.isSleeping) {
|
||||
synapse.neuron.outputValue = Vector3.zero;
|
||||
}
|
||||
synapse.neuron.SleepCheck();
|
||||
// if (synapse.isSleeping) {
|
||||
// synapse.neuron.outputValue = Vector3.zero;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user