WIP reciprocal activation

This commit is contained in:
Pascal Serrarens 2026-06-29 17:25:05 +02:00
parent 9258655c0b
commit 737cbfcfe5
2 changed files with 35 additions and 19 deletions

View File

@ -150,20 +150,20 @@ namespace NanoBrain.Unity {
else if (selectedTarget is GameObject g)
gameObject = g;
// Handles.color = Color.yellow;
// if (Cluster_Drawer.currentClusterView.selectedSynapseNeuron != null) {
// foreach (Cluster sibling in Cluster_Drawer.currentClusterView.selectedSynapseNeuron.parent.instances) {
// Neuron siblingNeuron = sibling.GetNeuron(Cluster_Drawer.currentClusterView.selectedSynapseNeuron.name);
// Vector3 worldVector = gameObject.transform.TransformVector(siblingNeuron.outputValue);
// Handles.DrawLine(gameObject.transform.position, gameObject.transform.position + worldVector);
// }
// }
// else {
// if (Cluster_Drawer.currentClusterView.currentNucleus is Neuron currentNeuron) {
// Vector3 worldVector = gameObject.transform.TransformVector(currentNeuron.outputValue);
// Handles.DrawLine(gameObject.transform.position, gameObject.transform.position + worldVector);
// }
// }
Handles.color = Color.yellow;
if (Cluster_Drawer.currentClusterView.selectedSynapseNeuron != null) {
foreach (Cluster sibling in Cluster_Drawer.currentClusterView.selectedSynapseNeuron.parent.instances) {
Neuron siblingNeuron = sibling.GetNeuron(Cluster_Drawer.currentClusterView.selectedSynapseNeuron.name);
Vector3 worldVector = gameObject.transform.TransformVector(siblingNeuron.outputValue);
Handles.DrawLine(gameObject.transform.position, gameObject.transform.position + worldVector);
}
}
else {
if (Cluster_Drawer.currentClusterView.currentNucleus is Neuron currentNeuron) {
Vector3 worldVector = gameObject.transform.TransformVector(currentNeuron.outputValue);
Handles.DrawLine(gameObject.transform.position, gameObject.transform.position + worldVector);
}
}
}
}

View File

@ -355,14 +355,15 @@ namespace NanoBrain
{
Debug.Break();
}
var combination = Combinator(this.bias, this.synapses);
this.outputValue = Activator(combination);
this.combinationValue = Combinator(this.bias, this.synapses);
this.outputValue = Activator(this.combinationValue);
this.lastUpdate = Time.time;
}
#region Combinator
#if UNITY_MATHEMATICS
public float3 combinationValue;
/// <summary>
/// The combinator which combines the bias with the values from all synapses
@ -418,6 +419,7 @@ namespace NanoBrain
}
#else
public Vector3 combinationValue;
/// <summary>
/// The combinator which combines the bias with the values from all synapses
@ -716,9 +718,23 @@ namespace NanoBrain
// loss is a derivative of error
// Backpropagation = loss * d(combinator)
// Assuming linear activation function.
// Derivative of this (f'()) would be 1.
Vector3 delta2 = loss * 1;
Vector3 delta2;
switch (activator)
{
case ActivationType.Linear:
// Derivative of this (f'()) would be 1.
delta2 = loss * 1;
break;
case ActivationType.Power:
delta2 = loss * (2 * this.combinationValue);
break;
case ActivationType.Reciprocal:
delta2 = loss * (-1 / (this.combinationValue * this.combinationValue));
break;
default:
delta2 = loss;
break;
}
Vector3 scaledOutput = Vector3.Scale(delta2, synapse.neuron.outputValue);
float deltaWeight = Mathf.Abs(scaledOutput.x) + Mathf.Abs(scaledOutput.y) + Mathf.Abs(scaledOutput.z);