You are on page 1of 46

Tutorial on Data-Driven Modeling in Water Resource

and Environmental Engineering Using Matlab


Feb 2014
Waqar S. Qureshi
Teaching Associate
Asian Institute of Technology

February 11, 2014

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

1 / 33

Outline
1
2

Major challenges for water engineers


System modeling for water engineering
What is modeling
Types of modeling
Data-driven models
Statistical models
Soft computing model
Spatio-temporal complexity
Type of data
General approach to develop a data-driven model
Regression-based models
Introduction
Regression model application
Linear regression
Linear-regression-example-1
Linear-regression-example-2
Matlab Tutorial

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

2 / 33

Outline
1
2

Major challenges for water engineers


System modeling for water engineering
What is modeling
Types of modeling
Data-driven models
Statistical models
Soft computing model
Spatio-temporal complexity
Type of data
General approach to develop a data-driven model
Regression-based models
Introduction
Regression model application
Linear regression
Linear-regression-example-1
Linear-regression-example-2
Matlab Tutorial

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

3 / 33

Todays major challenges for water engineers include:


Securing water resources for people
Protecting vital echosystems
Dealing with variability and uncertainty of water in space and time

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

4 / 33

Outline
1
2

Major challenges for water engineers


System modeling for water engineering
What is modeling
Types of modeling
Data-driven models
Statistical models
Soft computing model
Spatio-temporal complexity
Type of data
General approach to develop a data-driven model
Regression-based models
Introduction
Regression model application
Linear regression
Linear-regression-example-1
Linear-regression-example-2
Matlab Tutorial

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

5 / 33

Outline
1
2

Major challenges for water engineers


System modeling for water engineering
What is modeling
Types of modeling
Data-driven models
Statistical models
Soft computing model
Spatio-temporal complexity
Type of data
General approach to develop a data-driven model
Regression-based models
Introduction
Regression model application
Linear regression
Linear-regression-example-1
Linear-regression-example-2
Matlab Tutorial

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

5 / 33

System modeling for water engineering


What is modeling

The term model refers to tools, softwares, and programs used to


represent real-world systems.
Modeling of a system is used to predict the system behavior and response
to the changing factors.

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

6 / 33

Outline
1
2

Major challenges for water engineers


System modeling for water engineering
What is modeling
Types of modeling
Data-driven models
Statistical models
Soft computing model
Spatio-temporal complexity
Type of data
General approach to develop a data-driven model
Regression-based models
Introduction
Regression model application
Linear regression
Linear-regression-example-1
Linear-regression-example-2
Matlab Tutorial

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

6 / 33

System modeling for water engineering


Types of modeling

Physical model is rescaled copy of the actual system, example, DAM


models.
Mathematical model is baed on mathematical logic, knowledge, and
equations.

Figure: classification of models

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

7 / 33

System modeling for water engineering


Applications and complexity

As water and environmental engineers, system modeling can be applied in


many applications such as:
Simulation of natural phenomenon
Synthetic data generation
Forecasting and warning of extreme events
Developing decision making rules
Modeling a system in the field of water engineering is difficult:
Physical complexity of natural phenomenon.
Time consuming process of analyzing different components of the
system.

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

8 / 33

Outline
1
2

Major challenges for water engineers


System modeling for water engineering
What is modeling
Types of modeling
Data-driven models
Statistical models
Soft computing model
Spatio-temporal complexity
Type of data
General approach to develop a data-driven model
Regression-based models
Introduction
Regression model application
Linear regression
Linear-regression-example-1
Linear-regression-example-2
Matlab Tutorial

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

8 / 33

System modeling for water engineering


Data-driven models

Models that can simulate a system by the experimental data of that


system is known as data-driven models.
Data-driven models enable us to map causal factors and consequent
outcomes from the observed patterns (experimental data), without deep
understanding of the complex physical process.
The purpose of data-driven modeling in water engineering can include the
following:
Data classification and clustering.
Extreme value predition with ephasis on floods and droughts.
Water quality simulation and prediction.
Extending the length of hydroclimatological data from the historical
ones.
Modeling water balance concerning different components of a
hydrological system.
Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

9 / 33

System modeling for water engineering


data-driven models

For a complex system, data-driven models are inexpensive, accurate,


precise, and flexible in contrast to their counter physical models or
analytical models.
Data-driven models can be used for problems where we have less
information about the intrinsic complexity of the phenomenon, in contrast
to analytical modeling.
Two groups of Data-driven models are:
Statistical modeling
Soft computing (Artificial intelligence)

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

10 / 33

Outline
1
2

Major challenges for water engineers


System modeling for water engineering
What is modeling
Types of modeling
Data-driven models
Statistical models
Soft computing model
Spatio-temporal complexity
Type of data
General approach to develop a data-driven model
Regression-based models
Introduction
Regression model application
Linear regression
Linear-regression-example-1
Linear-regression-example-2
Matlab Tutorial

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

10 / 33

System modeling for water engineering


Statistical model

A statistical model is comprised of random and deterministic variables.


Deterministic variables are defined by mathematical model and use a set of
equations to generate data, while random variable is represented by a
probabilistic models for example a probability density function to generate
data.
The probabilistic models can be parametric and non parametric.
Parametric model can be described by its mean, variance, etc.
Non-parametric models can be described by loosely confined assumptions
such as nearest neighbor.

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

11 / 33

Outline
1
2

Major challenges for water engineers


System modeling for water engineering
What is modeling
Types of modeling
Data-driven models
Statistical models
Soft computing model
Spatio-temporal complexity
Type of data
General approach to develop a data-driven model
Regression-based models
Introduction
Regression model application
Linear regression
Linear-regression-example-1
Linear-regression-example-2
Matlab Tutorial

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

11 / 33

System modeling for water engineering


Soft computing model

In soft computing the system is modeled using fuzzy logic,


neuro-computing, and genetic algorithms.
It is tolerant of imprecision, uncertainty, partial truth, and approximation.
The role model of soft computing is human mind.
Example: A suitable temperature of a room to make people feel
comfortable!

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

12 / 33

Outline
1
2

Major challenges for water engineers


System modeling for water engineering
What is modeling
Types of modeling
Data-driven models
Statistical models
Soft computing model
Spatio-temporal complexity
Type of data
General approach to develop a data-driven model
Regression-based models
Introduction
Regression model application
Linear regression
Linear-regression-example-1
Linear-regression-example-2
Matlab Tutorial

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

12 / 33

System modeling for water engineering


Spatio-temporal complexity

The model complexity can also be classified in spacial and temporal


manner.
The spacial and temporal characteristics of a model is essential to study
the effects due to the dynamic change of natural phenomenon on the
system.
The spacial complexity of a model can be characterized as lumped,
semi-distributed, and distributed models.
Let us take an example of rainoff modeling to understand spacial
complexity of models.

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

13 / 33

System modeling for water engineering


Lumped models

Lumped modeling methods were used due to complex data collection


methods and software limitations.
Lumped models are still useful for producing flood guidance. They require
less data input and less computational power than more modern methods.

Figure: Spacial complexity for runoff model

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

14 / 33

System modeling for water engineering


Semi-distributed models

Semi-distributed modeling is a variation of the lumped method and is


sometimes referred to as a pseudo-distributed approach. Using this
approach, a basin is broken down into smaller sub-basins. Runoff amounts
from methods such as unit hydrograph are used to estimate stream flow
from each of these sub-basins

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

15 / 33

System modeling for water engineering


Semi-distributed models

A truly distributed modeling is one that represents processes in a gridded


manner.
Each cell has its parameters allowing for its own stream flow estimates.
If these data in each cell are not available, they must somehow be
estimated, introducing an uncertainty factor.

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

16 / 33

System modeling for water engineering


Temporal complexity

Data-driven models can be static or dynamic.


A rainoff is dynamic if its parameters changes as it receives new
information, and is considered static if the model relies only on the
historical data.
In summary, the purpose of modeling is an essential criteria to select a
model and determines its complexity, developing time, runtime, its
accuracy, and precision.
Modeling also depends upon the type of data that is available, and the
time required to acquire it.

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

17 / 33

Outline
1
2

Major challenges for water engineers


System modeling for water engineering
What is modeling
Types of modeling
Data-driven models
Statistical models
Soft computing model
Spatio-temporal complexity
Type of data
General approach to develop a data-driven model
Regression-based models
Introduction
Regression model application
Linear regression
Linear-regression-example-1
Linear-regression-example-2
Matlab Tutorial

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

17 / 33

System modeling for water engineering


Type of data

Figure: Types of Data, (a) discrete data, (b) continuous data, (c) spacial data,
(d) temporal data

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

18 / 33

Outline
1
2

Major challenges for water engineers


System modeling for water engineering
What is modeling
Types of modeling
Data-driven models
Statistical models
Soft computing model
Spatio-temporal complexity
Type of data
General approach to develop a data-driven model
Regression-based models
Introduction
Regression model application
Linear regression
Linear-regression-example-1
Linear-regression-example-2
Matlab Tutorial

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

18 / 33

System modeling for water engineering


General approach to develop a data-driven model

Figure: General approach to develop a data-driven model


Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

19 / 33

Outline
1
2

Major challenges for water engineers


System modeling for water engineering
What is modeling
Types of modeling
Data-driven models
Statistical models
Soft computing model
Spatio-temporal complexity
Type of data
General approach to develop a data-driven model
Regression-based models
Introduction
Regression model application
Linear regression
Linear-regression-example-1
Linear-regression-example-2
Matlab Tutorial

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

20 / 33

Outline
1
2

Major challenges for water engineers


System modeling for water engineering
What is modeling
Types of modeling
Data-driven models
Statistical models
Soft computing model
Spatio-temporal complexity
Type of data
General approach to develop a data-driven model
Regression-based models
Introduction
Regression model application
Linear regression
Linear-regression-example-1
Linear-regression-example-2
Matlab Tutorial

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

20 / 33

Regression-based models
Introduction

The regression-based models are data-driven models that are easy to use
and popular.
They ranges from linear to nonlinear and parametric to nonparametric
models.
Following are the application areas of regression based models
Prediction, forecasting, and estimation of missing data.
Interpolation and extrapolation of data.
They are segregated as
Multiple linear regression model.
Conventional non linear regression method.
KNN non parametric model.
logistic regression model.
Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

21 / 33

Outline
1
2

Major challenges for water engineers


System modeling for water engineering
What is modeling
Types of modeling
Data-driven models
Statistical models
Soft computing model
Spatio-temporal complexity
Type of data
General approach to develop a data-driven model
Regression-based models
Introduction
Regression model application
Linear regression
Linear-regression-example-1
Linear-regression-example-2
Matlab Tutorial

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

21 / 33

Regression-based models
Regression model application

Figure: A summary on the application of regression models in water resources and


environmental engineering
Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

22 / 33

Outline
1
2

Major challenges for water engineers


System modeling for water engineering
What is modeling
Types of modeling
Data-driven models
Statistical models
Soft computing model
Spatio-temporal complexity
Type of data
General approach to develop a data-driven model
Regression-based models
Introduction
Regression model application
Linear regression
Linear-regression-example-1
Linear-regression-example-2
Matlab Tutorial

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

22 / 33

Regression-based models
Linear regression

Linear regression is used to model the linear relationship between the


continuous dependent variable (y) and an independent variable (x).
The regression model aim to identify what variables are associated with y,
to predict the future observations of y.

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

23 / 33

Regression-based models
Linear regression

Let x and y two variables, then a plot between x and y shows if y is


positive, negative linear or non-linear function.

Figure: Different type of correlation between Y and X

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

24 / 33

Regression-based models
Linear regression

The strength of linear relationship between two variables is measured by


simple correlation coefficient.
The Correlation coefficient between n observations f X and Y is calculated
as

Figure: Correlation coefficient

Figure: sample script for corrcoef(x)


Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

25 / 33

Regression-based models
Linear regression

A simplest regression function is refined as


y = o + 1 .x, where o and 1 are parameters of the model

Figure: Samples of errors in linear regression fitting

The linear regression modeling tends to fit a line onto the observed data
such that the sum of absolute errors of fitting for n-observations is
minimized.
n
n
X
X
2
2
S =
i =
(yi o + 1 .xi )2
i=1
Waqar Qureshi (AIT)

i=1

Modeling for WREE

February 11, 2014

26 / 33

Regression-based models
Linear regression

In case of multiple independent variables xi ... xn the model becomes


multiple linear regression and is represented by the equation.
y = o + 1 .x1 + 2 .x2 + 3 .x3 + 3 .x3 + 4 .x4
The dependent variable y can be a deterministic or a probabilistic. In case
it becomes a probabilistic, then the stochastic equation of the form is
given as
y = o + 1 .x + e
, where e is the estimation error.
The output at any instant of x can be represented by a distribution
function. The expected value of the estimation is in fact the average value
of this distribution which is given by y = o + 1 .x.
Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

27 / 33

Regression-based models
Linear regression

Figure: PDF of dependent variable in a linear regression model

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

28 / 33

Outline
1
2

Major challenges for water engineers


System modeling for water engineering
What is modeling
Types of modeling
Data-driven models
Statistical models
Soft computing model
Spatio-temporal complexity
Type of data
General approach to develop a data-driven model
Regression-based models
Introduction
Regression model application
Linear regression
Linear-regression-example-1
Linear-regression-example-2
Matlab Tutorial

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

28 / 33

Regression-based models
Linear regression-example

Interpolation of water quality values.


Water quality of a river as a function of distane from the upstream of river
is tabulated. Use a linear regression model to interpolate total dissolved
solution (TDS) at different locations of the river.

Figure: Data presented for Example


Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

29 / 33

Outline
1
2

Major challenges for water engineers


System modeling for water engineering
What is modeling
Types of modeling
Data-driven models
Statistical models
Soft computing model
Spatio-temporal complexity
Type of data
General approach to develop a data-driven model
Regression-based models
Introduction
Regression model application
Linear regression
Linear-regression-example-1
Linear-regression-example-2
Matlab Tutorial

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

29 / 33

Regression-based models
Linear regression-example

Solve the above Example in a probabilistic manner and calculate the


probable range of TDS at the distance of 125km from the upstream.

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

30 / 33

Outline
1
2

Major challenges for water engineers


System modeling for water engineering
What is modeling
Types of modeling
Data-driven models
Statistical models
Soft computing model
Spatio-temporal complexity
Type of data
General approach to develop a data-driven model
Regression-based models
Introduction
Regression model application
Linear regression
Linear-regression-example-1
Linear-regression-example-2
Matlab Tutorial

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

31 / 33

Matlab Tutorial

Waqar Qureshi (AIT)

Modeling for WREE

February 11, 2014

32 / 33

End

46 / 46

You might also like