I want to learn how does an Adaline neuron works.
I written a sample code with VB.NET, and I want to train AND function or OR function for a neuron.
Here is my code :
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
I tried with bias and without bias. (If you remove comment mark from the commented parts, a bias will be added to neuron)
and I tried with these training sets for AND & OR:
-1 -1 -1
-1 1 -1
1 -1 -1
1 1 1
0 0 0
0 1 0
1 0 0
1 1 1
0 0 0
0 1 1
1 0 1
1 1 1
-1 -1 -1
-1 1 1
1 -1 1
1 1 1
But the neuron can’t trained with any of these training sets…
How do I solve my problem?
The problem is :
My hard limit function changes the output in 1, but it should change the answer at 0.
This is the changed part of code:
I tried it with bias enabled and it successfully trained AND & OR functions.