Thursday, November 28, 2013

Matlab NNtool : Simple Perceptron model

Its been quite a while since my last post. The past few months have been busy as I spent most of the time working on my research work. I'm back with my zeal to share with you what I have been learning.
Note:  Don't worry if you are not accustomed to the word perceptron. The only pre-requisite for this tutorial is your basic understanding of AND gate. If you are still not confident Google "AND gate".
  In the beginning I was looking at neural networks as a theoretical  perspective but to completely understand its true nature we have to implement it. Though it is not possible to implement immediately, we can use tools like NNtool (Neural networks tool) to simulate and analyze the networks. Besides reducing the time consumed, it is easier to do a comparative study on different type of networks. This tutorial is focused on implementing AND gate logic with a simple perceptron model. If you are not sure about how neuron works just imagine a bucket of water. If you keep on adding water (will increase weight) to the bucket at a certain point of time it overflows.
   Please follow the steps carefully. If you are stuck at any step, please mention your query in the comments below.
1. Download Matlab (Dont ask me which version :P i.e..e Any version of Matlab that supports NNtool box can work perfectly. Preferably use the latest version Matlab 2013a/2013b)
2.After installation just start Matlab. (Double click the matlab icon in your desktop after installation :-0)
 3. The truth table for AND gate is as follows:
Where A and B are inputs and A.B is the expected outputs. Now we have to train the neural network in such a way that when ewe give the value of A and B, it should be able to reproduce the output of A.B
4. First we have to define input data as vector matrix. When you type nntool and press enter a popup window will appear. From that popup window press the New button which in turn will produce another popup windows. Under this click the Data tab. Enter name as input_AB, datatype as Input and value as [ 0 0 1 1; 0 1 0 1]. Now if you observe closely the input vector is represented column-wise separated by a semicolon i.e. [A ; B ]. Finally press the create button.
 5. Now it is time to define the target vector. The target vector is represented with name as target_AND, type as Targets and value as [0 0 0 1] (similar to [ A.B ] ). Now press create.
 6. Once Input and target vectors have been defined, the network has to be created. Press the network tab set the name as AND_net, type as Perceptron and respective Input and target data. Don't worry about other parameter (I will explain you that in later tutorials)
 7. Now go back to the earlier popup and double click AND_net. A windows will be created. Under that press the train tab and set the input and target data. Press the train network button.
 8. Once it is trained the performance and the training states occurred during the training process can be analysed.
 9. Now it is time to simulate. Now to provide the input follow step 3 with value as [ 1 ; 1] representing a input 1, 1.
 10. In the Network AND_net popup navigate to the simulate tab. set the input and press Simulate network. Almost done :-)
 11. Now go the nntool popup and double click ANS_net_outputs. BAZZINGA.. we have got the expected output 1. i.e. when we gave the value A and B the perceptron model was able to predict the value of A.B

12. Wonderful isn't it. This is just the simplest of all. Now just try and explore the toolbox and widen your knowledge. (You can understand how your brain works :P)

If you have any queries or suggestions please feel free to contact me ."I always say the minute I stop making mistakes is the minute I stop learning and I've definitely learned a lot".

19 comments:

  1. which part of the total input specifically is used as testing dataset by the nntool?

    ReplyDelete
    Replies
    1. The [1;1] is used as the simple dataset it means that A=1 and B=1 and corresponding output will be X=1(A AND B)

      Delete
  2. May God bless u. Very helpful. Thank you so much!

    ReplyDelete
  3. Why do I get the error message, 'Too Many Output Arguments' when trying to simulate? hope you could help. tq

    ReplyDelete
  4. Thank you very much, you made it really clear and helpful.

    ReplyDelete
  5. Finding the time and actual effort to create a superb article like this is great thing. I’ll learn many new stuff right here! Good luck for the next post buddy..
    CCNA Training in Chennai

    ReplyDelete
  6. If we want to sort positive numbers from negative numbers what are the steps?

    ReplyDelete
  7. Thanks for the good words! Really appreciated. Great post. I’ve been commenting a lot on a few blogs recently, but I hadn’t thought about my approach until you brought it up. 

    python course institute in bangalore
    python Course in bangalore
    python training institute in bangalore

    ReplyDelete
  8. I found your blog while searching for the updates, I am happy to be here. Very useful content and also easily understandable providing.. Believe me I did wrote an post about tutorials for beginners with reference of your blog. 
    Best Devops training in sholinganallur
    Devops training in velachery
    Devops training in annanagar
    Devops training in tambaram

    ReplyDelete
  9. This is a terrific article, and that I would really like additional info if you have got any. I’m fascinated with this subject and your post has been one among the simplest I actually have read.
    Java training in Bangalore | Java training in Marathahalli

    Java training in Bangalore | Java training in Btm layout

    Java training in Bangalore |Java training in Rajaji nagar

    Java training in Bangalore | Java training in Kalyan nagar

    ReplyDelete
  10. A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article. I am learning a lot from you.
    Best Devops training in sholinganallur
    Devops training in velachery
    Devops training in annanagar
    Devops training in tambaram

    ReplyDelete
  11. After reading your post I understood that last week was with full of surprises and happiness for you. Congratz! Even though the website is work related, you can update small events in your life and share your happiness with us too.
    Selenium training in Chennai | Selenium training institute in Chennai | Selenium course in Chennai

    Selenium training in Bangalore | Selenium training institute in Bangalore | Selenium course in Bangalore

    ReplyDelete
  12. Your very own commitment to getting the message throughout came to be rather powerful and have consistently enabled employees just like me to arrive at their desired goals.
    python Online training in chennai
    python Online training in bangalore
    python interview question and answers

    ReplyDelete
  13. Thank you for sharing such great information with us. I really appreciate everything that you’ve done here and am glad to know that you really care about the world that we live in
    angularjs Training in chennai

    angularjs-Training in tambaram

    angularjs-Training in sholinganallur

    angularjs-Training in velachery

    angularjs-Training in pune

    angularjs Training in bangalore

    ReplyDelete