In the field of Machine Learning, the Perceptron is a Supervised Learning Algorithm for binary classifiers. The Perceptron Model implements the following function:

For a particular choice of the weight vector and bias parameter , the model predicts output for the corresponding input vector .

**OR** logical function truth table for * 2-bit binary variables*, i.e, the input vector and the corresponding output –

0 | 0 | 0 |

0 | 1 | 1 |

1 | 0 | 1 |

1 | 1 | 1 |

Now for the corresponding weight vector of the input vector , the associated Perceptron Function can be defined as:

For the implementation, considered weight parameters are and the bias parameter is .

**Python Implementation:**

`# importing Python library ` `import` `numpy as np ` ` ` `# define Unit Step Function ` `def` `unitStep(v): ` ` ` `if` `v >` `=` `0` `: ` ` ` `return` `1` ` ` `else` `: ` ` ` `return` `0` ` ` `# design Perceptron Model ` `def` `perceptronModel(x, w, b): ` ` ` `v ` `=` `np.dot(w, x) ` `+` `b ` ` ` `y ` `=` `unitStep(v) ` ` ` `return` `y ` ` ` `# OR Logic Function ` `# w1 = 1, w2 = 1, b = -0.5 ` `def` `OR_logicFunction(x): ` ` ` `w ` `=` `np.array([` `1` `, ` `1` `]) ` ` ` `b ` `=` `-` `0.5` ` ` `return` `perceptronModel(x, w, b) ` ` ` `# testing the Perceptron Model ` `test1 ` `=` `np.array([` `0` `, ` `1` `]) ` `test2 ` `=` `np.array([` `1` `, ` `1` `]) ` `test3 ` `=` `np.array([` `0` `, ` `0` `]) ` `test4 ` `=` `np.array([` `1` `, ` `0` `]) ` ` ` `print` `(` `"OR({}, {}) = {}"` `.` `format` `(` `0` `, ` `1` `, OR_logicFunction(test1))) ` `print` `(` `"OR({}, {}) = {}"` `.` `format` `(` `1` `, ` `1` `, OR_logicFunction(test2))) ` `print` `(` `"OR({}, {}) = {}"` `.` `format` `(` `0` `, ` `0` `, OR_logicFunction(test3))) ` `print` `(` `"OR({}, {}) = {}"` `.` `format` `(` `1` `, ` `0` `, OR_logicFunction(test4))) ` |

*chevron_right*

*filter_none*

**Output:**

OR(0, 1) = 1 OR(1, 1) = 1 OR(0, 0) = 0 OR(1, 0) = 1

Here, the model predicted output () for each of the test inputs are exactly matched with the OR logic gate conventional output () according to the truth table for 2-bit binary input.

Hence, it is verified that the perceptron algorithm for OR logic gate is correctly implemented.

Attention geek! Strengthen your foundations with the **Python Programming Foundation** Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the **Python DS** Course.

## Recommended Posts:

- Implementation of Perceptron Algorithm for AND Logic Gate with 2-bit Binary Input
- Implementation of Perceptron Algorithm for NOR Logic Gate with 2-bit Binary Input
- Implementation of Perceptron Algorithm for NAND Logic Gate with 2-bit Binary Input
- Implementation of Perceptron Algorithm for XOR Logic Gate with 2-bit Binary Input
- Implementation of Perceptron Algorithm for XNOR Logic Gate with 2-bit Binary Input
- Perceptron Algorithm for Logic Gate with 3-bit Binary Input
- Implementation of Perceptron Algorithm for NOT Logic Gate
- Implementation of Artificial Neural Network for AND Logic Gate with 2-bit Binary Input
- Implementation of Artificial Neural Network for OR Logic Gate with 2-bit Binary Input
- Implementation of Artificial Neural Network for NAND Logic Gate with 2-bit Binary Input
- Implementation of Artificial Neural Network for NOR Logic Gate with 2-bit Binary Input
- Implementation of Artificial Neural Network for XOR Logic Gate with 2-bit Binary Input
- Implementation of Artificial Neural Network for XNOR Logic Gate with 2-bit Binary Input
- OR Gate using Perceptron Network
- Page Rank Algorithm and Implementation
- ML | Reinforcement Learning Algorithm : Python Implementation using Q-learning
- Genetic Algorithm for Reinforcement Learning : Python implementation
- Box Blur Algorithm - With Python implementation
- Hebbian Learning Rule with Implementation of AND Gate
- Logic Gates in Python

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.