Good day. Suppose I want to make a simple neural network for XOR:
X = 0, Y = 0, O = 0 | X = 1, Y = 0, O = 1 | X = 0, Y = 1, O = 1 | X = 1, Y = 1, O = 0
I understand that 1.1 and 2.1 are input and the value is transferred to them without change. After transmitting the signals further, in each neuron the value is multiplied by weight, etc. At the end I have to compare the outputs of 1.3 and 2.3 and get the answer, if it is 1 row, then the answer is 0, if 2 is the answer 1.
For simplicity, let the neuron class contain the weight per input (ie, 2) and the signal strength:
Class Neuron Public weight() As Double = {0, 0} Public power As Double = 0.0 End Class Next we create an array and get a random weight, within the unit:
Dim neural(2, 1) As Neuron Dim rand As New Random For I As Integer = 0 To 2 Step 1 For J As Integer = 0 To 1 Step 1 neural(I, J) = New Neuron neural(I, J).weight(0) = rand.NextDouble() neural(I, J).weight(1) = rand.NextDouble() Next Next We get the input values:
neural(0, 0).power = Console.ReadLine() neural(0, 1).power = Console.ReadLine() Activation function:
Function Sigmoid(ByRef int As Double) As Double Const e_sigmoid As Double = 2.71828 Return (1 / (1 + (e_sigmoid ^ (-(int))))) End Function And a simple code of operation of this neural network:
For I As Integer = 1 To 2 Step 1 neural(I, 0).power = Sigmoid(((neural(I - 1, 0).power * neural(I, 0).weight(0)) + (neural(I - 1, 1).power * neural(I, 0).weight(1)))) neural(I, 1).power = Sigmoid(((neural(I - 1, 0).power * neural(I, 1).weight(0)) + (neural(I - 1, 1).power * neural(I, 1).weight(1)))) Next Now I have a question whether it will work and how to train it? Examples are not important on what.
