pre: activation function to synapse neuron

This commit is contained in:
Pascal Serrarens 2026-01-07 17:16:35 +01:00
parent cd74c312dc
commit b9b942760b
2 changed files with 7 additions and 18 deletions

View File

@ -75,30 +75,19 @@ public class Neuroid : Nucleus {
}
public override void UpdateState() {
Vector3 sum = Vector3.zero;
Vector3 result = Vector3.zero;
int n = 0;
foreach (Synapse synapse in this.synapses) {
if (synapse.nucleus.isSleeping)
continue;
Vector3 outputValue = synapse.nucleus.outputValue;
float weight = synapse.weight;
// As this is the activation function, it should be evaluated in the synapse.nucleus...
float activatedValue = curve.Evaluate(outputValue.magnitude);
float magnitude = weight * activatedValue;
//Spherical sVector = new(magnitude, outputValue.direction);
float magnitude = synapse.weight * activatedValue;
sum += magnitude * outputValue.normalized;//sVector.ToVector3();
result += magnitude * outputValue.normalized;
n++;
}
//Spherical result;
Vector3 result;
if (average)
//result = Spherical.FromVector3(sum / n);
result = sum / n;
else
//result = Spherical.FromVector3(sum);
result = sum;
result /= n;
UpdateResult(result);
}

View File

@ -65,7 +65,7 @@ public class Nucleus {
public NanoBrainObj brain { get; set; }
private Vector3 _outputValue;
public Vector3 outputValue //{ get; set; }
public Vector3 outputValue
{
get { return _outputValue; }
set {
@ -154,7 +154,7 @@ public class Nucleus {
public virtual void UpdateState() { }
public void UpdateResult(Vector3 result) {
// float d = Spherical.Distance(result, this.outputValue);
// float d = Vector3.Distance(result, this.outputValue);
// if (d < 0.1f) {
// //Debug.Log($"insignificant update: {d}");
// return;