Fix links to multiple cluster neurons & cleanup
This commit is contained in:
parent
e17a249743
commit
04bab9264f
@ -153,15 +153,11 @@ namespace NanoBrain {
|
|||||||
fontStyle = FontStyle.Bold
|
fontStyle = FontStyle.Bold
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Nucleus type
|
||||||
string nucleusType = this.currentNucleus.GetType().Name;
|
string nucleusType = this.currentNucleus.GetType().Name;
|
||||||
// if (this.currentNucleus.parent != null) {
|
|
||||||
// string clusterName = this.currentNucleus.parent.name;
|
|
||||||
// GUILayout.Label(clusterName + ": " + nucleusType, headerStyle);
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
GUILayout.Label(nucleusType, headerStyle);
|
GUILayout.Label(nucleusType, headerStyle);
|
||||||
|
|
||||||
|
// Nucleus name
|
||||||
if (this.currentNucleus.parent is Cluster parentCluster) {
|
if (this.currentNucleus.parent is Cluster parentCluster) {
|
||||||
EditorGUILayout.BeginHorizontal();
|
EditorGUILayout.BeginHorizontal();
|
||||||
if (GUILayout.Button(this.currentNucleus.parent.name))
|
if (GUILayout.Button(this.currentNucleus.parent.name))
|
||||||
@ -183,6 +179,7 @@ namespace NanoBrain {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Current output value
|
||||||
if (Application.isPlaying) {
|
if (Application.isPlaying) {
|
||||||
if (currentNucleus is Neuron currentNeuron1) {
|
if (currentNucleus is Neuron currentNeuron1) {
|
||||||
GUIContent nameLabel = new("Output", currentNeuron1.outputValue.ToString());
|
GUIContent nameLabel = new("Output", currentNeuron1.outputValue.ToString());
|
||||||
@ -194,44 +191,63 @@ namespace NanoBrain {
|
|||||||
else
|
else
|
||||||
EditorGUILayout.LabelField(" ");
|
EditorGUILayout.LabelField(" ");
|
||||||
|
|
||||||
if (this.currentNucleus is MemoryCell memory) {
|
// Memory cell
|
||||||
memory.staticMemory = EditorGUILayout.Toggle("Static Memory", memory.staticMemory);
|
if (this.currentNucleus is MemoryCell memory)
|
||||||
}
|
MemoryCellInspector(memory, ref anythingChanged);
|
||||||
|
// Cluster
|
||||||
|
else if (this.currentNucleus is Cluster cluster)
|
||||||
|
ClusterInspector(cluster, ref anythingChanged);
|
||||||
|
// Other
|
||||||
|
else
|
||||||
|
NucleusInspector(this.currentNucleus, ref anythingChanged);
|
||||||
|
|
||||||
if (this.currentNucleus is Cluster cluster) {
|
if (GUILayout.Button("Delete"))
|
||||||
EditorGUILayout.BeginHorizontal();
|
|
||||||
if (cluster.instanceCount > 1)
|
|
||||||
EditorGUILayout.IntField("Array size", cluster.instanceCount, GUILayout.MinWidth(150));
|
|
||||||
else if (cluster.siblingClusters != null && cluster.siblingClusters.Length > 1)
|
|
||||||
EditorGUILayout.IntField("Array size", cluster.siblingClusters.Count(), GUILayout.MinWidth(150));
|
|
||||||
else
|
|
||||||
EditorGUILayout.IntField("Array size", 1, GUILayout.MinWidth(150));
|
|
||||||
if (GUILayout.Button("Add")) {
|
|
||||||
Undo.RecordObject(prefabAsset, "Array add " + prefabAsset.name);
|
|
||||||
//cluster.AddInstance(this.prefab);
|
|
||||||
cluster.AddInstance();
|
|
||||||
anythingChanged = true;
|
|
||||||
}
|
|
||||||
if (GUILayout.Button("Del")) {
|
|
||||||
Undo.RecordObject(prefabAsset, "Array delete " + prefabAsset.name);
|
|
||||||
cluster.RemoveInstance();
|
|
||||||
anythingChanged = true;
|
|
||||||
}
|
|
||||||
EditorGUILayout.EndHorizontal();
|
|
||||||
}
|
|
||||||
|
|
||||||
SynapsesInspector(ref anythingChanged);
|
|
||||||
ActivationInspector(ref anythingChanged);
|
|
||||||
|
|
||||||
if (GUILayout.Button("Delete this neuron"))
|
|
||||||
DeleteNucleus(this.currentNucleus);
|
DeleteNucleus(this.currentNucleus);
|
||||||
|
|
||||||
if (this.currentNucleus is Cluster subCluster) {
|
serializedObject.ApplyModifiedProperties();
|
||||||
if (GUILayout.Button("Reimport Cluster"))
|
if (anythingChanged) {
|
||||||
ReimportCluster(subCluster);
|
EditorUtility.SetDirty(prefabAsset);
|
||||||
if (GUILayout.Button("Edit Cluster"))
|
AssetDatabase.SaveAssets();
|
||||||
EditCluster(subCluster);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void MemoryCellInspector(MemoryCell memoryCell, ref bool anythingChanged) {
|
||||||
|
memoryCell.staticMemory = EditorGUILayout.Toggle("Static Memory", memoryCell.staticMemory);
|
||||||
|
NucleusInspector(memoryCell, ref anythingChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void ClusterInspector(Cluster cluster, ref bool anythingChanged) {
|
||||||
|
EditorGUILayout.BeginHorizontal();
|
||||||
|
|
||||||
|
int instanceCount = cluster.instanceCount;
|
||||||
|
if (instanceCount <= 1) {
|
||||||
|
if (cluster.siblingClusters != null && cluster.siblingClusters.Length > 1)
|
||||||
|
instanceCount = cluster.siblingClusters.Count();
|
||||||
|
else
|
||||||
|
instanceCount = 1;
|
||||||
|
}
|
||||||
|
EditorGUILayout.IntField("Instances", instanceCount, GUILayout.MinWidth(150));
|
||||||
|
|
||||||
|
if (GUILayout.Button("Add")) {
|
||||||
|
Undo.RecordObject(prefabAsset, "Array add " + prefabAsset.name);
|
||||||
|
//cluster.AddInstance(this.prefab);
|
||||||
|
cluster.AddInstance();
|
||||||
|
anythingChanged = true;
|
||||||
|
}
|
||||||
|
if (GUILayout.Button("Del")) {
|
||||||
|
Undo.RecordObject(prefabAsset, "Array delete " + prefabAsset.name);
|
||||||
|
cluster.RemoveInstance();
|
||||||
|
anythingChanged = true;
|
||||||
|
}
|
||||||
|
EditorGUILayout.EndHorizontal();
|
||||||
|
|
||||||
|
if (GUILayout.Button("Reimport Cluster"))
|
||||||
|
ReimportCluster(cluster);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void NucleusInspector(Nucleus nucleus, ref bool anythingChanged) {
|
||||||
|
SynapsesInspector(ref anythingChanged);
|
||||||
|
ActivationInspector(ref anythingChanged);
|
||||||
|
|
||||||
EditorGUILayout.Space();
|
EditorGUILayout.Space();
|
||||||
breakOnWake = EditorGUILayout.Toggle("Break on wake", breakOnWake);
|
breakOnWake = EditorGUILayout.Toggle("Break on wake", breakOnWake);
|
||||||
@ -242,11 +258,6 @@ namespace NanoBrain {
|
|||||||
trace = EditorGUILayout.Toggle("Trace", trace);
|
trace = EditorGUILayout.Toggle("Trace", trace);
|
||||||
this.currentNucleus.trace = trace;
|
this.currentNucleus.trace = trace;
|
||||||
|
|
||||||
serializedObject.ApplyModifiedProperties();
|
|
||||||
if (anythingChanged) {
|
|
||||||
EditorUtility.SetDirty(prefabAsset);
|
|
||||||
AssetDatabase.SaveAssets();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void SynapsesInspector(ref bool anythingChanged) {
|
protected void SynapsesInspector(ref bool anythingChanged) {
|
||||||
@ -361,35 +372,31 @@ namespace NanoBrain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void ActivationInspector(ref bool anythingChanged) {
|
protected void ActivationInspector(ref bool anythingChanged) {
|
||||||
|
EditorGUILayout.Space();
|
||||||
if (this.currentNucleus is not Cluster) {
|
showActivation = EditorGUILayout.BeginFoldoutHeaderGroup(showActivation, "Activation");
|
||||||
EditorGUILayout.Space();
|
if (showActivation) {
|
||||||
showActivation = EditorGUILayout.BeginFoldoutHeaderGroup(showActivation, "Activation");
|
if (this.currentNucleus is Neuron neuron) {
|
||||||
if (showActivation) {
|
if (this.currentNucleus is not MemoryCell) {
|
||||||
if (this.currentNucleus is Neuron neuron) {
|
EditorGUILayout.BeginHorizontal();
|
||||||
if (this.currentNucleus is not MemoryCell) {
|
EditorGUILayout.LabelField("Activation Curve", GUILayout.MinWidth(60));
|
||||||
EditorGUILayout.BeginHorizontal();
|
if (neuron.curveMax > 0)
|
||||||
EditorGUILayout.LabelField("Activation Curve", GUILayout.MinWidth(60));
|
EditorGUILayout.CurveField(neuron.curve, Color.cyan, new Rect(0, 0, 1, neuron.curveMax), GUILayout.Width(40));
|
||||||
if (neuron.curveMax > 0)
|
else
|
||||||
EditorGUILayout.CurveField(neuron.curve, Color.cyan, new Rect(0, 0, 1, neuron.curveMax), GUILayout.Width(40));
|
EditorGUILayout.CurveField(neuron.curve, Color.cyan, new Rect(0, neuron.curveMax, 1, -neuron.curveMax), GUILayout.Width(40));
|
||||||
else
|
Neuron.ActivationType newPreset = (Neuron.ActivationType)EditorGUILayout.EnumPopup(neuron.curvePreset, GUILayout.MinWidth(50));
|
||||||
EditorGUILayout.CurveField(neuron.curve, Color.cyan, new Rect(0, neuron.curveMax, 1, -neuron.curveMax), GUILayout.Width(40));
|
anythingChanged |= newPreset != neuron.curvePreset;
|
||||||
Neuron.ActivationType newPreset = (Neuron.ActivationType)EditorGUILayout.EnumPopup(neuron.curvePreset, GUILayout.MinWidth(50));
|
neuron.curvePreset = newPreset;
|
||||||
anythingChanged |= newPreset != neuron.curvePreset;
|
EditorGUILayout.EndHorizontal();
|
||||||
neuron.curvePreset = newPreset;
|
|
||||||
EditorGUILayout.EndHorizontal();
|
|
||||||
}
|
|
||||||
// if (neuron is Receptor receptor2) {
|
|
||||||
// if (receptor2.nucleiArray == null || receptor2.nucleiArray.Count() == 0)
|
|
||||||
// receptor2.array = new NucleusArray(neuron);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
// if (neuron is Receptor receptor2) {
|
||||||
EditorGUILayout.Space();
|
// if (receptor2.nucleiArray == null || receptor2.nucleiArray.Count() == 0)
|
||||||
|
// receptor2.array = new NucleusArray(neuron);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
EditorGUILayout.EndFoldoutHeaderGroup();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
EditorGUILayout.Space();
|
||||||
|
}
|
||||||
|
EditorGUILayout.EndFoldoutHeaderGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Synapses
|
#region Synapses
|
||||||
|
|||||||
@ -447,28 +447,20 @@ namespace NanoBrain {
|
|||||||
// This is used to 'scale' the output value colors of the nuclei
|
// This is used to 'scale' the output value colors of the nuclei
|
||||||
float maxValue = 0;
|
float maxValue = 0;
|
||||||
int neuronCount = 0;
|
int neuronCount = 0;
|
||||||
//List<Nucleus[]> drawnArrays = new();
|
List<Neuron> drawnNeurons = new();
|
||||||
Cluster[] drawnCluster = null;
|
|
||||||
foreach (Synapse synapse in nucleus.synapses) {
|
foreach (Synapse synapse in nucleus.synapses) {
|
||||||
if (synapse.neuron == null)
|
if (synapse.neuron == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (synapse.neuron.parent is Cluster cluster &&
|
// Draw multiple synapses to the same neuron only once
|
||||||
//cluster.siblingClusters != null &&
|
if (drawnNeurons.Contains(synapse.neuron))
|
||||||
synapse.neuron.parent != nucleus.parent) {
|
continue;
|
||||||
|
drawnNeurons.Add(synapse.neuron);
|
||||||
|
|
||||||
|
float value = synapse.neuron.outputMagnitude * synapse.weight;
|
||||||
|
if (value > maxValue)
|
||||||
|
maxValue = value;
|
||||||
|
|
||||||
//if (drawnArrays.Contains(cluster.siblingClusters))
|
|
||||||
if (drawnCluster is not null && cluster.SameSiblingsAs(drawnCluster))
|
|
||||||
continue;
|
|
||||||
//drawnArrays.Add(cluster.siblingClusters);
|
|
||||||
drawnCluster = cluster.siblingClusters;
|
|
||||||
}
|
|
||||||
if (synapse.neuron is Neuron synapseNeuron) {
|
|
||||||
float value = synapseNeuron.outputMagnitude * synapse.weight;
|
|
||||||
// Debug.Log($"{synapse.nucleus.name}: {value} {length(synapse.nucleus.outputValue)} {synapse.weight}");
|
|
||||||
if (value > maxValue)
|
|
||||||
maxValue = value;
|
|
||||||
}
|
|
||||||
neuronCount++;
|
neuronCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -477,23 +469,15 @@ namespace NanoBrain {
|
|||||||
float margin = 10 + spacing / 2;
|
float margin = 10 + spacing / 2;
|
||||||
|
|
||||||
int row = 0;
|
int row = 0;
|
||||||
//drawnArrays = new();
|
drawnNeurons = new();
|
||||||
drawnCluster = null;
|
|
||||||
foreach (Synapse synapse in nucleus.synapses) {
|
foreach (Synapse synapse in nucleus.synapses) {
|
||||||
if (synapse.neuron is null)
|
if (synapse.neuron is null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (synapse.neuron.parent is Cluster cluster &&
|
if (drawnNeurons.Contains(synapse.neuron))
|
||||||
//cluster.siblingClusters != null &&
|
continue;
|
||||||
synapse.neuron.parent != nucleus.parent) {
|
drawnNeurons.Add(synapse.neuron);
|
||||||
|
|
||||||
// if (drawnArrays.Contains(cluster.siblingClusters))
|
|
||||||
// continue;
|
|
||||||
// drawnArrays.Add(cluster.siblingClusters);
|
|
||||||
if (drawnCluster is not null && cluster.SameSiblingsAs(drawnCluster))
|
|
||||||
continue;
|
|
||||||
drawnCluster = cluster.siblingClusters;
|
|
||||||
}
|
|
||||||
Vector3 pos = new(250, margin + row * spacing, 0.0f);
|
Vector3 pos = new(250, margin + row * spacing, 0.0f);
|
||||||
Handles.color = Color.white;
|
Handles.color = Color.white;
|
||||||
Handles.DrawLine(parentPos, pos);
|
Handles.DrawLine(parentPos, pos);
|
||||||
@ -502,18 +486,10 @@ namespace NanoBrain {
|
|||||||
if (maxValue == 0 || !float.IsFinite(maxValue))
|
if (maxValue == 0 || !float.IsFinite(maxValue))
|
||||||
maxValue = 1;
|
maxValue = 1;
|
||||||
float brightness = 0;
|
float brightness = 0;
|
||||||
if (synapse.neuron is Neuron synapseNeuron)
|
brightness = synapse.neuron.outputMagnitude * synapse.weight / maxValue;
|
||||||
brightness = synapseNeuron.outputMagnitude * synapse.weight / maxValue;
|
|
||||||
color = new Color(brightness, brightness, brightness, 1f);
|
color = new Color(brightness, brightness, brightness, 1f);
|
||||||
}
|
}
|
||||||
if (synapse.neuron.parent != null && synapse.neuron.parent != this.currentNucleus.parent) {
|
DrawNucleus(synapse.neuron, pos, size, color);
|
||||||
// the synapse nucleus is part of a subcluster
|
|
||||||
//DrawNucleus(synapse.neuron.parent, pos, maxValue, size, color);
|
|
||||||
DrawNucleus(synapse.neuron, pos, size, color);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
DrawNucleus(synapse.neuron, pos, size, color);
|
|
||||||
}
|
|
||||||
row++;
|
row++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -619,7 +595,7 @@ namespace NanoBrain {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawCluster(Cluster cluster, Vector3 position, Color color, float size) {
|
protected void DrawCluster(Cluster cluster, Vector3 position, Color color, float size) {
|
||||||
GUIStyle labelTextStyle = new(EditorStyles.label) {
|
GUIStyle labelTextStyle = new(EditorStyles.label) {
|
||||||
normal = { textColor = Color.white },
|
normal = { textColor = Color.white },
|
||||||
fontStyle = FontStyle.Bold,
|
fontStyle = FontStyle.Bold,
|
||||||
@ -704,7 +680,7 @@ namespace NanoBrain {
|
|||||||
Handles.DrawLine(from, to);
|
Handles.DrawLine(from, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleMouseHover(Nucleus nucleus, Rect rect) {
|
protected void HandleMouseHover(Nucleus nucleus, Rect rect) {
|
||||||
GUIContent tooltip;
|
GUIContent tooltip;
|
||||||
if (nucleus is Neuron neuron) {
|
if (nucleus is Neuron neuron) {
|
||||||
tooltip = new(
|
tooltip = new(
|
||||||
|
|||||||
@ -468,9 +468,10 @@ namespace NanoBrain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void AddArrayReceiver(Nucleus receiverToAdd, float weight = 1) {
|
public void AddArrayReceiver(Nucleus receiverToAdd, float weight = 1) {
|
||||||
foreach (Cluster cluster in this.siblingClusters) {
|
this.defaultOutput.AddReceiver(receiverToAdd, weight);
|
||||||
cluster.defaultOutput.AddReceiver(receiverToAdd, weight);
|
// foreach (Cluster cluster in this.siblingClusters) {
|
||||||
}
|
// cluster.defaultOutput.AddReceiver(receiverToAdd, weight);
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user