The brain is made up of hundreds of billions of cells called neurons. These neurons are connected together by synapses, which are nothing more than connections through which a neuron can send an impulse to another neuron. When a neuron sends an excitation signal to another neuron, that signal will be added to all other inputs of that neuron. If it exceeds the specified threshold, it will cause the target neuron to fire a forward action signal — this is how the thought process works internally.
In computer science, we model this process by creating “networks” on a computer using matrices. These networks can be understood as an abstraction of neurons without considering all the biological complexities. For simplicity, we`ll just simulate a simple NN with two levels capable of solving linear classification problems.
Let`s say we have a problem where we want to predict an output using a set of inputs and outputs as a teaching example, like this:
Note that the output is directly related to the third column, i.e. the values of input 3 correspond to output values m in each training example in Fig. 2. Thus, for the test case, the output value should be 1.
The learning process consists of the following stages:
Note. Repeat the whole process for several thousand iterations.
Let`s code the whole process in Python. We will use the Numpy library to make all the matrix calculations easier for us. You need to install the NumPy library on your system to run the code
The command to install numpy:
sudo apt -get install python-numpy
Expected result: after 10 iterations, our neural network predicts a value of 0.65980921. This doesn`t look very good, as the answer should be 1. If we increase the number of iterations to 100, we get 0.87680541. Our network is getting smarter! Subsequently, for 10,000 iterations, we get 0.9897704, which is pretty close and a really satisfying result.
This article is courtesy of Vivek Pal . If you are as Python.Engineering and would like to contribute, you can also write an article using contribute.python.engineering or by posting an article contribute @ python.engineering. See my article appearing on the Python.Engineering homepage and help other geeks.
Please post comments if you find anything wrong or if you would like to share more information on the topic discussed above.