Deep Learning algorithm is one of the most powerful learning algorithms of the digital era. It has found a unique place in various industrial applications such as fraud detection in credit approval, automated bank loan approval, stock price prediction etc. Some of the more recent uses of neural networks are image recognition and speech recognition.
In fact, you'd be amazed to know that Google incorporates neural networks into its image search and voice applications. Furthermore, the first successful deep learning model for speech recognition made by Microsoft is now used in Cortana.
This article provides an introduction to deep learning methods in detail.
The first section of the article presents a detailed introduction of the perceptron model and a python implementation of the algorithm. Although the perceptron model is a linear classifier and has limited applications, it forms the building block of the multi-layered neural network. Hence, it is imperative for you to learn.
In the second section, a rather complicated extension of the perceptron model called Deep Learning Network (also known as Multilayered Neural Network) is introduced along with its mathematical and algorithmic development. Additionally, a task of intelligent decision-making has been implemented using Deep Learning.
Note: This article is best suited for people having a concrete understanding of mathematical concepts such as differentiation, matrix multiplication etc.
What is Perceptron Algorithm?
The human brain is astonishingly smart and powerful. It is capable of recognizing the underlying patterns in massive and noisy world's information, memorizing those patterns and generalizing the knowledge for making informed decision making.
Perceptron model is an artificial neural network inspired by biological neural networks and is used to approximate functions that are generally unknown. They are inspired by the behavior of neurons and they convey electrical signals between input (such as from the eyes or nerve endings in the hand), processing, and output from the brain (such as reacting to light, touch, or heat). A biological neuron generates an electrical signal if the strength of the input signal is greater than a threshold value. The biological neural network is a layer of interconnected neurons which receives an external stimulus (such as a sensation of heat) and information propagates all the way to the brain, which in turn generates a response signal which again travels through the neural network.
The Perceptron model was an attempt to replicate human learning inside computers by Frank Rosenblatt in 1957. Here, the neural computational units are called perceptrons. The model is composed of two layers: an input and output layer. The output layer is composed of perceptron units. Each output unit is connected to all the inputs through a weight. Perceptron does the weighted summation of the input signals and processes this sum through a function called "activation function". For a given activation function "f(x)", if the weighted summation of input is z then output produced by the perceptron will be "f(z)".
The activation function of a perceptron is a Heaviside step function "(H(Z))".
Here, z is the weighted summation of the input vector, Wij is weight connecting ith perceptron to jth input node and yi is the output of ith perceptron.
The figure above depicts an input vector with components 1, x1 and x2 connected to a single perceptron unit through weights w0, w1, and w2, respectively. The physical interpretation of weights could be related to the strength of the connection. A weight with a very high value will prejudice the perceptron's response toward the signal from its corresponding input node and vice versa. Here input node with value 1 is called a bias node. The role and significance of the bias node will be explained later in this section, and for now, let's consider bias as a regular input node.
Let's do an analysis with the figure above by setting x2 = 0 and w0, w1 and w2 equal 0.5, 1 and 3.
So, here it's evident that the response of the perceptron is heavily prejudiced toward the values of x1, i.e, there exist values of x1< x2 for which the perceptron generates a positive signal.
Let's consider a task of character recognition. Identification of a character from its image is a complicated intelligent task. It's almost impossible to explicitly code a bot to identify different alphabets. Everytime we write an alphabet say "a" it's different from all previous times from the perspective of scale position, color and orientation. A more sophisticated and intelligent model would be one which itself infer the underlying significance of the character from the training data.
Let's say you are given a bunch of images of hand-written characters "a" and "b" along with their labels. A label "1" corresponds to an image of character "a" and "0" for "b".Now using this we need to train the perceptron network to classify these images into different sets, one set of character "a" and another of character "b". Basically, any digital image is a matrix of pixels values, which determines the color at a specific point on the screen. This matrix of pixel values could be converted into an array of pixels, and further this array could be used as an input for the network.
Now to train the model such that whenever an image of the character "a" is given it returns 1, and returns 0 if the image of character "b" is given. For a given single input vector and its output, there exist many solutions of weights but the values of weights have to be updated to a value which gives the desired output for all the examples in the training set. In doing so, the common underlying feature embedded in the examples is captured and higher values of weights is assigned to them. Noisy distinctive features which don't tend to appear in every example are weighted negligibly. So, after training, when a new image is fed to the model, it will extensively look for the heavily weighted features in the signal and judge its class.
Further, a methodology has to be devised to tune the values of weights for appropriate decision making. Since the output of a perceptron could be +1 or 0, the error function E of ith perceptron for mth training example could be +1,-1, or 0.
where Eim, tim and yim are error, target value (actual desired output), and the output value of ith perceptron for mth training example. If Eim=0, then weights associated with that perceptron are appropriate and don't need to be changed. But if Eim=1, this means output produced is 0 when +1 was desired, hence weights associated with that perceptron need an accent. Each weight is increased by a fraction of the corresponding input node and similarly, the weights are reduced if Eim=â??1. The equation below could do the required updates.
Here,? determines learning rate, for higher values of alpha, the model tends to learn faster but has lesser chances of procuring an optimum solution, whereas, for lower alpha, the model learns slowly but has better chances of procuring an optimum solution. Consequently, a moderate choice of learning rate is made ranging from 0.1 to 0.8. However, the best strategy to determine alpha is trial and error.
The above strategy to update the weights might fail if the value of all the input nodes is 0 because then the second term on the right-hand side of equation (1) will be zero. So, in order to avoid such complication biasing is introduced.
Biasing: an extra input node is acquainted whose value is Â±1 and this node is called a bias node. Bias node ensures that weights get updated when needed to be, even when all the input nodes of a vector are 0. Suppose input (0,0) has target value 0 and output given by model is 1 hence its required for weights to be updated but using (1) it could be easily seen that none of the weights will get updated if there is no biasing.
Perceptron neural networks can be used for the classification of a logical function. A logical function takes two input parameters In 1 and In 2. The input of the logical function is digital i.e. input values could be either 0 or 1. There are different types of logical function, and the following is a classification of Binary OR logical function.
In 1 and In 2 are components of input vectors and In 1 OR In2 are their corresponding output.
There are two different types of outputs of the binary OR function, 1 marked with the dot and 0 marked with a plus sign in the above figure.
Using the Perceptron model we will try to determine the boundary of classification of this two different types of output.
Step 1: Import libraries necessary for the project.
Step 2: Initialize weights to random values.
Step 3: Define input feature vectors and corresponding targets in arrays X and t, and set the value of bias node to -1.
Step 4: Train the model. Here, the sum is an array containing a weighted summation of each input vector and y is an array containing activation output of perceptron corresponding to each input. Weighted summation for each perceptron can be calculated using the dot method of numpy where dot does the matrix multiplication.
A linear classification boundary separating two different types of examples will be obtained.
Since all the operations in the model are linear, the extent of the model is limited to linear classification. For the extension of the model to exhibit non-linear classification, novel improvisations have been introduced. The method is known as the multi-layer perceptron model or deep learning neural network.
What is Deep Learning Neural Networks?
In contrast to the perceptron network, the activation function of the Deep learning neural networks is non-linear, enabling it to learn complex and nonlinear features of the system. In addition to input and output layers deep learning architecture has a stack of hidden layers between the input and output layer. Deep learning neural networks are capable of extracting deep features out of the data; hence the name Deep Learning.
There are several different types of neural networks.
1. Feed Forward neural network: It was the first and arguably most simple type of artificial neural network devised. In this network, the information moves in only one direction â?? forward. From the input nodes data goes through the hidden nodes (if any) and to the output nodes. There are no cycles or loops in the network.
2. Radial basis function networks: It is used to perform interpolation in multidimensional space. An RBF is a function which has built into it a distance criterion with respect to a center. RBF networks have two layers of processing. In first, the input is mapped onto each RBF in the hidden layer. The activation function chosen in RBF network is a Gaussian function contrary to Feedforward networks where activation function is sigmoidal.
3. Recurrent neural networks (RNNs): These are networks comprising of bi-directional data flow i.e. information in the network flows from later processing stages to earlier stages. RNNs can be used as general sequence processors. Hopfield network (like similar attractor-based networks) is of historic interest although it is not a general RNN as it is not designed to process sequences of patterns. Instead, it requires stationary inputs. It is an RNN in which all connections are symmetric, and it was invented by John Hopfield in 1982.
This section presents a basic yet powerful form of deep learning neural network - Feed Forward Neural network.
The key idea of the model is that each feature of an input vector is connected to all the neurons of the subsequent hidden layer and all the neurons of this layer are further connected to the next hidden layer and so on. The last hidden layer is connected to the output neurons; each connection has a weight associated with it. Output neurons generate an output signal depicting information about the corresponding input signal.
In the perceptron model, each single processing unit of a neuron does the weighted summation of signals arriving from the neurons of the previous layer and processes an output through Heaviside step function "H(z)". But here the point of demarcation from the perceptron model is that the activation function of a neuron is sigmoid "g(z)" instead of a Heaviside step function. The advantage of choosing a sigmoid over step function is that sigmoid is very close to stepping function. And, it's also differentiable, which turns out to be an essential criterion for parameter tuning in neural networks.
where yi is the output of ith neuron and wij is the weight connecting ith neuron to jth input node.
Another difference from the perceptron model is that here, multiple hidden layers are stacked between input and output layers and each of these layers acts as input for the subsequent layer. As the signal progresses through each layer, more detailed and fine structures are recovered, hence improvisation of hidden layers has enabled the penetration into deeply embedded features in data. This has made learning more comprehensive.
Further sigmoid activation adds non-linearity to the model, which enables it to learn non-linear discrepancies between different classes, making it a better and more complex brain for the machines.
Learning in neural networks progresses in a similar fashion as in the perceptron model. First, training examples are fed to the network and the input signal propagates through each layer, producing an output. This mechanism is known as "Feed Forward." Then, weights are tuned such that the output produced by networks matches the target values of the corresponding training example. This tuning is done by an algorithm called "Back Propagation."
Let's consider a network with n hidden layers and let Xim denote the ith component of the mth training example. In the context, this framework, Feed Forward and Back Propagation are illustrated below.
where YiL is the output of ith hidden neuron in Lth hidden layer and WijL are the weights connecting ith hidden neuron of Lth hidden layer to jth node of the previous layer.
where ymi is the output of ith output neuron for mth training example and since there are n hidden layers in the network, Ynj represents the output of jth neuron in the last hidden layer.
Back Propagation: The backward propagation of errors or backpropagation is a common method of training artificial neural networks and used in conjunction with gradient descent optimization. Optimization objective of backpropagation is the cost function "J".
Gradient Descent is an iterative procedure to optimize an objective. For the optimization problem above
where alpha determines the learning rate and functions as in perceptron model.
There are two aspects of incorporating gradient descent in backpropagation depending on the choice of optimization objective "J."
Here ymi is target value of ith output neuron for mth training example.
Since the cost function in BGD is the sum of squared error over all training examples the solution converges at local minima, whereas in SGD since weights are updated independently for each training example solution doesn't converge at local minima, instead it oscillates near the optimum regime. However, SGD is preferred over BGD because of its lower time complexity.
To tune the weights to produce the desired output, cost J has to be optimized.
Iterating Back Propagation step for several iterations converges the weights to the optimum solution.
Following is an implementation of non-linear multiclass classification of the Iris data set written in Python using the Keras library. It's a deterministic task to identify the class of iris flower from its physical dimensions.
Neural Network Architecture: One hidden layer consists of five neural nodes.
Step 1: Randomly segregate the data into two different parts, training set with 120 examples and testing set with 30 examples.
Step 2: Import required libraries.
Step 3: Load data from the training set.
Here, X is an array of input feature vectors and t is an array containing their corresponding target values. dtype= None changes the default data type of numpy array (i.e float) to contents of each column, individually.
Step 4: Since target values t are in string format, it has to be assigned numerical labels and this could be done by using scikit's LabelEncoder class.
transform method will assign a distinct numerical label to each distinct values in t.
Step 5: When modeling multi-class classification problems using neural networks, it is good practice to reshape the output attributes to binary Euclidean basis vectors and this could be easily done using to_categorical method from np_util class of keras library.
vec_t is an array of target vectors in binary Euclidean basis format.
Step 6: Define a model of the network using Sequential class. An object of layers package is added to the model and since our model is fully connected dense network, a Dense method will be added to the model.
A dense network consisting of a hidden layer with five nodes and an output layer with three nodes with sigmoid activation and uniform random weights initialization is defined above.
Step 7: Compile and train the model using compile and fit methods. Set loss (cost function) to mean squared error (mse) and optimizer to sgd and train the model for 500 epoch.
Training with an accuracy of 98% could be achieved.
Step 8: Predict test data using the predict method
A value of prediction basically quantifies certainty of an input belonging to a particular class. Choose the one with maximum certainty. Prediction with an accuracy of around 90% is achieved.
Step 9: The best architecture for prediction could be determined using trial and error.
Above implementation signifies the remarkable performance of Neural Networks. Although neural networks have been overlooked ever since its inception but the multilayer extension to the model and recent developments in computational technologies has made it one of the best learning algorithms. The neural network has outperformed every Machine learning algorithm in task image recognition with an accuracy level of above 95%. Inspired by collective underlying behavior and performance of different types of biological neurons many insightful architectures and variations in this model have been improvised.
Perceptron model is a neural network capable of linear classification.
Deep Learning neural networks are capable of learning nonlinear decision boundaries.
Typically activation function used in a feed-forward neural network is a sigmoid function.
The cost function (mean squared difference of desired and the predicted value) is optimized to determine appropriate weights.
A gradient-based optimization algorithm called back propagation is used to optimize the cost function.