Single layer perceptron learning algorithm program w/ flowchart & Code in C++

Last updated on June 14th, 2020 at 12:48 am

Single layer perceptron is the first proposed neural model created. The content of the local memory of the neuron consists of a vector of weights. The computation of a single layer perceptron is performed over the calculation of sum of the input vector each with the value multiplied by corresponding element of vector of the weights. The value which is displayed in the output will be the input of an activation function.

Algorithm:

  1. Initialize all weights and threshold and values.
  2. Get the weighted sum of one input.
  3. Compare the weighted sum with the threshold and set value to output.
    1. If the input is of class A
      1. If the desired output mismatches with the output
        1. Decrease those weights which have corresponding 1 in the input
      2. Else Take the next input and go to Step 2
    2. Else If the desired output mismatches with the output
      1. Increase those weights which have corresponding 1 in the input
    3. Else Take the next input and go to Step 2
  4. While all weights has been set, take input from the user.
  5. Get the weighted sum for this input
  6. Compare the weighted sum with the threshold
    1. If weighted sum is less then the threshold
      1. input is from Class A
    2. Else input is from Class B

Flowchart of the Program:

Part 01:

Click on image to see enlarged view

Part 02:

Source Code:

You can run the code using the RUN button at the end of the code

Link to source code https://www.onlinegdb.com/

Output:

single-layer-perceptron-learning-algorithm-run-output
It was an assignment when I was having the course Theory of Computation. I don’t think this blog post has simplified the matter at all. However if it helps you anyway, I will be glad to know that.

14 comments

  1. Great work done… It is a bit late… but keep it up… don't let others get to you.. Your post is good and i have benefited from it… Thanx…

Leave a Reply

Your email address will not be published. Required fields are marked *