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