Tutorials References Exercises Menu
Paid Courses

Artificial Intelligence

Perceptrons

A Perceptron is an Artificial Neuron

It is the simplest possible Neural Network

Neural Networks are the building blocks of Artificial Intelligence.

Frank Rosenblatt

Frank Rosenblatt (1928 – 1971) was an American psychologist notable in the field of Artificial Intelligence.

In 1957 he started something really big.

Scientists had discovered that brain cells (Neurons) receive input from the outside world by electrical signals sent from our senses (eyes, ears, smell, nerves, ... ). The Neurons, then again use electrical signals to send commands to muscles, store information, and make decisions based on previous input.

Frank had the idea that an Artificial Neuron could be created, simulating biological brain principles, with the ability to learn and make decisions.

From these thoughts, he "invented" the Perceptron.

The Perceptron was tested on an IBM 704 computer at Cornell Aeronautical Laboratory in 1957.


Perceptrons

The original Perceptron was designed to take one or more binary inputs and output either 1 or 0.

The idea was to use different weights to represent the importance of each input, and that the sum of the values should be greater than a threshold value before making a decision (like "yes" or "no").

Will I Go to a Concert?

Perceptron

CriteriaInputWeight
Artists is Goodx1 = 0 or 1w1 = 0.7
Weather is Goodx2 = 0 or 1w2 = 0.6
Friend Will Comex3 = 0 or 1w3 = 0.5
Food is Servedx4 = 0 or 1w4 = 0.3
Alcohol is Servedx5 = 0 or 1w5 = 0.4

The Perceptron Algorithm

  • Multiply the inputs with its weights
  • Sum all the results
  • Compute the outcome

Input * Weight

  • x1 * w1 = 1 * 0.7 = 0.7
  • x2 * w2 = 0 * 0.6 = 0
  • x3 * w3 = 1 * 0.5 = 0.5
  • x4 * w4 = 0 * 0.3 = 0
  • x5 * w5 = 1 * 0.4 = 0.4

Sum Results

  • 0.7 + 0.5 + 0.4 = 1.6

Activate a Result

  • If sum > 1.5, return true ("Yes I will go to the Concert")

Example

function activate(sum) {return (sum > 1.5)}

let sum = 0;
const inputs = [1, 0, 1, 0, 1];
const weights = [0.7, 0.6, 0.5, 0.3, 0.4];

for (let i = 0; i < inputs.length; i++) {
  sum += inputs[i] * weights[i];
}

const answer = activate(sum);

Try it Yourself »

In Neuroscience, there is a debate is whether single-neuron encoding or distributed encoding is most relevant for understanding how the brain functions.

It is obvious that a decision like the one above, is not made by one brain neuron.

At least there must be another neuron deciding if the artist is good, and another trying to decide if the weather will be good.

Neural Networks

Neural networks are in fact multi-layer Perceptrons.

The perceptron defines the first step into multi-layered neural networks.

To simulate inputs from many layers, you can change the Binary perceptron with a Decimal perceptron.

Maybe you can develop an algorithms that help you come up with the best possible answer in any situation. 😀

InputCriteriaInputWeight
Artistsis Goodx1 = 70w1 = 0.7
Weatheris Goodx2 = 60w2 = 0.6
Friendwill Comex3 = 50w3 = 0.5
Foodis Servedx4 = 40w4 = 0.3
Alcoholis Servedx5 = 30w5 = 0.4

From the table above, you can see that each input has a different values:

  • Input 1: x1 = 70 (Artist is quite good)
  • Input 5: x5 = 30 (Alcohol is probably not served)

And each input has a weight:

  • Weight 1: w1 = .70 (Quite important)
  • Weight 5: w5 = .40 (Not so important)

The Perceptron Algorithm

  • Multiply the inputs with its weights
  • Sum all of the results
  • Compute the output

Input * Weight

  • x1 * w1 = 70 * 0.7 = 49
  • x2 * w2 = 60 * 0.6 = 36
  • x3 * w3 = 50 * 0.5 = 25
  • x4 * w4 = 40 * 0.3 = 12
  • x5 * w5 = 30 * 0.4 = 12

Sum Results

  • 49 + 36 + 25 + 12 + 12 = 135

Activate a Result

  • If sum > 100, return true ("Yes I will go to the Concert")

In JavaScript

function activate(sum) {return sum > 100}

let sum = 0;
const inputs = [70, 60, 59, 40, 30];
const weights = [0.7, 0.6, 0.5, 0.3, 0.4];

for (let i = 0; i < inputs.length; i++) {
  sum += inputs[i] * weights[i];
}

const answer = activate(sum);

Try it Yourself »


Training a Perceptron

In the next chapters, you will learn more about how to:

  • Program a Perceptron
  • Train a Perceptron