【发布时间】:2014-07-20 20:40:43
【问题描述】:
我刚刚创建了我的第一个神经网络,它使用梯度法和反向传播学习算法。它使用双曲正切作为激活函数。代码经过了很好的单元测试,所以我对网络能够真正工作充满希望。然后我决定创建一个集成测试并尝试教我的网络解决一些非常简单的功能。基本上我正在测试权重是否有所改善(只有一个,因为这是一个非常小的网络 - 输入加上一个神经元)。
// Combinations of negative sign for values greater than 1
[TestCase(8, 4)] // FAIL reason 1
[TestCase(-8, 4)] // FAIL reason 1
[TestCase(8, -4)] // FAIL reason 1
[TestCase(-8, -4)] // FAIL reason 1
// Combinations of negative sign for values lesser than 1
[TestCase(.8, .4)] // OK
[TestCase(-.8, .4)] // FAIL reason 2
[TestCase(.8, -.4)] // FAIL reason 2
[TestCase(-.8, -.4)] // OK
// Combinations of negative sign for one value greater than 1 and the other value lesser than 1
[TestCase(-.8, 4)] // FAIL reason 2
[TestCase(8, -.4)] // FAIL reason 2
// Combinations of one value greater than 1 and the other value lesser than 1
[TestCase(.8, 4)] // OK
[TestCase(8, .4)] // FAIL reason 1
public void ShouldImproveLearnDataSetWithNegativeExpectedValues(double expectedOutput, double x)
{
var sut = _netBuilder.Build(1, 1); // one input, only one layer with one output
sut.NetSpeedCoefficient = .9;
for (int i = 0; i < 400; i++)
{
sut.Feed(new[] { x }, new[] { expectedOutput });
}
var postFeedOutput = sut.Ask(new[] { x }).First();
var postFeedDifference = Math.Abs(postFeedOutput - expectedOutput);
postFeedOutput.Should().NotBe(double.NaN);
postFeedDifference.Should().BeLessThan(1e-5);
}
我非常失望,因为大多数测试用例都失败了(只有 3 个标有“// OK”的测试通过了)。我深入研究了代码,发现了一些有趣的事实。
- 双曲正切最大值为 1。因此,无论权重 * 输入的总和有多大,神经元的输出绝对值将始终
- 在其中一个数字为负数的测试用例中,最终权重也应为负数。首先它减少了,但它永远不会变成负数。它要么在 0 左右停止,要么在 0 左右来回跳跃。
神经网络是否只能解决具有 0..1 个输入值和 0..1 个预期输出值的问题,还是我的实现有问题?
【问题讨论】:
标签: artificial-intelligence neural-network