Code Java Example for a Simple Perceptron

Concept of a Simple Perceptron

The simplest biological model of a Simple Perceptron is a neuron and vice versa. That is the easiest mathematical model of a neuron is a perceptron.

The main characteristic of a neuron is to have an indefinite number of input channels called dendrites, and an output channel called an axon.

The dendrites operate as sensors that collect information of the region where they are. Then they derive it towards the body of the neuron that reacts through a synapse that sends a response to the brain.

To achieve all the major delivery targets of globalized companies while decreasing risk and increasing productivity read our blog: Challenges and Solutions on Global Delivery Models.

Concepts of the network

A single and isolated neuron has no reason to be. Its work becomes reasonable insofar it´s associated with other neurons, forming a network. The axon of a neuron delivers its information as an “input signal” to a dendrite of another neuron and so on. The perceptron that picks up the signal onwards spreads forming a network of neurons. They may be biological or semiconductor substrates (logic gates).


In the perceptron, there are two types of learning; the first one uses a learning rate while the second one does not. This learning rate dampens the change in the values of the weights.

The learning algorithm is the same for all neurons. Everything that follows applies to a single neuron in isolation.

What this formula says is how the new weight vector results from subtracting the desired output minus the actual output (obtaining the error, that is the percentage of mistaken of the network). The next pattern will use this new weight vector. Then, it multiplies the result because of learning. Once we obtain this scalar, we must multiply the vector of the pattern increased by it and then add the current weight vector. It is not complicated. Later we will do a small practice to illustrate how to perform these operations.

Simple Perceptron

Code java example of Simple Perceptron.

import java.util.Random;

public class Perceptron {

   public static void main(String[] args) {

       //Valores Entradas

       double x1 = 1.4;

       double x2 = -0.33;


       //Valores Pesos (aleatorios)

       double w1 = new Random().nextDouble();

       double w2 = new Random().nextDouble();


       Neurona n = new Neurona(x1, x2, w1, w2);


       System.out.println("Entrada 1 (x1): " + x1);

       System.out.println("Entrada 2 (x2): " + x2);

       System.out.println("Salida 1 (y1) = " + n.getY1());



public class Neurona {

   final double x1, x2, w1, w2;

   Neurona(double x1, double x2, double w1, double w2) {

       this.x1 = x1;

       this.x2 = x2;

       this.w1 = w1;

       this.w2 = w2;


   public double getY1() {

       double wx, y1;

       wx = (x1 * w1) + (x2 * w2); //Función propagación

       y1 = Math.tanh(wx); //Salida

       return y1;



Advantages of Artificial Intelligence

  • Self-learning.
  • Abstraction of the essence of a set of entries that do not represent common aspects.
  • Offer concrete answers to entries with small variations.
  • They can continue to respond acceptably even if partially damaged.
  • You can get answers in real form.

Disadvantages of Artificial Intelligence

  • The more things you need to learn, the more complicated it will be to teach you.
  • A high amount of data for training.
  • Lack of hardware due to the amount of data to process.
  • Lack of defining rules that help build a network for a given problem.

A further reading on Virtual and augmented reality technologies and how they can now be mass produced. Understand the basics of these gadgets here and be ready for the future!

You may also like


AI And The Future Of Jobs

artificial intelligence

Artificial Intelligence

History of 4G

History of 4G- All That You Need To Know