Fix set weight on receptor arrays

This commit is contained in:
Pascal Serrarens 2026-03-04 15:22:36 +01:00
parent 1dfe65eefa
commit 28ffae8ce7
9 changed files with 1319 additions and 125 deletions

View File

@ -104,7 +104,7 @@ public class Cluster : Nucleus {
foreach (Nucleus prefabArrayNucleus in prefabReceptor.nucleiArray) {
int arrayNucleusIx = GetNucleusIndex(prefabNuclei, prefabArrayNucleus);
if (arrayNucleusIx >= 0) {
Neuron clonedArrayNucleus = clonedNuclei[arrayNucleusIx] as Neuron;
Nucleus clonedArrayNucleus = clonedNuclei[arrayNucleusIx];
clonedArray.nuclei[arrayIx] = clonedArrayNucleus;
}
else {

View File

@ -152,6 +152,7 @@ public class ClusterReceptor : Cluster, IReceptor {
public virtual void ProcessStimulus(Neuron input, Vector3 inputValue, int thingId = 0, string thingName = null) {
CleanupReceivers();
Debug.Log($"{input.name} is {inputValue}, 1/{inputValue} = {1 / inputValue.x}, {1/inputValue.y}, {1/inputValue.z}");
//inputValue = input.Activator(inputValue);
if (!thingReceivers.TryGetValue(thingId, out ClusterReceptor selectedReceiver))
@ -173,6 +174,7 @@ public class ClusterReceptor : Cluster, IReceptor {
if (selectedReceiver.clusterNuclei[inputIx] is Neuron selectedNeuron)
selectedNeuron.ProcessStimulusDirect(inputValue);
Debug.Log($"cluster output = {selectedReceiver.defaultOutput.outputValue}");
}
// private ClusterReceptor FindReceiver(int thingId, float3 inputValue) {
@ -220,7 +222,6 @@ public class ClusterReceptor : Cluster, IReceptor {
private ClusterReceptor FindReceiver2(int thingId, float3 inputValue) {
// No existing nucleus for this thing
//float inputMagnitude = length(inputValue);
ClusterReceptor selectedReceiver = null;
float selectedMagnitude = 0;
foreach (ClusterReceptor receiver in this.nucleiArray.Cast<ClusterReceptor>()) {

View File

@ -176,7 +176,7 @@ public class ClusterInspector : Editor {
if (this.prefabAsset == null) {
// create in memory save if it doesn't exist
this.prefabAsset = CreateInstance<ClusterPrefab>();
Debug.LogError("Cluster Prefab is not found on disk");
//Debug.LogError("Cluster Prefab is not found on disk");
}
DrawInspector(inspectorContainer);
}
@ -752,10 +752,10 @@ public class ClusterInspector : Editor {
EditorGUI.indentLevel++;
float newWeight = EditorGUILayout.FloatField("Weight", synapse.weight);
if (newWeight != synapse.weight) {
if (synapse.nucleus is IReceptor receptor) {
if (synapse.nucleus.parent is IReceptor receptor) {
Nucleus[] receptorArray = receptor.nucleiArray;
foreach (Synapse s in this.currentNucleus.synapses) {
if (s.nucleus is IReceptor r && r.nucleiArray == receptorArray)
if (s.nucleus.parent is IReceptor r && r.nucleiArray == receptorArray)
s.weight = newWeight;
}
}

1305
NewVelocity.asset Normal file

File diff suppressed because it is too large Load Diff

8
NewVelocity.asset.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 61eea9f818639ec20b7a7bf4e86fff66
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,54 +0,0 @@
// using System;
// using Unity.Mathematics;
// /// <summary>
// /// The Pulsar represents a type of neuron that operates based on
// /// the product of its weighted inputs rather than the traditional summation.
// /// Drawing inspiration from the concept of pulsars in astrophysics
// /// —highly magnetized rotating neutron stars that emit beams of radiation—
// /// the Pulsar could symbolize dynamic, focused output based on the interaction of multiple factors.
// /// </summary>
// /// Multiplicative Functionality:
// /// Instead of summing inputs, the Pulsar takes the weighted product of its inputs.
// /// This means that all inputs must be active (non-zero) for the neuron to "pulse" or activate.
// /// Output Behavior:
// /// The output could amplify or diminish depending on the magnitude of the inputs.
// /// The product would be sensitive to small values,
// /// which means that even a small input could significantly lower the overall output if multiplied.
// /// Activation Mechanism:
// /// The activation function can further refine the output from the product result.
// /// For instance, a certain threshold could be used to determine if a pulse occurs.
// /// Modeling Complex Interactions:
// /// The Pulsar could be particularly beneficial for modeling situations where interactions multiply rather than add.
// /// This is useful in fields such as economics (e.g., compound growth models),
// /// biology (e.g., interaction of hormones), and machine learning where multiplicative relationships exist.
// [Serializable]
// public class Pulsar : Neuron {
// public Pulsar(Cluster parent, string name) : base(parent, name) {
// // To prevent mistakes, bias one (instead of zero for standard neurons)
// this.bias = new float3(1, 1, 1);
// }
// public Pulsar(ClusterPrefab parent, string name) : base(parent, name) {
// // To prevent mistakes, bias one (instead of zero for standard neurons)
// this.bias = new float3(1, 1, 1);
// }
// public override Nucleus ShallowCloneTo(Cluster newParent) {
// Pulsar clone = new(newParent, this.name);
// CloneFields(clone);
// return clone;
// }
// public override void UpdateStateIsolated() {
// float3 product = this.bias;
// //Applying the weight factors
// foreach (Synapse synapse in this.synapses) {
// float3 input = synapse.weight * synapse.nucleus.outputValue;
// product *= input;
// }
// // Activation function
// this.outputValue = Activator(product);
// }
// }

View File

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 46bd155173053a01585411c3e07f85d4

View File

@ -1,62 +0,0 @@
// using System;
// using Unity.Mathematics;
// using static Unity.Mathematics.math;
// [Serializable]
// public class Selector : Neuron {
// public Selector(Cluster parent, string name) : base(parent, name) { }
// public Selector(ClusterPrefab parent, string name) : base(parent, name) {}
// public override Nucleus ShallowCloneTo(Cluster newParent) {
// Selector clone = new(newParent, this.name) {
// // array = this.array,
// curve = this.curve,
// curvePreset = this.curvePreset,
// curveMax = this.curveMax,
// };
// return clone;
// }
// public override void UpdateStateIsolated() { //float3 bias) {
// float3 max = this.bias;
// float maxSqrLength = lengthsq(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) {
// max = input;
// maxSqrLength = inputSqrlength;
// }
// }
// // Activation function
// float3 result;
// switch (this.curvePreset) {
// case CurvePresets.Linear:
// result = max;
// break;
// case CurvePresets.Sqrt:
// result = normalize(max) * System.MathF.Sqrt(length(max));
// break;
// case CurvePresets.Power:
// result = normalize(max) * System.MathF.Pow(length(max), 2);
// break;
// case CurvePresets.Reciprocal: {
// float magnitude = length(max);
// if (magnitude > 0)
// result = normalize(max) * (1 / magnitude);
// else
// result = float3(0, 0, 0);
// break;
// }
// default:
// float activatedValue = this.curve.Evaluate(length(max));
// result = normalize(max) * activatedValue;
// break;
// }
// this.outputValue = result;
// }
// }

View File

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 4218c2f3f15af944db0eadd6e1500d17