Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
55 views

Simulation of Relay Operation On Detection of Faulty Readings in Smart Meters

Uploaded by

IP PILLAI
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

Simulation of Relay Operation On Detection of Faulty Readings in Smart Meters

Uploaded by

IP PILLAI
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 71

SIMULATION OF RELAY OPERATION ON

DETECTION OF FAULTY READINGS IN


SMART METERS

A PROJECT REPORT

​ Submitted by

CATHERINE R 311116105015

ILA PORTKODI PILLAI 311116105030

SHERIN DOROTHY B 311116105052

SHOBANA P 311116105053

in partial fulfillment for the award of the degree

of

BACHELOR OF ENGINEERING
IN

ELECTRICAL AND ELECTRONICS ENGINEERING

LOYOLA ICAM COLLEGE OF ENGINEERING AND TECHNOLOGY

CHENNAI

ANNA UNIVERSITY: CHENNAI 600 025


APRIL 2020

0
ANNA UNIVERSITY: CHENNAI 600 025
BONAFIDE CERTIFICATE

Certified​ ​that​ ​this​ ​project​ ​report on ​“SIMULATION OF RELAY OPERATION


ON DETECTION OF FAULTY READINGS IN SMART METERS”​ is the
bonafide work of ​“CATHERINE R, ILA PORTKODI PILLAI, SHERIN
DOROTHY B, SHOBANA P” ​who carried out the project work under my
supervision

SIGNATURE:
DR.S.PRATHIBA

HEAD OF THE DEPARTMENT

ELECTRICAL AND ELECTRONICS


ENGINEERING

LOYOLA-ICAM COLLEGE OF ENGINEERING


AND TECHNOLOGY

NUNGAMBAKKAM

CHENNAI-34

Submitted for the Anna University Examination


held on​ __________________________

Internal Examiner External Examiner

1
TABLE OF CONTENTS

CH.NO TITLE PAGE NO.

ACKNOWLEDGEMENT 04

ABSTRACT 05

LIST OF TABLES 06

LIST OF FIGURES 07

LIST OF SYMBOLS 08

LIST OF ABBREVIATIONS 09

1 INTRODUCTION 1

1.1 SMART METER 10

1.2 ARTIFICIAL INTELLIGENCE 11

1.2.1 ARTIFICIAL NEURAL NETWORKS 12

1.2.2 FEEDFORWARD NEURAL NETWORKS 15

1.2.3 RECURRENT NEURAL NETWORK 18

1.3 BACKPROPAGATION 18

1.4 MATLAB 20

1.4.1 APPS AVAILABLE ON MATLAB 20

1.5 MACHINE LEARNING 23

1.6 TYPES OF MACHINE LEARNING 26

1.7 TIME SERIES FORECASTING 27

1.8 SIMULATING THE DETECTION OF FAULT 28

AND RELAY OPERATION USING MATLAB

1
NON LINEAR AUTO REGRESSION WITH
1.9 EXOGENOUS INPUTS 29

1.10 LEVENBERG-MARQUARDT ALGORITHM 31

1.10.1 NEURAL NETWORKS 32

1.10.2 COMPUTING THE JACOBIAN 33

1.10.3 APPROXIMATING THE HESSIAN 34

1.10.4 SOLVING THE MARQUARDT EQUATION 34

1.10.5 GENERAL LEVENBERG MARQUARDT 35

ALGORITHM

1.11 BLOCK DIAGRAM FOR TRAINING USING 36

LEVENBERG MARQUARDT ALGORITHM

1.12 NEURAL NETWORK TIME SERIES TOOL 37

1.13 INPUT DATA SELECTION FOR TRAINING 39

THE NETWORK

1.14 NEURAL NETWORK TRAINING TOOL 44

1.15 VIEWING THE NEURAL NETWORK 45

1.16 MATLAB CODE FOR TRAINING A NAR 45

NETWORK

1.16.1 CHOOSE FEEDBACK FOR PRE/POST 47

PROCESSOR FUNCTIONS

1.16.2 THE MAPMINMAX FUNCTION FOR 47

NORMALISATION

1.16.3 PREPARE THE DATA FOR TRAINING 48

AND SIMULATION

2
1.16.4 SETUP DIVISON OF DATA FOR TRAINING,

VALIDATION AND SIMULATION 49

1.16.5 RECALCULATE TRAINING,VALIDATION 51

AND TEST PERFORMANCE

56
1.17 THE USE OF LM ALGORITHM OVER GD METHOD
58
1.18 EARLY PREDICTION NETWORK
59
1.19 GENERATING THE SIMULINK BLOCK FOR THE NET
61
1.20 THE NEURAL LIBRARY
64
1.21 BLOCK PARAMETERS
65
1.22 PREDICTED OUTPUT (DISPLAY BLOCK)
65
1.23 REMOVE ROWS BLOCK
67
1.24 OUTPUT PLOTS
68
1.25 RELAY STATE

2 LITERATURE REVIEW 69

3
ACKNOWLEDGEMENT
First and foremost, praises and thanks to the God, the Almighty,
for His showers of blessings throughout my project work to complete the
project successfully.
We express our sincere gratitude to our beloved Director
Rev.Dr.Maria Venish SJ, ​the Dean of Students ​Rev.Dr.Justin
Immanuel SJ, ​and the Dean of Engineering Education ​Mr Nicolas
Juhel for their continuous support and encouragement and also for
providing immense facilities in our Institution​.
We proudly render our heartfelt thanks to our Principal ​Dr.Antony
Micheal Raj ​for the constant encouragement and support given by him
for the progress and completion of our project.
Our immense thanks to the Head of the Department
Ms.Dr.Prathiba ​for her effective leadership, encouragement and
guidance in this project.
I would like to express my deep and sincere gratitude to our project
supervisor ​Ms.Dr.Prathiba for her valuable ideas and constant
motivation throughout the course of our project.. It was a great privilege
and honor to work and do our project under her guidance.
We wish to extend our sincere thanks to all Faculty members and
the Lab Instructors of the Department of Electrical and Electronics
Engineering for their valuable suggestions and their kind cooperation for
the successful completion of our project.
Finally, our thanks go to all the people who have supported us to
complete our project work directly or indirectly.

4
ABSTRACT

Smart meters being the need for the electric utility in this
era as adoption of advanced metering infrastructure (AMI)
becomes more widespread, its appeal to cyber attackers will
undoubtedly increase, and addressing security vulnerabilities
across layers and by different stakeholders must be taken into
account from the outset. Smartgrid is increasingly benefiting
from intelligence-driven capability supported by machine
learning.​ ​The correct implementation of security best practices
prevents, as far as possible, breaches of complex systems, and
allows AMI component manufacturers to develop skills in the
area of cybersecurity which help protect customers from
potential and unwanted cyber-attacks. This project aims​ ​to use
neural networks, in detection of faulty or unusual readings of a
smart meter, and simulate using Matlab, the relay operation on
detection of faulty readings in the smart meter​.

5
LIST OF TABLES :

S.NO BLOCKS PAGE NO


1 SMART METER DATASET 41
2 COMPONENTS USED 61

6
LIST OF FIGURES:

S.NO FIGURE NAME PAGE.NO


1 Artificial Neural Network 13
2 Single layer Feed-forward neural network 16
3 Multi-layer Feed-forward neural network 17
4 Self learning block 25
5 Types of Machine Learning 26
6 Flow diagram 28
7 NARK Network 30
8 Training Block diagram of LM algorithm 36
9 Import wizard 43
10 Neural Network 45
11 Performance plot 51
12 Time series response plot 52
13 Error autocorrelation plot 53
14 Cross Correlation plot 54
15 Simulation block 62
16 Red cross plot 66
17 Plot of relay state 67

7
LIST OF SYMBOLS:

1. ε -​ Error term

2. λ - ​ Levenberg's damping factor

3. δ​ - weight update vector

4. w - weight factor

5. v - Displacement factor

8
LIST OF ABBREVIATIONS:

1. AMI - Advanced metering infrastructure

2. AMR - Automatic meter reading

3. PLC - Power line carrier

4. AI - Artificial intelligence

5. ANN - Artificial neural networks

6. RNN - Recurrent Neural Network

7. LSTM​ - ​Long Short-term Memory Networks


8. NARX - Nonlinear Autoregressive Exogenous Model

9. LMA - Levenberg-marquardt Algorithm

10. GD - Gradient Descent

11. BP - Back Propagation

9
CHAPTER-1
INTRODUCTION
1.1 SMART METER:
A smart meter (also known as advanced meters) is an electronic
device that records consumption of electric energy and communicates
the information to the electricity supplier for monitoring and billing.
Smart meters typically record energy hourly or more frequently, and
report at least daily. Grids with smart meters or “smart grids” attempt to
predict demand and react to rapid changes in demand and supply to
deliver efficient, reliable, and sustainable electric power.Smart meters
are part of a smart grid but the meters themselves do not comprise the
entire smart grid solution, but rather a part of the physical backbone of
the system.Such an advanced metering infrastructure (AMI) differs from
automatic meter reading (AMR) in that it enables two-way
communication between the meter and the supplier. Communications
from the meter to the network may be wireless, or via fixed wired
connections such as power line carrier (PLC). Wireless communication
options in common use include cellular communications, Wi-Fi,
wireless ad hoc networks over Wi-Fi, wireless mesh networks, low
power long range wireless , ZigBee , and Wi-SUN.

Computer security, cybersecurity or information technology


security is the protection of computer systems and networks from the
theft of or damage to their hardware, software, or electronic data, as well
as from the disruption or misdirection of the services they provide.

10
1.2 ARTIFICIAL INTELLIGENCE:

Artificial intelligence (AI), also called machine intelligence, is


intelligence demonstrated by machines, in contrast to the natural
intelligence displayed by humans. It ​is often used to describe machines
that mimic "cognitive" functions that humans associate with the human
mind, such as "learning" and "problem solving".

The traditional problems of AI research include reasoning,


knowledge representation, planning, learning, natural language
processing, perception and the ability to move and manipulate objects.
General intelligence is among the field's long-term goals. Approaches
include statistical methods, computational intelligence, and traditional
symbolic AI. Many tools are used in AI, including versions of search
and mathematical optimization, artificial neural networks, and methods
based on statistics, probability and economics. The AI field draws upon
computer science, information engineering, mathematics, psychology,
linguistics, philosophy, and many other fields.

AI is relevant to any intellectual task. Modern artificial intelligence


techniques are pervasive and are too numerous to list here. Frequently,
when a technique reaches mainstream use, it is no longer considered
artificial intelligence; this phenomenon is described as the AI effec​t

High-profile examples of AI include autonomous vehicles medical


diagnosis,proving mathematical theorems,search engines online
assistants , image recognition in photographs, spam filtering, predicting
flight delays, prediction of judicial decisions, targeting online
advertisements and energy storage.

11
1.2.1 ARTIFICIAL NEURAL NETWORKS:

What is an Artificial Neural Network ?

It is a computational system inspired by the Structure Processing


Method Learning Ability of a biological brain

Characteristics of Artificial Neural Networks :

➔ A large number of weighted connections between the


elements
➔ Distributed representation of knowledge over the connections
Knowledge is acquired by network through a learning
process

Why Artificial Neural Networks ?

- Massive Parallelism

- Distributed representation

- Learning ability

- Generalization ability

- Fault tolerance

Elements of Artificial Neural Networks:

- Processing Units

- Topology

- Learning Algorithm

12
Artificial neural networks (ANN) or connectionist systems are
computing systems vaguely inspired by the biological neural networks
that constitute animal brains. Such systems "learn" to perform tasks by
considering examples, generally without being programmed with
task-specific rules. For example, in image recognition, they might learn
to identify images that contain cats by analyzing example images that
have been manually labeled as "cat" or "no cat" and using the results to
identify cats in other images. They do this without any prior knowledge
of cats, for example, that they have fur, tails, whiskers and cat-like faces.
Instead, they automatically generate identifying characteristics from the
examples that they process.

​ ​Figure 1​ . ​Artificial Neural Networks


An ANN is based on a collection of connected units or nodes called
artificial neurons, which loosely model the neurons in a biological brain.
Each connection, like the synapses in a biological brain, can transmit a
signal to other neurons. An artificial neuron that receives a signal then
processes it and can signal neurons connected to it.

13
In ANN implementations, the "signal" at a connection is a real
number, and the output of each neuron is computed by some non-linear
function of the sum of its inputs. The connections are called edges.
Neurons and edges typically have a weight that adjusts as learning
proceeds. The weight increases or decreases the strength of the signal at
a connection. Neurons may have a threshold such that a signal is sent
only if the aggregate signal crosses that threshold. Typically, neurons are
aggregated into layers. Different layers may perform different
transformations on their inputs. Signals travel from the first layer (the
input layer), to the last layer (the output layer), possibly after traversing
the layers multiple times.A feedforward neural network is an artificial
neural network wherein connections between the nodes do not form a
cycle. As such, it is different from its descendant: recurrent neural
networks. ​Artificial neural networks (ANNs) are statistical models
directly inspired by, and partially modeled on biological neural
networks. They are capable of modeling and processing nonlinear
relationships between inputs and outputs in parallel.Artificial Neural
networks (ANN) or neural networks are computational algorithms. It
intended to simulate the behavior of biological systems composed of
“neurons”. A neural network is a machine learning algorithm based on
the model of a human neuron.

Applications:
- Pattern Classification
- Clustering/Categorization
- Function approximation
- Prediction/Forecasting

14
- Optimization
- Content-addressable Memory
- Control
1.2.2 FEEDFORWARD NEURAL NETWORK:

A feedforward neural network is a biologically inspired


classification algorithm. It consists of a number of simple neuron-like
processing units, organized in nodes.These connections are not all equal,
each connection may have a different strength or weight. The weights on
these connections encode the knowledge of a network. Often the units in
a neural network are also called nodes.

Data enters at the inputs and passes through the network, layer by
layer, until it arrives at the outputs. During normal operation, that is
when it acts as a classifier, there is no feedback between layers. This is
why they are called feedforward neural networks

Feedforward neural network was the first and simplest type of


artificial neural network devised.
In this network, the information moves
in only one direction, forward, from the
input nodes, through the hidden nodes
(if any) and to the output nodes.​The
simplest kind of neural network is a
single-layer perceptron network, which
consists of a single layer of output
nodes; the inputs are fed directly to the
outputs via a series of weights. The sum of the products of the weights
and the inputs is calculated in each node, and if the value is above some

15
threshold (typically 0) the neuron fires and takes the activated value
(typically 1); otherwise it takes the deactivated value (typically -1).
Neurons with this kind of activation function are also called artificial
neurons or linear threshold units.There are two main categories of
network architectures depending on the type of the connections between
the neurons, “feed-forward neural networks” and “recurrent neural
networks”. If there is no “feedback” from the outputs of the neurons
towards the inputs throughout the network, then the network is referred
to as “​feed-forward neural network​”. Otherwise, if there exists such
feedback,connection from the outputs towards the inputs then the
network is called a “​recurrent neural network”​ .Usually, neural networks
are arranged in the form of “​layers​”. Feed-forward neural networks fall
into two categories depending on the number of the layers, either
1. Single layer feed-forward neural network
2. Multi-layer feed-forward neural network

​Figure 2​. A single layer feed-forward neural network

16
A single-layer neural network represents the most simple form of
neural network, in which there is only one layer of input nodes that
send weighted inputs to a subsequent layer of receiving nodes, or
in some cases, one receiving node

​ Figure 3. ​A multi-layer feed-forward neural network

A multilayer feedforward neural network is an interconnection of


perceptrons in which data and calculations flow in a single direction,
from the input data to the outputs. The number of layers in a neural
network is the number of layers of perceptrons.

17
1.2.3 RECURRENT NEURAL NETWORK:
A ​recurrent neural network (​RNN​) is a class of artificial neural
networks where connections between nodes form a directed graph along
a temporal sequence. This allows it to exhibit temporal dynamic
behavior. Derived from feedforward neural networks, RNNs can use
their internal state (memory) to process variable length sequences of
inputs. This makes them applicable to tasks such as unsegmented,
connected handwriting recognition​ ​or speech recognition.
The term "recurrent neural network" is used indiscriminately to
refer to two broad classes of networks with a similar general structure,
where one is ​finite impulse and the other is ​infinite impulse​. Both
classes of networks exhibit temporal dynamic behavior. A finite impulse
recurrent network is a directed acyclic graph that can be unrolled and
replaced with a strictly feedforward neural network, while an infinite
impulse recurrent network is a directed cyclic graph that can not be
unrolled.
Both finite impulse and infinite impulse recurrent networks can
have additional stored states, and the storage can be under direct control
by the neural network. The storage can also be replaced by another
network or graph, if that incorporates time delays or has feedback loops.
Such controlled states are referred to as gated state or gated memory,
and are part of long short-term memory networks (LSTMs) and gated
recurrent units. This is also called ​Feedback Neural Network.

18
1.3 .3 BACKPROPAGATION:
In machine learning, specifically deep learning, ​backpropagation
(​backprop​, ​BP​) is a widely used algorithm in training feedforward
neural networks for supervised learning. Generalizations of
backpropagation exist for other artificial neural networks (ANNs), and
for functions generally – a class of algorithms is referred to generically
as "backpropagation".Backpropagation is an algorithm used to calculate
derivatives quickly. Artificial neural networks use backpropagation as a
learning algorithm to compute a gradient descent with respect to
weights.The algorithm gets its name because the weights are updated
backwards, from output towards input.
Backpropagation is a short form for "backward propagation of
errors." It is a standard method of training artificial neural networks.
This method helps to calculate the gradient of a loss function with
respect to all the weights in the network. In deep learning,
backpropagation computes the gradient of the loss func​tion with respect
to the weights of the network for a single input–output example, and
does so efficiently, unlike a naive direct computation of the gradient
with respect to each weight individually. This efficiency makes it
possible to use gradient methods for training multilayer networks,
updating weights to minimize loss; gradient descent, or variants such as
stochastic gradient descent, are commonly used. The backpropagation
algorithm works by computing the gradient of the loss function with
respect to each weight by the chain rule, computing the gradient one
layer at a time, iterating backward from the last layer to avoid redundant
calculations of intermediate terms in the chain rule; this is an example of
dynamic programming.

19
1.4 1.4 MATLAB:
MATLAB (​matrix laboratory)​ is a multi-paradigm numerical
computing environment and proprietary programming language
developed by MathWorks. MATLAB allows matrix manipulations,
plotting of functions and data, implementation of algorithms, creation of
user interfaces, and interfacing with programs written in other
languages.
Although MATLAB is intended primarily for numerical
computing, an optional toolbox uses the MuPAD symbolic engine
allowing access to symbolic computing abilities. An additional package,
Simulink, adds graphical multi-domain simulation and model-based
design for dynamic and embedded systems.
MATLAB users come from various backgrounds of engineering,
science, and economics.

1.4.11.4.1 APPS AVAILABLE IN MATLAB:

MATH,STATISTICS,AND MACHINE LEARNING


OPTIMIZATION

20
AUTOMOTIVE CONTROL SYSTEM
DESIGN AND ANALYSIS

SIGNAL PROCESSING IMAGE PROCESSING


AND AND
COMMUNICATIONS COMPUTER VISION

TEST AND COMPUTATIONAL


MEASUREMENT FINANCE

21
COMPUTATIONAL CODE GENERATION
BIOLOGY

CODE VERIFICATION APPLICATION


DEPLOYMENT

DATABASE CONNECTIVITY SIMULATION


GRAPHICS
AND REPORTING

22
1.5 MACHINE LEARNING:
Machine learning is closely related to computational statistics,
which focuses on making predictions using computers. The study of
mathematical optimization delivers methods, theory and application
domains to the field of machine learning. In its application across
business problems, machine learning is also referred to as predictive
analytics.
Machine learning is the scientific study of algorithms and
statistical models that computer systems use to perform a specific task
without using explicit instructions, relying on patterns and inference
instead. It is seen as a subset of artificial intelligence. Machine
learning algorithms build a mathematical model based on sample data,
known as "training data", in order to make predictions or decisions
without being explicitly programmed to perform the task. Machine
learning algorithms are used in a wide variety of applications, such as
email filtering and computer vision, where it is difficult or infeasible to
develop a conventional algorithm for effectively performing the task.
Types of learning algorithms
1.Supervised learning
2.Unsupervised learning
3.Semi-supervised learning
4.Reinforcement learning
5.Self learning
1.Supervised learning:

23
Supervised learning algorithms build a mathematical model of a
set of data that contains both the inputs and the desired outputs. The data
is known as training data, and consists of a set of training examples.
Each training example has one or more inputs and the desired output,
also known as a supervisory signal.

2.Unsupervised learning:

Unsupervised learning algorithms take a set of data that contains


only inputs, and find structure in the data, like grouping or clustering of
data points. The algorithms, therefore, learn from test data that has not
been labeled, classified or categorized. Instead of responding to
feedback, unsupervised learning algorithms identify commonalities in
the data and react based on the presence or absence of such
commonalities in each new piece of data.

3.Semi-supervised learning:

Semi-supervised learning falls between unsupervised learning and


supervised learning. Many machine-learning researchers have found that
unlabeled data, when used in conjunction with a small amount of labeled
data, can produce a considerable improvement in learning accuracy.

4.Reinforcement learning:
Reinforcement learning is an area of machine learning concerned
with how software agents ought to take actions in an environment so as
to maximize some notion of cumulative reward. Reinforcement learning
algorithms do not assume knowledge of an exact mathematical model of
the MDP, and are used when exact models are infeasible. Reinforcement

24
learning algorithms are used in autonomous vehicles or in learning to
play a game against a human opponent.

5.Self learning:

Self-learning is a machine learning paradigm along with a neural


network capable of self-learning named ​Crossbar Adaptive Array
(CAA).​Self learning ​is a learning with no external rewards and no
external teacher advice. The CAA self-learning algorithm computes both
decisions about actions and emotions about consequence situations. The
system is driven by the interaction between cognition and emotion.

25
Figure 4 . ​Self learning block

1.6 TYPES OF MACHINE LEARNING:

26
Figure 5. ​Types of Machine Learning

1.7 TIME SERIES FORECASTING


A ​time series is a series of data points indexed (or listed or
graphed) in time order. Most commonly, a time series is a sequence
taken at successive equally spaced points in time. Thus it is a sequence
of discrete-time data. Examples of time series are heights of ocean tides,
counts of sunspots, and the daily closing value of the Dow Jones
Industrial Average.
Time series are very frequently plotted via line charts. Time series
are used in statistics, signal processing, pattern recognition,
econometrics, mathematical finance, weather forecasting, earthquake
prediction, electroencephalography, control engineering, astronomy,
communications engineering, and largely in any domain of applied
science and engineering which involves temporal measurements.
Time series analysis comprises methods for analyzing time series
data in order to extract meaningful statistics and other characteristics of
the data. ​Time series forecasting is the use of a model to predict future
values based on previously observed values. While regression analysis is
often employed in such a way as to test theories that the current values
of one or more independent time series affect the current value of
another time series, this type of analysis of time series is not called "time
series analysis", which focuses on comparing values of a single time
series or multiple dependent time series at different points in time.
Interrupted time series analysis is the analysis of interventions on a
single time series.

27
1.8 SIMULATING THE DETECTION OF FAULT AND RELAY
OPERATION USING MATLAB
The following are the tools used for realisation of fault type
identification or in general anomaly detection in a smart power grid.
PROCESS FLOW

28
Figure 6 .​ Flow Diagram
1.9 NON LINEAR AUTO REGRESSION WITH EXOGENOUS
INPUTS:
I​ n time series modeling, a nonlinear autoregressive exogenous
model (NARX) is a nonlinear autoregressive model which has
exogenous inputs. This means that the model relates the current value of
a time series to both:
● past values of the same series; and
● current and past values of the driving (exogenous) series — that
is, of the externally determined series that influences the series
of interest.
In addition, the model contains:
● an "error" term
which relates to the fact that knowledge of other terms will not enable
the current value of the time series to be predicted exactly.
Such a model can be stated algebraically as
y_{t}=F(y_{t-1},y_{t-2},y_{t-3},\ldots,u_{t},u_{t-1},u_{t-2},u_{t-3},\l
dots )+\varepsilon _{t}}
Here ​y is the variable of interest, and ​u is the externally determined
variable. In this scheme, information about ​u helps predict ​y​, as do
previous values of ​y itself. Here ​ε is the error term (sometimes called
noise). For example, ​y may be air temperature at noon, and ​u may be the
day of the year (day-number within year).
The function ​F is some nonlinear function, such as a polynomial. To test
for non-linearity in a time series, the BDS test

29
(Brock-Dechert-Scheinkman test) developed for econometrics can be
used.
NARX Network (narxnet, closeloop) in matlab
All the specific dynamic networks discussed so far have either been
focused networks, with the dynamics only at the input layer, or
feedforward networks. The nonlinear autoregressive network with
exogenous inputs (NARX) is a recurrent dynamic network, with
feedback connections enclosing several layers of the network. The
NARX model is based on the linear ARX model, which is commonly
used in time-series modeling. The next value of the dependent output
signal y(t) is regressed on previous values of the output signal and
previous values of an independent (exogenous) input signal.

​ - Figure 7. ​NARX Network


You can implement the NARX model by using a feedforward neural
network to approximate the function f. A diagram of the resulting
network is shown below, where a two-layer feedforward network is used

30
for the approximation. This implementation also allows for a vector
ARX model, where the input and output can be multidimensional.
1.10 LEVENBERG-MARQUARDT ALGORITHM:
In mathematics and computing, the ​Levenberg–Marquardt
algorithm (​LMA​), also known as the ​Damped least-squares (​DLS​)
method, is used to solve non-linear least squares problems. These
minimization problems arise especially in least squares curve fitting.
The LMA is used in many software applications for solving
generic curve-fitting problems. However, as with many fitting
algorithms, the LMA finds only a local minimum, which is not
necessarily the global minimum. The LMA interpolates between the
Gauss–Newton algorithm (GNA) and the method of gradient descent.
The LMA is more robust than the GNA, which means that in many cases
it finds a solution even if it starts very far off the final minimum. For
well-behaved functions and reasonable starting parameters, the LMA
tends to be a bit slower than the GNA. LMA can also be viewed as
Gauss–Newton using a trust region approach.
The Levenberg-Marquardt algorithm is a very simple, but robust,
method for approximating a function. Basically, it consists in solving the
equation:
(Jt​ ​J + λI)δ = Jt​ E

Where ​J is the Jacobian matrix for the system, ​λ is the Levenberg's


damping factor, ​δ is the weight update vector that we want to find and ​E
is the error vector containing the output errors for each input vector used
on training the network. The ​δ tell us by how much we should change

31
our network weights to achieve a better solution. The ​Jt​​ J matrix can also
be known as the approximated Hessian.

The ​λ damping factor is adjusted at each iteration, and guides the


optimization process. If reduction of ​E is rapid, a smaller value can be
used, bringing the algorithm closer to the Gauss–Newton algorithm,
whereas if an iteration gives insufficient reduction in the residual, ​λ can
be increased, giving a step closer to the gradient descent direction.

1.10.1 NEURAL NETWORKS:

Neural networks are a relatively new artificial intelligence


technique. In most cases an ANN is an adaptive system that changes its
structure based on external or internal information that flows through the
network during the learning phase. The learning procedure tries is to
find a set of connections ​w that gives a mapping that fits the training set
well.Furthermore, neural networks can be viewed as highly nonlinear
functions with the basic the form:

F(x,w) = y

Where ​x is the input vector presented to the network, ​w ​are ​the weights
of the network, and ​y is the corresponding output vector approximated
or predicted by the network. The weight vector ​w is commonly ordered
first by layer, then by neurons, and finally by the weights of each neuron
plus its bias.This view of network as an parameterized function will be

32
the basis for applying standard function optimization methods to solve
the problem of neural network training.

1.10.2 Computing the Jacobian

The Jacobian is a matrix of all first-order partial derivatives of a


vector-valued function. In the neural network case, it is a ​N​-by-​W
matrix, where ​N is the number of entries in our training set and ​W is the
total number of parameters of our network. It can be created by taking
the partial derivatives of each output in respect to each weight, and has
the form:

Where ​F(x​i​, w) is the network function evaluated for the i​-th input vector
of the training set using the weight vector ​w and w​j is the ​j-​ th element of
the weight vector ​w​ of the network.

In traditional Levenberg-Marquardt implementations, the Jacobian is


approximated by using finite differences. However, for neural networks,
it can be computed very efficiently by using the chain rule of calculus
and the first derivatives of the activation functions.

33
Approximating the Hessian

For the least-squares problem, the Hessian generally doesn't need to be


calculated. As stated earlier, it can be approximated by using the
Jacobian matrix with the formula:

H ≈ J​t​J

Which is a very good approximation of the Hessian if the residual errors


at the solution are "small". If the residuals are not sufficiently small at
the solution, this approach may result in slow convergence. The Hessian
can also be used to apply regularization to the learning process.

1.10.3 Solving the Levenberg-Marquardt equationL:

Levenberg's main contribution to the method was the introduction of the


damping factor ​λ​. This value is summed to every member of the
approximate Hessian diagonal before the system is solved for the
gradient. Typically, ​λ​ would start as a small value such as 0.1.

Then, the Levenberg-Marquardt equation is solved, commonly by using


a LU decomposition. However, the system can only be solved if the

approximated Hessian has not become singular. If this is the case, the
equation can still be solved by using a SVD decomposition.

34
After the equation is solved, the weights ​w are updated using ​δ and
network errors for each entry in the training set are recalculated. If the
new sum of squared errors has decreased, ​λ is decreased and the iteration
ends. If it has not, then the new weights are discarded and the method is
repeated with a higher value for ​λ​.

This adjustment for ​λ is done by using an adjustment factor ​v​, usually


defined as 10. If ​λ needs to increase, it is multiplied by ​v​. If it needs to
decrease, then it is divided by ​v​. The process is repeated until the error
decreases. When this happens, the current iteration ends.

1.10.4 General Levenberg-Marquardt Algorithm

As stated earlier, the Levenberg-Marquardt consists basically in


solving
(J​t​J + λI)δ = J​t​E ​ ​ ​ (1)
with different ​λ​ values until the sum of squared error decreases.
Variations of the algorithm may include different values for ​v​, one for
decreasing ​λ and other for increasing it. Others may solve ​(H +
λdiag(H))δ = g instead of (​ H + λI)δ = g (​ 1),​ while others may select the
initial ​λ according to the size of the elements on H, by setting ​λ0​ = t
max(diag(H))​, where ​t ​is a value chosen by the user. I've chosen the
identity matrix equation because, apparently, it is the same method
implemented internally by the Neural Network Toolbox in MATLAB.

35
1.11 BLOCK DIAGRAM FOR TRAINING USING LEVENBERG
MARQUARDT ALGORITHM:

Figure 8.​Training block diagram of LM algorithm

36
1.12 NEURAL NETWORK TIME SERIES TOOL:

Syntax
ntstool
ntstool('close')

37
Description
ntstool opens the neural network time series tool and leads you through
solving a fitting problem using a two-layer feed-forward network.
ntstool('close')c​ loses the tool.
ntstool can be used to solve three different kinds of time series problems.

● In the first type of time series problem, you would like to predict
future values of a time series ​y(​ ​t​) from past values of that time
series and past values of a second time series ​x(​ ​t)​ . This form of
prediction is called nonlinear autoregressive with exogenous
(external) input, or NARX, and can be written as follows:
y(​ ​t​) = ​f​(​y(​ ​t​ – 1), ..., ​y(​ ​t​ – ​d)​ , ​x​(​t ​– 1), ..., (​t​ – ​d)​ )
This model could be used to predict future values of a stock or
bond, based on such economic variables as unemployment rates,
GDP, etc. It could also be used for system identification, in which
models are developed to represent dynamic systems, such as
chemical processes, manufacturing systems, robotics, aerospace
vehicles, etc.
● In the second type of time series problem, there is only one series
involved. The future values of a time series ​y​(​t​) are predicted only
from past values of that series. This form of prediction is called
nonlinear autoregressive, or NAR, and can be written as follows:
y(​ ​t​) = ​f​(​y(​ ​t​ – 1), ..., ​y(​ ​t​ – ​d)​ )
This model could also be used to predict financial instruments, but
without the use of a companion series.
● The third time series problem is similar to the first type, in that two
series are involved, an input series ​x(​ ​t​) and an output/target series
y(​ ​t​). Here you want to predict values of ​y(​ ​t)​ from previous values

38
of ​x(​ ​t​), but without knowledge of previous values of ​y​(​t​). This
input/output model can be written as follows:
y(​ ​t​) = ​f​(​x(​ ​t​ – 1), ..., ​x(​ ​t​ – ​d)​ )
The NARX model will provide better predictions than this
input-output model, because it uses the additional information
contained in the previous values of ​y(​ ​t​). However, there may be
some applications in which the previous values of ​y(​ ​t)​ would not
be available. Those are the only cases where you would want to
use the input-output model instead of the NARX model.

1.13 INPUT DATA SELECTION FOR TRAINING THE


NETWORK:
The dataset consists of electricity consumption data (​December 2016 to
June 2018​) from a ​high-rise residential building inside the IIT
Bombay campus. The building consists of 60 3BHK(3 Bedrooms, I Hall
and a Kitchen) apartments, each instrumented with a smart-meter,
logging data at a ​sampling period of 5s​. The data shared in the link
below is ​downsampled at 1-hour granularity​. All the timestamps
mentioned in the dataset are of Indian Standard Time(GMT+5.30), and
India doesn’t follow daylight saving time. For privacy reasons,
apartments are kept anonymous. The folder consists of ​39 CSV files
each representing an apartment. Apartments having significant data loss
are removed from the list. The headers in the CSV files are as follows:

1)TS – Unix Timestamp (epochs)


2)V1 – Voltage of phase 1 (V)
3)V2 – Voltage of phase 2 (V)

39
4)V3 – Voltage of phase 3 (V)
5)W1 – Electricity consumption of phase 1 (Wh)
6)W2 – Electricity consumption of phase 2 (Wh)
7)W3 – Electricity consumption of phase 3 (Wh)
8)Virtual Apartment- Virtual Apartment ID
9)Date – Date in YYYY-MM-DD
10)Time – Time in HH:MM:SS
11)Power- Sum of W1 + W2 + W3 (Wh)

40
The following BibTex can be used to cite the dataset
@inproceedings{mammen2018want,
title={Want to Reduce Energy Consumption, Whom should we call?},
author={Mammen, Priyanka Mary and Kumar, Hareesh and
Ramamritham, Krithi and Rashid, Haroon},
booktitle={Proceedings of the Ninth International Conference on Future
Energy Systems},
pages={12–20},
year={2018},
organization={ACM}
}

V1 (V) W1 (W) Date Time Power (W)


(Hours)

230.4811 120.8918 01/30/2017 12:30:00 535.9928

234.9078 239.655 01/30/2017 13:30:00 1077.778

238.0418 335.3541 01/30/2017 14:30:00 1630.481

238.4602 211.3115 01/30/2017 15:30:00 724.6753

240.738 97.20476 01/30/2017 16:30:00 825.152

234.9638 134.7338 01/30/2017 17:30:00 542.6346

235.9224 156.6678 01/30/2017 18:30:00 472.5153

237.6545 126.4852 01/30/2017 19:30:00 298.4639

239.4076 127.923 01/30/2017 20:30:00 298.11


Table 2​. Smart meter data set

41
42
The data is imported to the workspace and saved.

Figure 9​.Import wizard

Targets are selected as ‘data’ with the time steps along a matrix
column and samples for each timestep along matrix row

43
1.14 NEURAL NETWORK TRAINING TOOL:
Syntax
nntraintool
nntraintool('close')

Description
nntraintool opens the training window GUI.
This is launched automatically when TRAIN is called.

44
1.15 VIEWING THE NEURAL NETWORK
● The NAR neural network considered here for training contains 2
layers with 10 hidden layers and 8 sublayers in the output layer.
● The samples are row vectors each of size 8 X 1.
● The input layer has a delay of 1.
SYNTAX
view(net);

Figure 10. ​Neural Network


1.16 MATLAB CODE FOR CREATING AND TRAINING
A NAR NETWORK

USING THE LEVENBERG MARQUARDT & GRADIENT DESCENT


TRAINING ALGORITHMS
​ OTE: V
[N ​ arious plots are generated, the first of every type corresponding to that
generated after gradient descent method and the second to levenberg marquardt
method of training the net.​]

45
Solve an Autoregression Time-Series Problem with a NAR
Neural Network

% This script assumes this variable is defined:


% data - feedback time series.
targetSeries = tonndata(data,false,false);

Create a Nonlinear Autoregressive Network


feedbackDelays = 1:1;
hiddenLayerSize = 10;
net = narnet(feedbackDelays,hiddenLayerSize);

46
1.16.1 CHOOSE FEEDBACK PRE/POST-PROCESSING
FUNCTIONS:
Settings for feedback input are automatically applied
to feedback output

net.inputs{1}.processFcns
={'removeconstantrows','mapminmax'};

1.16.2 THE​ ​mapminmax​ ​FUNCTION FOR NORMALISATION :


● The mapminmax maps matrix row minimum and maximum values
to [-1 1].
● It processes input and target data by mapping it from its original
range to the range [-1 1].

[Y,settings] = mapminmax(X) takes matrix or cell array


neural data,returns it transformed with the settings used to perform
the transform.

Here random data with non-standard ranges in each row is transformed.


x1 = [rand(1,20)*5-1; rand(1,20)*20-10;
rand(1,20)-1];
[y1,settings] = mapminmax(x1)

mapminmax.apply(X,settings) transforms X consistent with


settings returned by a previous transformation.

47
x2 = [rand(1,20)*5-1; rand(1,20)*20-10;
rand(1,20)-1];
y2 = mapminmax.apply(x2,settings)

mapminmax.reverse(Y,settings) reverse transforms Y


consistent with settings returned by a previous transformation.
x1_again = mapminmax.reverse(y1,settings)

1.16.3 Prepare the Data for Training and Simulation:


● The function PREPARETS prepares timeseries data for a particular
network,shifting time by the minimum amount to fill input states
and layer states.
● Using PREPARETS allows you to keep your original time series
data unchanged, while easily customizing it for networks with
differing numbers of delays, with open loop or closed loop
feedback modes.
[inputs,inputStates,layerStates,targets]=preparets(net
,{},{},targetSeries);
1.16.4 Setup Division of Data for Training, Validation,
Testing
net.divideFcn = 'dividerand'; % Divide data randomly
net.divideMode = 'time'; % Divide up every value
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;

48
Choose a Training Function
net.trainFcn = 'trainlm'; % ​Levenberg-Marquardt
net.trainFcn = 'traingdx'; %​gradient descent method
Choose a Performance Function
net.performFcn = 'mse'; % Mean squared error
Choose Plot Functions
net.plotFcns={'plotperform','plottrainstate','plotresp
onse','ploterrcorr', 'plotinerrcorr'};
Train the Network
[net,tr]=train(net,inputs,targets,inputStates,layerSta
tes);

49
Test the Network
outputs = net(inputs,inputStates,layerStates);
errors = gsubtract(targets,outputs);

1.16.5 Recalculate Training, Validation and Test


Performance
trainTargets = gmultiply(targets,tr.trainMask);
valTargets = gmultiply(targets,tr.valMask);
testTargets = gmultiply(targets,tr.testMask);
trainPerformance = perform(net,trainTargets,outputs)
valPerformance = perform(net,valTargets,outputs)
testPerformance = perform(net,testTargets,outputs)
performance = perform(net,targets,outputs)

50
​Figure 11. ​Performance plot

51
Plots ​figure, plotperform(tr)

​Figure 12.​Time series response

52
figure, plottrainstate(tr)
figure, plotresponse(targets,outputs)
figure, ploterrcorr(errors)

Figure 13​ .Error autocorrelation

53
​plotinerrcorr(inputs,errors)

​Figure 14. ​Cross correlation plots

54
1.17 THE USE OF LM ALGORITHM OVER GD
METHOD:
At each iteration, the Levenberg–Marquardt Algorithm chooses
either the gradient descent or GN and updates the solution.

The iterative update is ​dependent on the value of an


algorithmic parameter, λ​— a non-negative damping factor
which smooths out the graph. The update is ​Gauss-Newton if λ
is small (i.e. close to the optimal value) and a ​gradient descent
if λ is large. The Gauss-Newton is more accurate and faster than
the gradient descent when close to the minimum error.
Therefore, the algorithm will migrate towards the GN algorithm
as soon as possible.

● As there are two possible options for the algorithm’s


direction at each iteration, the LM is more ​robust ​than the
Gauss-Newton method
● It’s ​faster to converge​ than either the GN or gradient
descent on its own.
● It can ​handle models with multiple free parameters​—
which aren’t precisely known.
● If your ​initial guess is far​ from the mark, the algorithm can
still find an optimal solution.

55
Disadvantages:

● For flat functions (i.e. smooth functions with derivatives


that vanish at a certain point), the algorithm can get “…lost
in parameter space”
● In some cases, the LM can be very slow to converge. This
is particularly true if the model has more than ten
parameters which requires the algorithm to inch slowly
along a narrowly defined crawl space.

Closed Loop Network to do multi-step prediction :


The function CLOSELOOP replaces the feedback input with a direct
connection from the output layer.
netc = closeloop(net);
[xc,xic,aic,tc] = preparets(netc,{},{},targetSeries);
yc = netc(xc,xic,aic);
perfc = perform(net,tc,yc);
view(netc)

56
1.18 Early Prediction Network :
For some applications it helps to get the prediction a timestep early.The
original network returns predicted y(t+1) at the same time it is given
y(t+1).
For some applications such as decision making, it would help to have
predicted y(t+1) once y(t) is available, but before the actual y(t+1)
occurs.
The network can be made to return its output a timestep early by
removing one delay so that its minimal tap delay is now 0 instead of 1.
The new network returns the same outputs as the original network, but
outputs are​ shifted left one timestep​.

nets = removedelay(net);
view(nets)
[xs,xis,ais,ts] = preparets(nets,{},{},targetSeries);
ys = nets(xs,xis,ais);
closedLoopPerformance = perform(net,tc,yc)

57
1.19 GENERATING THE SIMULINK BLOCK FOR THE
NETWORK
gensim
Generate a Simulink block diagram of a neural network.
gensim(net,'name','nntsnet');

[SYSNAME,NETNAME] = gensim(NET) takes a neural network


NET, generates a Simulink system containing a block
which implements NET, and returns the name of the
system and network block.
If the network has delays its sample time is
determined by the network property NET.sampleTime,
otherwise the sample time will be -1.
Optional pairs of parameter/value arguments may be
added to the argument list as
gensim(NET,'param1',value1,'param2',value2,...).The
parameters and value definitions are:

58
'Name' - A string to be the new system's name.

'SampleTime' - The value may be -1 or any integer


greater or equal to 1.This overrides the default
sample time.

'InputMode' - The value may be 'none', 'port',

'workspace', or the default, 'constant'. This


indicates the kind of input block generated.

'OutputMode' - The value may be 'none', 'display',


'port', 'workspace',or the default, 'scope'.

'SolverMode' - This can be 'default' which leaves


the generated system with the default Simulink solver
settings, or 'discrete' which sets the solver mode to
discrete with the steps equal to the sample time.

59
1.20 THE NEURAL LIBRARY:

The Neural Network Toolbox™ product provides a set of blocks you


can use to build neural networks using Simulink® software or that the
function gensim can use to generate the Simulink version of any network
you have created using MATLAB® software.
Bring up the Neural Network Toolbox blockset with this command:
<< neural;
The result is a window that contains five blocks. Each of these blocks
contains additional blocks.

60
THE SIMULATION OF RELAY OPERATION ON DETECTING
FAULTY READING:

BLOCKS USED

1. Neural Network Trained By


● Levenberg Marquardt Algorithm
● Gradient Descent Algorithm
2. Data Import From Workspace
3. Vector Concatenate
4. Remove Rows
5. Vector Array Subtract
6. VectorScope
7. Delay
8. Relay
9. Display

Table:1 ​The table shows the list of blocks used for realizing the simulation.

61
​Figure 15. ​Simulation block

62
1.21 BLOCK PARAMETERS:
RELAY STATE (VectorScope) :

The scope shows the plot of the relay state at a time span of 1000
frames.

63
1.22 PREDICTED OUTPUT(DISPLAY BLOCK):

1.23 REMOVEROWS BLOCK:

​ he remove rows block takes in a vector of size 7X1 and retains


T
only the first row indicated by the “keep indices” parameter.

64
FUNCTION BLOCK PARAMETERS:
RELAY:

The relay is switched on for threshold voltage of 200 volts and switched
off for any value below 10 volts.

65
1.24 OUTPUT PLOT:

Figure 16 ​.Red cross plot - actual values of parameters, black


curve - predicted values of parameters.
The above capture is that of frame 460 and it has a 10s time
span.This is a continuous and row-wise plotting of the values of
voltmeter and wattmeter readings of the three phases in order.

66
1.25 RELAY STATE:

Figure 17 .​Plot of the state of relay from time of start to 0.16 min.
The relay state transition occurs at time 0.065 min after detecting fault.

67
CHAPTER-2
2.1 LITERATURE REVIEW
● HD Beale, HB Demuth, MT Hagan - Pws, Boston, 1996 -
pdfs.semanticscholar.org-​Designing ​Neural Networks ​- ​Evolving
Artificial Neural Network Proceedings of the IEEE, 1999 -
ieeexplore.ieee.org-Recurrent Neural Network and time series
prediction JT Connor, RD Martin, LE Atlas - … on neural
networks, 1994 - ieeexplore.ieee.org-Training Recurrent Neural
Networks With the Levenberg–Marquardt Algorithm.
● X Fu, S Li, M Fairbank, DC Wunsch… - IEEE transactions on …,
2014 - ieeexplore.ieee.org-Levenberg–Marquardt Backpropagation
Training of Multilayer Neural Networks for State Estimation of a
Safety-Critical Cyber-Physical System
● C Lv, Y Xing, J Zhang, X Na, Y Li, T Liu… - IEEE ​Transactions
2017 - ieeexplore.ieee.org-Neural networks in process fault
diagnosis
● T Sorsa, HN Koivo, H Koivisto - IEEE ​Transactions on systems
…, 1991 - ieeexplore.ieee.org-Smart attacks in smart grid
communication networks
● PY Chen, SM Cheng, KC Chen - IEEE ​Communications …, 2012
- ieeexplore.ieee.org
● A Very Brief Introduction to Machine Learning With Applications
to Communication Systems
● O Simeone - IEEE ​Transactions on Cognitive Communications …,
2018 - ieeexplore.ieee.org
● Artificial Neural Networks-Based Machine Learning for Wireless
Networks M Chen, U Challita, W Saad, C Yin… - … Surveys &
Tutorials, 2019 - ieeexplore.ieee.org

68
● Learning capability and storage capacity of two-hidden-layer
feedforward networks GB Huang - IEEE transactions on neural
networks, 2003 - ieeexplore.ieee.org
● AN EFFICIENT ELECTRICITY THEFT AND FAULT
DETECTION SCHEME IN DISTRIBUTION SYSTEM :
Muhammad Salik, Muhammad Fahad Zia, Fahad Ali School of
Science and Technology, University of Management and
Technology
● Rezaei, N., & Haghifam, M. R. (2008). Protection scheme for a
distribution system with distributed generation using neural
networks. International Journal of Electrical Power & Energy
Systems, 30(4), 235-241.
● NARMAX time series model prediction: feedforward and
recurrent fuzzy neural network approaches ​Y Gao, MJ Er - Fuzzy
sets and systems, 2005 - Elsevier
● A delay damage model selection algorithm for NARX neural
networks
● TN Lin, CL Giles, BG Horne… - IEEE Transactions on …, 1997 -
ieeexplore.ieee.org

69

You might also like