我想了解Adaline神经元的工作原理。
我用VB.NET编写了一个示例代码,我想训练一个神经元来实现AND或OR功能。
这是我的代码:
Dim Valid As Boolean Dim c As Integer = 0 Do Valid = True c += 1 For i As Integer = 0 To ListBox1.Items.Count - 1 Dim s() As String = Microsoft.VisualBasic.Split(ListBox1.Items(i), " ") Dim y As Single = (W(1) * CInt(s(0)) + W(2) * CInt(s(1)))' + W(3) * 1) W(1) += Alpha * CSng(CInt(s(2)) - y) * CSng(CInt(s(0))) W(2) += Alpha * CSng(CInt(s(2)) - y) * CSng(CInt(s(1))) 'W(3) += Alpha * CSng(CInt(s(2)) - y) * 1.0 Next For i As Integer = 0 To ListBox1.Items.Count - 1 Dim s() As String = Microsoft.VisualBasic.Split(ListBox1.Items(i), " ") Dim y As Single = (W(1) * CInt(s(0)) + W(2) * CInt(s(1)))' + W(3) * 1) If CInt(s(2)) = 1 Then If y < 1 Then Valid = False End If Else If y >= 1 Then Valid = False End If End If Next Loop Until ((Valid) Or (c > 100000)) If c > 10000 Then MsgBox("I Can't Learn!", MsgBoxStyle.Exclamation) End If
我尝试了有偏置和无偏置的情况。(如果你从注释部分移除注释标记,将会为神经元添加偏置)
我还尝试了这些训练集来训练AND和OR功能:
-1 -1 -1-1 1 -11 -1 -11 1 10 0 00 1 01 0 01 1 10 0 00 1 11 0 11 1 1-1 -1 -1-1 1 11 -1 11 1 1
但神经元无法用这些训练集进行训练…
我该如何解决这个问题?
回答:
问题是:我的硬限制函数将输出改为1,但它应该在0时改变答案。
这是修改后的代码部分:
If CInt(s(2)) = 1 Then If y < 0 Then Valid = False End If Else If y >= 0 Then Valid = False End If
我尝试启用偏置后,成功训练了AND和OR功能。