CS Electrical And Electronics
@cselectricalandelectronics
All PostsDeep Learning, Machine Learning, & Artificial IntelligenceProgrammingWhat Is

What Is ANN Controller, Artificial Neural Network (ANN) In MATLAB

Hello guys, welcome back to my blog. In this article, I will discuss what is ANN controller, artificial neural network, ANN in MATLAB Simulink, human brain analogy with artificial neural network or ANN, a mathematical model of ANN, ANN implementation in MATLAB using the program, ANN implementation in MATLAB using GUI tool, ANN implementation in Simulink, etc.

If you have any doubts related to electrical, electronics, and computer science, then ask question. You can also catch me @ Instagram – Chetan Shidling. 

Also, read:

Artificial Neural Network Or ANN Controller

Applications Of Artificial Neural Network

The ANN is used in different fields, such as:

  • Medical sciences
  • Computer system
  • Engineering science (electrical, mechanical, civil, electronics, telecommunication, control system, chemical, etc)
  • Industrial process an control
  • Robotics
  • Aerospace, automotive and transportation
  • Military
  • Speech recognition, face recognition, and pattern recognition

And still, there are many domains where ANN or artificial neural networks can be implemented. Well, guys, if you are facing any problem while implementing ANN in MATLAB then this article is for you.

Topics -> “What Is ANN Controller”

Introduction To Artificial Neural Network

The work artificial in the neural network itself is points out that it is not the natural or original neural network. Now, the question may arise that what do we mean by the natural neural network? The original neural network means a human biological neural network.

In simple words, it means our human brain. It means that aim of the artificial neural network is to work like the human brain. Now, again questions may arise that what functions are performed by the human brain? and how the human brain performs those various functions?

Let us consider an example for better understanding.

Topics -> “What Is ANN Controller”

What Functions Are Performed By Human Brain

What Functions Are Performed By Human Brain

a. Just consider the example of a class. The teacher is delivering the lecture to a class of 50 students. It means that he is performing the following task simultaneously. Means he is doing all the tasks at the same time.

  1. He is speaking to deliver his lecture.
  2. Apart from speaking, he is writing on the board at the same time.
  3. Apart from writing and speaking, he is moving his fingers, hands, and legs to move across the board at the same time.
  4. Along with movement, speaking, and writing, he is also feeling the hotness or coldness depending on the weather conditions at the same time.
  5. Along with speaking, movement, writing, and feeling sensation, he is smelling too and may find it bad or good depending upon its fragrance at the same time.
  6. Apart from speaking, writing, movement, feeling sensation, and smelling, he/she is also watching the students as well as whole class room too at the same time.
  7. Furthermore, he/she is not only watching, but he is also feeling again from the facial expressions of the students that students are understanding his lecture or not?
  8. Again, apart from all these tasks, he is listening too at the same time.

Therefore, to conclude, the human brain is performing all the above multi-tasking at the same time. Therefore, the human brain system is a very powerful and complex system that can perform many operations simultaneously.

Now a question may arise as that how the human brain is performing all these tasks. The answer to this question is that our human brain has got, typically billions of nerve cells or neurons with trillions of interconnections between them.

Topics -> “What Is ANN Controller”

Due to these billions of neurons, and trillions of interconnections to transfer the information from one neural to other. Therefore, the human brain becomes a massively large parallel interconnection of a large number of neurons which achieves different tasks such as recognition tasks, decision tasks, etc.

In an amazingly small amount of time. It can recognize the face of any person, any student, any animal within a fraction of seconds. This inspired the researchers to think that is there anyway, whereby a computer can be made to mimic a large number of interconnections and the networking which exists between all the nerves cells.

Now the question may arise, how to make the computer enable to perform these tasks? To answer this question, I will repeat the same question for that example of the teacher.

How did the teacher know all the mathematical equations, theories, how did he become able to walk and talk in different languages? The ultimate answer is that because that teacher has gone through the processing of learning for years in fact from his childhood. That’s why he is now able to understand the mathematical equations, and has the ability to apply these equations, and can make or take decisions on various matters.

Topics -> “What Is ANN Controller”

Similarly, artificial neural networks can also be enabled to perform these tasks by going through the learning and training process. Therefore, an artificial neural network (ANN) is the piece of a computing system designed to simulate the way the human brain analyzes and processes information.

Before going to discuss the ANN training, I am going to ask another point that in real practice, the human brain is performing many tasks in parallel. However, in engineering applications, most of the time, we need only one task to perform at one time. Therefore, fortunately, it is not so difficult to apply ANN for different engineering applications.

b. Let me give you an example to clarify this concept. In the power system control, suppose we are performing the load frequency control of the power plant, we have to control the frequency subjected to the load variations.

load frequency control of the power plant

Therefore, if we are going to use the ANN for the load frequency control. Then, ANN requires only the input data in the form of the speed or frequency. The ANN has nothing to do with other power system parameters, protection, overcurrent, voltage, etc.

Topics -> “What Is ANN Controller”

Therefore, now to conclude, artificial neural network technology is not trying to produce biological machines but ANN is a very mimic (extremely small) part of the original brain to perform a specific task and limited task (one task at a time). Whereas, the human brain is continuously performing multi-directional and decisions based tasks. Now, I am going to discuss the human brain.

Human Brain Analogy With ANN

 artificial neural network technology

It may be noted that the human brain is composed of 86 billion nerve cells called neurons. The information is processed through neurons in the human brain. A neuron consists of 3 main components, i.e., the soma or cell body, dendrites, and the axon. The neuron receives information from the dendrites which acts as the input to the neuron.

These inputs create electric impulses, which quickly travel through the neural network. Based upon these inputs, all the information is gathered and the decision is taken within the cell body or soma. This decision is sent through an axon which acts as the output. Based upon this analogy, the biological neuron may be converted into an artificial neuron as below in the form of the table.

Artificial Neural Network
Biological Neural NetworkArtificial Neural Network
DendriteInput
AxonOutput
SomaNeuron (Summing point and decision function)
SynapseWeight

Look at the table, it may be noted that dendrites in the biological neuron may be represented as an input signal, whereas axon in the biological neuron may be represented as the output signal. Similarly, the soma of the biological neural network may be represented by the summing point and decision function.

Last the synapse in the biological neural network may be represented by the multiplying weight. It is because synapse indicates the intensity of the signal. If its intensity is 100% then its weight maybe 1, otherwise its weight may vary from 0 to 1 depending upon the intensity of the signal. Now, let see how these biological terms are represented in mathematical form in this figure.

Topics -> “What Is ANN Controller”

Simple Mathematical Model Of ANN

Simple Mathematical Model Of ANN

It may be noted that the inputs may consist of any real data or signal, or it may consist of many inputs. In the next step, the summation of these inputs is carried out. Based upon this, summation, the final decision will be carried out.

To take the decision we may use activation functions such as linear function, or any nonlinear function. In the end, the final decision will be the output signal. Now have a look at this figure, which shows the mathematical model of the artificial neuron in more real form.

Mathematically,

mathematical model of the artificial neuron

Suppose, we want the output of the linear combiner, then it will be the sum of the product of all the inputs with their respective synaptic weighs as below. Now, the final output will become,

  • xj: input signals
  • wkj: synaptic weights
  • uk: linear combiner output
  • theta*k: threshold
  • f(): activation function
  • yk: output signal

To make it simple so that it may be easy to understand, we use the following function with the conditions. Now, it will be easy to get the output. Suppose, the total sum uk is less than zero, then the output will be zero.

And if the total sum uk is greater than 0, then the output will be 1. Similarly, different linear and nonlinear functions such as logsig, tansig, sigmoid function may also be used. Now, based upon these neurons, ANN may have consist of

01. Single-layer perceptron feedforward neural:

Single-layer perceptron feedforward neural

The above figure is the network. The term perceptron is the simplest form of a neural network. It consists of a single neuron with adjustable synaptic weights or in other words, perceptron means neuron. In this network, we have one input layer of source nodes that projects onto an output layer of neurons. That’s why it is known as a single layer.

Furthermore, the neurons in this network always move in the forward direction means they are processed in the forward direction and don’t have feedback loops or connections. That’s why they are known as feed-forward networks. Now, suppose, when the single layer is applied to solve the problem. But, this single layer is not able to give an accurate output.

The next step to get an accurate result is to increase the number of layers. Such a network is known as a multilayer perceptron feedforward neural network.

02. Multi-layer perceptron feedforward neural network:

Multi-layer perceptron feedforward neural network

In this network, one or more hidden layers are used in order to get accurate results. Overall this network consists of an input layer of source neurons, at least one middle or hidden layer of computational neurons, and an output layer of computational neurons.

The input signals are propagated in a forward direction on layer by layer basis. The output signals of the second layer are used as input to the third layer, and so on for the rest of the network. The below figure shows a multilayer feed-forward network that has 10 source nodes, 4 hidden neurons, and 2 output neurons. Now, questions may arise as that how the learning of ANN is carried out?

The answer to this question is that there are many learning categories such as supervised learning, and unsupervised learning, and the most common learning technique used is known as error correction learning.

You can read about these topics from books or the internet. Now, I am going to discuss error-correction learning. In the error correction learning, the output of the ANN is compared with the desired output or target output value, and the difference between the two outputs known as the error is computed. Suppose, if the system output is y, and the desired system output is known to be d, the error signal can be defined as,

E = D – Y

In the most direct route, this error value can be used to directly adjust the weights of the artificial neural networks. Error correction learning algorithms attempt to minimize this error signal at each training iteration.

The most popular learning algorithm for use with error-correction learning is the backpropagation algorithm. The process is continued until the difference is zero or within the desired threshold. When the desired output is achieved it means the ANN model is successfully trained.

Topics -> “What Is ANN Controller”

This basic knowledge is required to implement ANN in MATLAB. Now, we will first implement ANN in MATLAB through a mathematical example. Later on, we will implement ANN for a particular power system example.

Methods Of ANN Implementation In MATLAB

In MATLAB, the artificial neural network can be implemented in one of the following ways.

01. ANN implementation through MATLAB program

02. ANN implementation by using Simulink

03. ANN implementation by using GUI tool

ANN Implementation Through MATLAB Program

In order to teach you the ANN implementation through the MATLAB program, I am going to consider a mathematical example. Let us take an example of a model having three inputs a, b, and c which generates an output y. Suppose, the model has the following mathematical equation.

y = 2a+3b+5c

Now, the output y can be obtained by putting the input values a, b, and c. At this stage, I want to highlight the advantage of artificial neural networks that ANN does not require the mathematical equation of its learning. In fact, ANN requires input and output data only.

Based upon this data, the ANN goes into the training process for its learning and understanding the relationship between the input and output data. Once, the training is successfully completed, the ANN can provide the accurate output for any input variable without knowing the mathematical equation. Therefore, at the first stage, we need the data for the ANN. It is the first primary requirement of the ANN implementation.

Now, I am going to discuss the ways by which the data can be obtained for ANN implementation.

01. Collect data from the industries or government organizations such as WAPDA, NTDC, & PEPCO, or any other national or international organization depending upon the type of model to be considered for the ANN.

Topics -> “What Is ANN Controller”

02. Collect data by doing experiments.

03. Data can be collected by doing the simulations in any software.

Now, let’s collect the data for this mathematical equation. Suppose, we need the 1000 output data with the following ranges of the inputs. It means that the minimum and maximum range of the input a, b, and c are taken from 0 to 1 to get the 1000 data samples, we are going to use the random function of Matlab which generates a different number of samples within the range. Let me teach you this random function first. For this purpose, just look at the Matlab syntax of the random function.

The random function has the following MATLAB syntax:

a = rand(x,y)

Here x shows the number of rows, and y shows the number of columns. Whereas rand by default generates the random values from 0 to 1. Now, suppose, if we want to produce 5 samples within the range of 0 and 1. Then the syntax will become as below,

a = rand(1,5)

In MATLAB

clear
a = rand(1,5);
disp(a)

Output:

0.8147    0.9058    0.1270    0.9134    0.6324

You can see, Matlab has generated 5 random numbers within the range of 0 and 1. Now, suppose, we want to increase the range from 0 to 5 and sample up to 10. Then following changes will be required as shown in the format.

a = 5*rand(1,10)

It may be noted that 5 is multiplied in order to increase its range from 0 to 5, whereas 10 is written to get the total number of samples. Let me show you this in Matlab again.

Topics -> “What Is ANN Controller”

>> a = 5*rand(1,10);
>> disp(a)

Output:

0.4877    1.3925    2.7344    4.7875    4.8244    0.7881    4.8530    4.7858    2.4269    4.0014

You can see, Matlab has generated 10 random numbers having a range within the range of 0 and 5. Now, suppose if we want to generate 10 random from 10 to 25 range. TO write such random numbers, Matlab has the following syntax.

a = A*rand(x,y)+B

Where,

  • A is the maximum range
  • B is the minimum range

Therefore, to get 10 random numbers from 10 to 25, the following changes will be required as to how in the format. Let me show you this in Matlab again.

>> a = 15*rand(1,10)+10;
>> disp(a)

Just type this code on the command window and press enter. You can see, Matlab has generated 10 random numbers within the range of 10 to 25.

Output:

12.1283   16.3264   23.7360   21.8831   24.3924   19.8361   10.5357   22.7369   24.0099   20.1810

Well, guys, I hope now you are clear on how different random numbers can be generated for different input ranges. Let us come back to our mathematical example. In which we need to get 1000 samples of the inputs for the range from 0 to 1 and its output. Therefore, for better results, we are going to write this code in the new m file.

Topics -> “What Is ANN Controller”

a = rand(1,1000);
b = rand(1,1000);
c = rand(1,1000);
y = 2*a + 3*b + 5*c;
disp(y)
random number between 1 to 1000

You can see, Matlab has generated 1000 samples for input a, b, c, as well as 1000 samples for the output. You can try and look at the whole data. You will see, that Matlab has created four variables namely a, b, c, and y.

Workspace in MATLAB

Just look at this side, it shows that each variable has 1000 samples. As we know that ANN requires only the input and output data. Therefore, we need to combine all the inputs into single input data. For this purpose, we can introduce an array and combine all these inputs. To get this, just add the following lines in the code.

a = rand(1,1000);
b = rand(1,1000);
c = rand(1,1000);
y = 2*a + 3*b + 5*c;
I = [a; b; c;];
T = y;
disp(y)

It may be noted that the variable I represent the input data and T represents the target data or output data. Furthermore, we have intentionally put the semicolon after each variable. This is necessary because we want to pull all the variables in the form of columns. Let me show you this by clicking on this run button.

random number in matlab

Now, just click on the “I” variable to see its values.

1000 samples in matlab

You can see, the input variable “I” consists of three rows having 1000 samples in each row. Well, guys, our first step of the ANN implementation is completed. Because we have collected all the input and output data for the ANN training. Now, open another new m file. Now, write here the input and output data variables as shown here. Now, this is the time to write the code to initialize the artificial neural network.

net=newff(minmax(I),[3,5,1],{'logsig','tansig','purelin'},'trainlm');
net = init(net);                   % Used to initialize the network (weight and biases)
net.trainParam.show =1;            % The result of error (mse) is shown at
each iteration (epoch)
net.trainParam.epochs = 1000;       % Maximum limit of the network training
iteration process (epoch)
net.trainParam.goal =1e-12;         % Stopping criterion based on error(mse) goal
net=train(net,I,T);                 % Start training the network

Well, guys, don’t be confused with this code. It is very easy and interesting point is that this code remains almost the same for any type of problem. Now, I am going to explain this code step by step. Just look at this line of code.

net=newff(minmax(I),[3,5,1],{'logsig','tansig','purelin'},'trainlm');

In this line, net shows the artificial neural network and newff means new feed-forward neural network. Minmax(I) is written to include the minimum and maximum value of the total input data in order to know the minimum and maximum input range for the training.

Now, 3, 5, and 1 represent basically the number of neurons in the input layer, hidden layer, and output layer. As we have three input variables namely a, b, c. Therefore, we have chosen 3 neurons for the input layer. Similarly, we have one output namely Y. Therefore, we have used one neuron in the output layer.

Now, a question arises, how many neurons we may choose for the hidden layer. The answer to this question is that there is no such rule for choosing the number of neurons. Therefore, we may start from 5 neurons to get the training.

If the training is succeeded then good. Otherwise, we may increase the number of neurons and train the neural network again and again until the training is successfully completed.

Let us move ahead. The term logsig, tansig, and puerlin are the activation functions for the input is hidden and output layer respectively. These activation functions are also used arbitrarily and we may use any activation function depending upon the need of the problem. However, usually all these three most common activation functions are used at the first stage of the training.

Mostly, ANN completes its training successfully with these activation functions. However, in case, the ANN fail to train correctly then we may change the activation functions to get the successful training of the ANN. It may be noted that purelin represents the pure linear activation function.

This function is commonly used in the output layer. ‘trainlm’ represents the training algorithm. MATLAB has many training algorithms already developed and stored in it. Let me share with you the list of various algorithms.

Types Of ANN Learning Algorithms In MATLAB

01.trainbBatch training with weight and bias learning rules
02trainbfgBFGS Quasi-Newton Backpropagation
03trainbrBayesian Regularization
04traincCyclical order incremental training w/learning functions
05traincgbPowel-beale Conjugate gradient Backpropagation
06traincgfFletcher-Powell Conjugate gradient Backpropagation
07traincgpPolak-Ribiere COnjugate gradient Backpropagation
08traingdGradient decent backpropagation
09traingdmGradient decent with momentum backpropagation
10 traingdaGradient decent with adaptive Ir Backpropagation
11traingdxGradient decent with momentum & adaptive Ir Backpropagation
12trainlmLevenberg-Marquardt Backpropagation
13trainossOne step secant Backpropagation
14trainrRandom order incremental training with learning functions
15trainrpResilient Backpropagation
16trainsSequential order incremental training with learning functions
17trainscgScaled conjugate gradient backpropagation

These all are the algorithms that can be used for ANN training. I have highlighted the most common algorithms that are used for the ANN training which provide good results. However, among all these training algorithms, levenberg marquardt backpropagation algorithm is the most widely used for ANN training.

It is because this algorithm provides fast results for most of the case. That’s why ANN always uses this algorithm by default for its training. You can see here leveberg marquardt training algorithm Matlab code is written as trainlm.

Topics -> “What Is ANN Controller”

net = init(net);                   % Used to initialize the network (weight and biases)

Now, this code line indicates that an artificial neural network is initialized by this input, output data, and these layers.

net.trainParam.show =1;            % The result of error (mse) is shown at

This code line is used to show the training error at each iteration.

Still, this article is pending. We will complete this article as soon as possible.

I hope this article What Is ANN Controller may help you all a lot. Thank you for readingWhat Is ANN Controller“.

Also, read:

Author Profile

CS Electrical And ElectronicsChetu
Interest's ~ Engineering | Entrepreneurship | Politics | History | Travelling | Content Writing | Technology | Cooking
Share Now

CS Electrical And Electronics

Interest's ~ Engineering | Entrepreneurship | Politics | History | Travelling | Content Writing | Technology | Cooking

Leave a Reply

Your email address will not be published. Required fields are marked *