Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

MachineX: Artificial Neural Networks (Part 1)

DZone 's Guide to

MachineX: Artificial Neural Networks (Part 1)

Learn about artificial neural networks and deep learning.

· AI Zone ·
Free Resource

In this article, we will talk about neural networks, which are the base of deep learning and give machine learning an edge in the current AI revolution.

Before diving in, let’s look at:

Why Deep Learning?

  • Deep learning is more popular than shallow-level learning once you have a huge quantity of data (either labeled or not).
  • There is awesome progressive performance in tasks involving text, sound, and images. There have been several advances in computer vision, NLP, and speech recognition.
  • Feature illustration or an abstract representation. We tend to not need to spend time on feature engineering.

Let's learn more about neural networks.

Neuron

A neuron is a computational unit that takes the input(s), does some calculations, and produces the output.

Within the above figure is the one we tend to use in Neural Network. We’ve got the input A neuron and we have some weights (parameters). We apply the real of those two vectors. It will produce the result (which will be a continuous value -infinity to + infinity).

If we wish to limit the output values, we need to use an activation function.

The activation function squashes the output value and turns out a value within a rage (which is based on the kind of activation function).

We have three (Sigmoid ranges from 0 to 1, Tanh from -1 to 1, and Relu from 0 to +infinity).

Activation Function

  • Sigmoid function (σ): g(z) = 1 / (1 + e^{-z}). It’s recommended to be used only on the output layer so that we can easily interpret the output as probabilities since it has restricted output between 0 and 1. One of the main disadvantages for using a sigmoid function on hidden layers is that the gradient is very close to zero over a large portion of its domain, which makes it slow and harder for the learning algorithm to learn.
  • tanh function: tanh is like sigmoid, but better. The range of the tanh function is from (-1 to 1). tanh is also sigmoidal (The advantage is that the negative inputs will be mapped strongly negative and the zero inputs will be mapped near zero in the tanh graph. The tanh function is mainly used classification between two classes.ped).
  • Rectified Linear Unit (ReLU): g(z)= max{0, z}. The models that are close to linear are easy to optimize. Since ReLU shares a lot of the properties of linear functions, it tends to work well on most of the problems. The only issue is that the derivative is not defined at z = 0, which we can overcome by assigning the derivative to 0 at z = 0. However, this means that for z ≤ 0 the gradient is zero and again can’t learn tanh.

Neural Network

A neural network is a set of layers (a layer has a set of neurons) stacked together sequentially.

The output of one layer is the input of the next layer.

In the above image, we have three layers.

  1. Input layer: A set of input neurons where each neuron represents each feature in our dataset. It takes the inputs and passes them to the next layer.
  2. Hidden layer: A set of (n) number of neurons where each neuron has a weight (parameter) assigned to it. It takes the input from the previous layer and does the dot product of inputs and weights, applies activation function (as we have seen above), produces the result, and passes the data to next layer.

Note: We can have (n) number of hidden layers in between (for the sake of understanding, let’s take only one hidden layer).

4. Output layer: it’s the same as the hidden layer except it gives the final result (outcome/class/value).

So, how do we define the number of neurons in each layer and the whole network?

Based on number of features in the dataset, the input layer’s neurons are decided.

  • N_Features= N_i/p_neurons+1(bias)

We can define as many neurons/layers as we wish (it depends on the data and problem), however, it would be good to define features and be sure all hidden layers have the same number of neurons.

  • N_h_neurons+1(bias)>N_Features

For binary classification, you can have 1 or 2 neurons. For multi-classification, you can have more than 2 neurons.

Note: there is no bias here, as it is the last layer in the network.

We got the basic understanding of Neural Networks, so let’s dive deeper.

Once you got the dataset and problem identified, you can follow the below steps:

  1. Pick the network architecture (initialize with random weights)

  2. Do a forward pass (forward propagation)

  3. Calculate the total error (we need to minimize this error)

  4. Back-propagate the error and update weights (backpropagation)

  5. Repeat the process (2-4) for no of epochs/until error is minimum.

There are 2 algorithms in Neural Networks:

  1. Forward propagation

  2. Backpropagation

We will talk about these steps and forward and backward propagation in the next article. Stay tuned!

Topics:
artifical intelligence ,data science ,deep learning ,machine learning ,neural networks ,ai ,neurons

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}