3D DeltaWeight fix
This commit is contained in:
parent
50e09c0db3
commit
10e1dd0126
@ -36,9 +36,7 @@ namespace NanoBrain {
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
public virtual void BackPropagation(Neuron receiver, float error, float learningRate) {
|
||||
float derivative = error;
|
||||
|
||||
public virtual void BackPropagation(Neuron receiver, float derivative, float learningRate) {
|
||||
switch (receiver.activator) {
|
||||
case Neuron.ActivationType.Linear:
|
||||
derivative *= 1;
|
||||
@ -67,8 +65,6 @@ namespace NanoBrain {
|
||||
}
|
||||
|
||||
public virtual void BackPropagation(Neuron receiver, Vector3 derivative, float learningRate) {
|
||||
//Vector3 derivative = error;
|
||||
|
||||
switch (receiver.activator) {
|
||||
case Neuron.ActivationType.Linear:
|
||||
derivative *= 1;
|
||||
@ -83,21 +79,28 @@ namespace NanoBrain {
|
||||
break;
|
||||
default:
|
||||
Debug.Log("other activator");
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
this.neuron.BackPropagation3D(derivative * this.weight, learningRate);
|
||||
|
||||
derivative = Vector3.Scale(derivative, this.neuron.activation);
|
||||
derivative *= math.length(this.neuron.activation);
|
||||
|
||||
if (this.trainable) {
|
||||
// Compared to the 1D solution, this does not decrease the weight.
|
||||
// direction and sign are different....
|
||||
// Perhaps the sign is determine by the direction of the derivative and the neuron activation?
|
||||
// When they are oppositie, the sign is negative? (or the other way round...)
|
||||
this.weight += learningRate * derivative.magnitude;
|
||||
float deltaWeight = learningRate * derivative.magnitude;
|
||||
// Compared to the 1D solution, this does not decrease the weight because magnitude is always positive
|
||||
// derivative.direction and derivative.sign are different....
|
||||
if (AreOpposed(derivative, this.neuron.activation))
|
||||
this.weight -= deltaWeight;
|
||||
else
|
||||
this.weight += deltaWeight;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool AreOpposed(Vector3 a, Vector3 b) {
|
||||
// Check if the angle between the vectors is > 90 degrees
|
||||
return Vector3.Dot(a, b) < 0f;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user