Fix max combinator and connecting to receptors
This commit is contained in:
parent
2ef9629e4d
commit
f9ce73fd7a
@ -99,7 +99,7 @@ public class Cluster : Nucleus {
|
||||
clonedArray.nuclei[arrayIx] = clonedArrayNucleus;
|
||||
}
|
||||
else {
|
||||
Debug.LogError($" Could not find prefab nuclues {prefabNucleus.name} in the clones");
|
||||
Debug.LogError($" Could not find prefab nucleus {prefabNucleus.name} in the clones");
|
||||
}
|
||||
arrayIx++;
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ public class ClusterReceptor : Cluster, IReceptor {
|
||||
nucleus.UpdateNuclei();
|
||||
}
|
||||
|
||||
public virtual void ProcessStimulus(Vector3 inputValue, int thingId = 0, string thingName = null) {
|
||||
public override void ProcessStimulus(Vector3 inputValue, int thingId = 0, string thingName = null) {
|
||||
this.array ??= new NucleusArray(this.parent);
|
||||
this.array.ProcessStimulus(thingId, inputValue, thingName);
|
||||
}
|
||||
|
||||
@ -606,11 +606,11 @@ public class ClusterInspector : Editor {
|
||||
else
|
||||
expandArray = false;
|
||||
}
|
||||
else if (nucleus is ReceptorInstance receptor) {
|
||||
this.currentNucleus = receptor.receptor;
|
||||
expandArray = false;
|
||||
BuildLayers();
|
||||
}
|
||||
// else if (nucleus is ReceptorInstance receptor) {
|
||||
// this.currentNucleus = receptor.receptor;
|
||||
// expandArray = false;
|
||||
// BuildLayers();
|
||||
// }
|
||||
else {
|
||||
this.currentNucleus = nucleus;
|
||||
expandArray = false;
|
||||
@ -674,21 +674,21 @@ public class ClusterInspector : Editor {
|
||||
if (this.currentNucleus is MemoryCell memory) {
|
||||
memory.staticMemory = EditorGUILayout.Toggle("Static Memory", memory.staticMemory);
|
||||
}
|
||||
if (this.currentNucleus is ReceptorArray receptor) {
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.IntField("Receptor size", receptor.instances.Count());
|
||||
if (GUILayout.Button("Add")) {
|
||||
Undo.RecordObject(prefabAsset, "Receptor add " + prefabAsset.name);
|
||||
receptor.AddReceptor(this.prefab);
|
||||
anythingChanged = true;
|
||||
}
|
||||
if (GUILayout.Button("Del")) {
|
||||
Undo.RecordObject(prefabAsset, "Receptor delete " + prefabAsset.name);
|
||||
receptor.RemoveReceptor();
|
||||
anythingChanged = true;
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
// if (this.currentNucleus is ReceptorArray receptor) {
|
||||
// EditorGUILayout.BeginHorizontal();
|
||||
// EditorGUILayout.IntField("Receptor size", receptor.instances.Count());
|
||||
// if (GUILayout.Button("Add")) {
|
||||
// Undo.RecordObject(prefabAsset, "Receptor add " + prefabAsset.name);
|
||||
// receptor.AddReceptor(this.prefab);
|
||||
// anythingChanged = true;
|
||||
// }
|
||||
// if (GUILayout.Button("Del")) {
|
||||
// Undo.RecordObject(prefabAsset, "Receptor delete " + prefabAsset.name);
|
||||
// receptor.RemoveReceptor();
|
||||
// anythingChanged = true;
|
||||
// }
|
||||
// EditorGUILayout.EndHorizontal();
|
||||
// }
|
||||
if (this.currentNucleus is Receptor receptor1) {
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.IntField("Array size", receptor1.nucleiArray.Count());
|
||||
@ -857,28 +857,28 @@ public class ClusterInspector : Editor {
|
||||
|
||||
void OnSceneGUI(SceneView sceneView) {
|
||||
if (this.gameObject != null) {
|
||||
if (this.currentNucleus is ReceptorArray receptor && expandArray) {
|
||||
foreach (Nucleus nucleus in receptor.instances) {
|
||||
// if (this.currentNucleus is ReceptorArray receptor && expandArray) {
|
||||
// foreach (Nucleus nucleus in receptor.instances) {
|
||||
// Vector3 worldVector = this.gameObject.transform.TransformVector(nucleus.outputValue);
|
||||
// Handles.color = Color.yellow;
|
||||
// Handles.DrawLine(this.gameObject.transform.position, this.gameObject.transform.position + worldVector);
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
if (this.currentNucleus is Receptor receptor1) {
|
||||
foreach (Nucleus nucleus in receptor1.nucleiArray) {
|
||||
Vector3 worldVector = this.gameObject.transform.TransformVector(nucleus.outputValue);
|
||||
Handles.color = Color.yellow;
|
||||
Handles.DrawLine(this.gameObject.transform.position, this.gameObject.transform.position + worldVector);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (this.currentNucleus is Receptor receptor1) {
|
||||
foreach (Nucleus nucleus in receptor1.nucleiArray) {
|
||||
Vector3 worldVector = this.gameObject.transform.TransformVector(nucleus.outputValue);
|
||||
Handles.color = Color.yellow;
|
||||
Handles.DrawLine(this.gameObject.transform.position, this.gameObject.transform.position + worldVector);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Vector3 worldVector = this.gameObject.transform.TransformVector(this.currentNucleus.outputValue);
|
||||
Handles.color = Color.yellow;
|
||||
Handles.DrawLine(this.gameObject.transform.position, this.gameObject.transform.position + worldVector);
|
||||
Vector3 worldVector = this.gameObject.transform.TransformVector(this.currentNucleus.outputValue);
|
||||
Handles.color = Color.yellow;
|
||||
Handles.DrawLine(this.gameObject.transform.position, this.gameObject.transform.position + worldVector);
|
||||
|
||||
}
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@ -904,9 +904,9 @@ public class ClusterInspector : Editor {
|
||||
case Nucleus.Type.Receptor:
|
||||
AddReceptorInput(nucleus);
|
||||
break;
|
||||
case Nucleus.Type.ReceptorArray:
|
||||
AddReceptorArrayInput(nucleus);
|
||||
break;
|
||||
// case Nucleus.Type.ReceptorArray:
|
||||
// AddReceptorArrayInput(nucleus);
|
||||
// break;
|
||||
case Nucleus.Type.ClusterReceptor:
|
||||
AddClusterReceptorInput(nucleus);
|
||||
break;
|
||||
@ -993,7 +993,12 @@ public class ClusterInspector : Editor {
|
||||
|
||||
IEnumerable<Nucleus> nuclei = cluster.nuclei
|
||||
.Except(synapseNuclei);
|
||||
IEnumerable<string> nucleiNames = nuclei.Select(n => n.name);
|
||||
IEnumerable<string> nucleiNames = nuclei
|
||||
.Select(n => {
|
||||
int idx = n.name.IndexOf(':');
|
||||
return idx < 0 ? n.name : n.name[..idx];
|
||||
})
|
||||
.Distinct();
|
||||
|
||||
string[] names = nucleiNames.ToArray();
|
||||
int selectedIndex = -1;
|
||||
@ -1002,7 +1007,9 @@ public class ClusterInspector : Editor {
|
||||
return false;
|
||||
|
||||
Nucleus nucleus = nuclei.ElementAt(selectedIndex);
|
||||
if (nucleus is Neuron neuron)
|
||||
if (nucleus is Receptor receptor)
|
||||
receptor.AddArrayReceiver(this.currentNucleus);
|
||||
else if (nucleus is Neuron neuron)
|
||||
neuron.AddReceiver(this.currentNucleus);
|
||||
else if (nucleus is Cluster subCluster)
|
||||
subCluster.defaultOutput.AddReceiver(this.currentNucleus);
|
||||
|
||||
@ -211,16 +211,16 @@ public class Neuron : Nucleus {
|
||||
|
||||
public float3 CombinatorMax() {
|
||||
float3 max = this.bias;
|
||||
float maxSqrLength = lengthsq(max);
|
||||
float maxLength = length(max);
|
||||
|
||||
//Applying the weight factors
|
||||
foreach (Synapse synapse in this.synapses) {
|
||||
float3 input = synapse.weight * synapse.nucleus.outputValue;
|
||||
|
||||
float inputSqrlength = lengthsq(input);
|
||||
if (inputSqrlength > maxSqrLength) {
|
||||
float inputLength = length(input);
|
||||
if (inputLength > maxLength) {
|
||||
max = input;
|
||||
maxSqrLength = inputSqrlength;
|
||||
maxLength = inputLength;
|
||||
}
|
||||
}
|
||||
return max;
|
||||
|
||||
@ -42,7 +42,7 @@ public abstract class Nucleus {
|
||||
Cluster,
|
||||
Pulsar,
|
||||
Receptor,
|
||||
ReceptorArray,
|
||||
// ReceptorArray,
|
||||
ClusterReceptor,
|
||||
}
|
||||
|
||||
|
||||
@ -55,6 +55,15 @@ public class Receptor : Neuron, IReceptor {
|
||||
this.nucleiArray = IReceptorHelpers.RemoveReceptorElement(this.nucleiArray);
|
||||
}
|
||||
|
||||
// public override void AddReceiver(Nucleus receiverToAdd, float weight = 1) {
|
||||
// foreach (Nucleus element in receptorToAdd.nucleiArray) {
|
||||
// if (element is Neuron neuron) {
|
||||
// neuron._receivers.Add(receiverToAdd);
|
||||
// receiverToAdd.AddSynapse(element, weight);
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
public virtual void AddArrayReceiver(Nucleus receiverToAdd, float weight = 1) {
|
||||
foreach (Nucleus element in this._array.nuclei) {
|
||||
if (element is Neuron neuron) {
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/*
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -258,4 +259,5 @@ public class ReceptorArray : Nucleus {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
Loading…
x
Reference in New Issue
Block a user