# Why do we need weights when training a perceptron as an OR gate?

Without using any of Matlab's neural network tools, I'm writing a program to simulate an OR gate with a perceptron. I have seen many tutorials, but I still can't understand why we need weights to train a perceptron for such a simple purpose.

One way is to program the perceptron with the conditions (0,0)=0. (1,0)=1. (0,1)=1. (1,1)=1. So the two inputs to the perceptron would be either zeroes or ones. I don't see the purpose of weights here. Assuming weights are 1, for the second training example, the output would be 1*1 + 0*1 = 1. For the last example, it would be 1*1 + 1*1 = 2. So an activation function which says if output >= 1, output = 1 else output =0; end should suffice. This would successfully simulate an OR gate. So why do I need to "train" any weights?

• Update: I got a hint from the Perceptron Learning example. University of Kurdistan. The table on page 4 is self explanatory, but the question still persists. Why weights? eng.uok.ac.ir/esmaili/teaching/spring2012/nn/slides/…
– Nav
Oct 20 '17 at 7:20
• Why would you use a perceptron as an OR gate at all? It is a pedagogical tool to show how a perceptron can map to a specific function. Oct 20 '17 at 13:55
• @antlersoft: It's for a pedagogical purpose. I'm learning how these things work. Hard to believe these techniques model the brain. Looks like it's designed to model the computer more than a brain. Even if the brain performs logical operations.
– Nav
Oct 21 '17 at 2:12

There are two aspects that you need to consider:

1. Because it is part of the definition of a perceptron. There are many different mechanisms to implement an OR gate, most of them rather easy. But if you want to implement it based on a perceptron, you have to follow the definition of the perceptron. Otherwise you would just implement an OR gate without using an actual perceptron.

2. The purpose of an neural network is to initialize it more or less randomly without knowing the correct weights and biases for each neuron (or perceptron in your case). You just know the desired behavior of the network and you train it accordingly. In your example you know the desired output of the OR gate and can train your network to give you this desired output. What's bothering you is the fact that you can easily derive the correct weights without actual training the network just by analyzing it. That's because this is a theoretical example to show that a perceptron is capable to learn the behavior of an OR gate. In a real application you would not benefit from artificially crafting an OR gate based on an perceptron.

This would successfully simulate an OR gate.

Of course. In fact, hardware implementation of an OR gate needs just a few transistors. It may sound surprising, but the best python implementation of OR is a or b.

So why do I need to "train" any weights?

It's one of the simplest functions out there, everyone understands how OR works just from the boolean table. The task shows that a neural network can learn it as well, just from examples and without specification what a logical operation is and how to wire it.