WIP reciprocal activation
This commit is contained in:
parent
9258655c0b
commit
737cbfcfe5
@ -150,20 +150,20 @@ namespace NanoBrain.Unity {
|
|||||||
else if (selectedTarget is GameObject g)
|
else if (selectedTarget is GameObject g)
|
||||||
gameObject = g;
|
gameObject = g;
|
||||||
|
|
||||||
// Handles.color = Color.yellow;
|
Handles.color = Color.yellow;
|
||||||
// if (Cluster_Drawer.currentClusterView.selectedSynapseNeuron != null) {
|
if (Cluster_Drawer.currentClusterView.selectedSynapseNeuron != null) {
|
||||||
// foreach (Cluster sibling in Cluster_Drawer.currentClusterView.selectedSynapseNeuron.parent.instances) {
|
foreach (Cluster sibling in Cluster_Drawer.currentClusterView.selectedSynapseNeuron.parent.instances) {
|
||||||
// Neuron siblingNeuron = sibling.GetNeuron(Cluster_Drawer.currentClusterView.selectedSynapseNeuron.name);
|
Neuron siblingNeuron = sibling.GetNeuron(Cluster_Drawer.currentClusterView.selectedSynapseNeuron.name);
|
||||||
// Vector3 worldVector = gameObject.transform.TransformVector(siblingNeuron.outputValue);
|
Vector3 worldVector = gameObject.transform.TransformVector(siblingNeuron.outputValue);
|
||||||
// Handles.DrawLine(gameObject.transform.position, gameObject.transform.position + worldVector);
|
Handles.DrawLine(gameObject.transform.position, gameObject.transform.position + worldVector);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// else {
|
else {
|
||||||
// if (Cluster_Drawer.currentClusterView.currentNucleus is Neuron currentNeuron) {
|
if (Cluster_Drawer.currentClusterView.currentNucleus is Neuron currentNeuron) {
|
||||||
// Vector3 worldVector = gameObject.transform.TransformVector(currentNeuron.outputValue);
|
Vector3 worldVector = gameObject.transform.TransformVector(currentNeuron.outputValue);
|
||||||
// Handles.DrawLine(gameObject.transform.position, gameObject.transform.position + worldVector);
|
Handles.DrawLine(gameObject.transform.position, gameObject.transform.position + worldVector);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -355,14 +355,15 @@ namespace NanoBrain
|
|||||||
{
|
{
|
||||||
Debug.Break();
|
Debug.Break();
|
||||||
}
|
}
|
||||||
var combination = Combinator(this.bias, this.synapses);
|
this.combinationValue = Combinator(this.bias, this.synapses);
|
||||||
this.outputValue = Activator(combination);
|
this.outputValue = Activator(this.combinationValue);
|
||||||
this.lastUpdate = Time.time;
|
this.lastUpdate = Time.time;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Combinator
|
#region Combinator
|
||||||
|
|
||||||
#if UNITY_MATHEMATICS
|
#if UNITY_MATHEMATICS
|
||||||
|
public float3 combinationValue;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The combinator which combines the bias with the values from all synapses
|
/// The combinator which combines the bias with the values from all synapses
|
||||||
@ -418,6 +419,7 @@ namespace NanoBrain
|
|||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
public Vector3 combinationValue;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The combinator which combines the bias with the values from all synapses
|
/// The combinator which combines the bias with the values from all synapses
|
||||||
@ -716,9 +718,23 @@ namespace NanoBrain
|
|||||||
// loss is a derivative of error
|
// loss is a derivative of error
|
||||||
// Backpropagation = loss * d(combinator)
|
// Backpropagation = loss * d(combinator)
|
||||||
|
|
||||||
// Assuming linear activation function.
|
Vector3 delta2;
|
||||||
// Derivative of this (f'()) would be 1.
|
switch (activator)
|
||||||
Vector3 delta2 = loss * 1;
|
{
|
||||||
|
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);
|
Vector3 scaledOutput = Vector3.Scale(delta2, synapse.neuron.outputValue);
|
||||||
float deltaWeight = Mathf.Abs(scaledOutput.x) + Mathf.Abs(scaledOutput.y) + Mathf.Abs(scaledOutput.z);
|
float deltaWeight = Mathf.Abs(scaledOutput.x) + Mathf.Abs(scaledOutput.y) + Mathf.Abs(scaledOutput.z);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user