Skip to content

Commit d75ff5f

Browse files
committed
break gradient
1 parent ee89d5e commit d75ff5f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

MLTests/GradientLearnTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ private double LearnWeightByGradient(double weight, double input, double predict
1313
for (int iteration = 0; iteration < iterations; iteration++)
1414
{
1515
var prediction = input * result;
16+
var error = Math.Pow(prediction - predictionGoal, 2);
1617
var delta = prediction - predictionGoal;
1718
var weightDelta = delta * input;
1819
result = result - weightDelta;
@@ -67,5 +68,14 @@ public void ShouldLearnWeightIn4Iteration2()
6768
var result = Math.Round(learnedWeight * input, 2);
6869
result.Should().Be(0.8);
6970
}
71+
72+
[Test]
73+
public void ShouldBreakLearnWeight()
74+
{
75+
var (weight, input, predictionGoal, iterations) = (0.0, 2.0, 0.8, 100);
76+
var learnedWeight = LearnWeightByGradient(weight, input, predictionGoal, iterations);
77+
var result = Math.Round(learnedWeight * input, 2);
78+
result.Should().NotBe(0.8);
79+
}
7080
}
7181
}

0 commit comments

Comments
 (0)