Matlab NN
Matlab NN
neural networks
R. R. Shrestha, S. Theobald, F. Nestmann
Abstract
Artificial neural networks (ANNs) provide a quick and flexible means of developing flood flow simulation models. An important criterion for
the wider applicability of the ANNs is the ability to generalise the events outside the range of training data sets. With respect to flood flow
simulation, the ability to extrapolate beyond the range of calibrated data sets is of crucial importance. This study explores methods for
improving generalisation of the ANNs using three different flood events data sets from the Neckar River in Germany. An ANN-based model
is formulated to simulate flows at certain locations in the river reach, based on the flows at upstream locations. Network training data sets
consist of time series of flows from observation stations. Simulated flows from a one-dimensional hydrodynamic numerical model are integrated
for network training and validation, at a river section where no measurements are available. Network structures with different activation
functions are considered for improving generalisation. The training algorithm involved backpropagation with the Levenberg-Marquardt
approximation. The ability of the trained networks to extrapolate is assessed using flow data beyond the range of the training data sets. The
results of this study indicate that the ANN in a suitable configuration can extend forecasting capability to a certain extent beyond the range of
calibrated data sets.
Keywords: artificial neural networks, activation function, backpropagation, hydrodynamic numerical model, multilayer perceptron, Neckar
River.
313
Rajesh Raj Shrestha, Stephan Theobald and Franz Nestmann
forecasting and found that although lower water levels were Bias
x1 wk1
predicted fairly accurately, higher water levels were bk
underestimated. Solas et al. (2000) used average, dry and Activation
x2 wk2 function
wet years mean annual precipitation in a rainfall-runoff f(yk)
modelling application of ANNs, and observed that high Ȉ
flows were overestimated for the wet years. yk
314
Simulation of flood flow in a river system using ar tificial neural networks
ii. Sigmoidal function produces an output in the range 0 Study area and data
to +1. This function has the following form
The Neckar is a major tributary of the Rhine and flows
1 (2) through the region of Stuttgart, Heidelberg and Mannheim
f (y k )
1 exp(-y k ) in south-west Germany. The study area consists of a reach
iii. Hyperbolic tangent function is mathematically of about 100 km from Lauffen to Heidelberg (Fig. 3) with a
equivalent to tanh(yk) and produces an output in the catchment area of 13 787 km2 at the Heidelberg station. Time
range -1 to +1. This function is given by series of flow and water level data at one hour intervals are
available from the gauging stations located at Lauffen,
2 Rockenau and Heidelberg and water level time series are
f (y k ) 1 (3)
1 exp(-2y k ) available from Gundelsheim station for the 1988, 1990 and
iv. Hyperbolic tangent + linear function can be used to 1993 flood events. Flow time series from the major
combine non-linearity of the hyperbolic tangent function tributaries Kocher, Jagst and Elz and the smaller tributaries
with the linear function using the weighing factor ±. Schwarzbach, Elsenz and Itter are also available for the same
This function is of the form years. There is also a functioning one-dimensional
hydrodynamic numeric (HN) model of the study area, with
§ 2 · cross-sections at 100 m interval. Only the simulated flows
f (y k ) ¨¨ 1 ¸¸D (1 D )y k (4)
© 1 exp(-2y k ) ¹ from the HN model at Gundelsheim station, where no flow
Figure 2 shows these four different activation functions for
the data range 2 to +2. From the figures it can be seen that
1.5
0.5
f (yk)
-0.5
-1 Linear function
Linear + Hyperbolic tangent function
Hyperbolic tangent function
-1.5 Sigmoidal function
-2
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
yk
315
Rajesh Raj Shrestha, Stephan Theobald and Franz Nestmann
Table 1. Statistical characteristics of the flow data at Rockenau and Heidelberg gauging stations
ROCKENAU
Training set (1988) 958 1930 341 399
Validation set (1990) 583 2225 144 576
Test set (1993) 713 2680 232 579
HEIDELBERG
Training set (1988) 1060 1945 374 401
Validation set (1990) 666 2299 224 604
Test set (1993) 807 2706 275 597
data are available, are included for model training and The forecast horizons at Gundelsheim, Rockenau and
validation. The available flow data were divided in such a Heidelberg with respect to the upstream flows are each 2
way that the maximum flows of validation and test data sets hours. However, since the contribution from the tributaries
exceed the range of training data sets. The flow time series Elz, Schwarzbach, Elsenz and Itter are quite small compared
from the 1988 flood event was used as training set, and to flows in the rivers, their flows can be assumed to be
flood event data from 1990 and 1993 were used as validation constant for the duration of forecast to increase the forecast
and test data sets. The statistical characteristics of the flow horizon. This increases the forecast horizon at Rockenau
data at the prediction stations Rockenau and Heidelberg are station to 5 hours and Heidelberg station to 7 hours. The
summarised in Table 1. forecast horizon can be increased further by integrating with
A cross correlation analysis was performed on the time external models such as the rainfall-runoff models.
series flows to identify a suitable lag time from upstream to
downstream points. The cross correlation analyses of the
time series water level data from Lauffen, Gundelsheim and
River flow prediction
Rockenau stations yielded the suitable lag time for The selection of appropriate input and output data sets is an
Gundelsheim and Rockenau with respect to the upstream important consideration in the ANN modelling. A number
stations. Similarly, the analysis between the flow data from of experiments was performed with the division of river
Rockenau and Heidelberg gave the lag time for the reach into different ANN blocks. In the first experiment the
Heidelberg station. The lag times for the tributaries inflows ANN was used to predict flows at the gauging station
were calculated based on their distances. The lag times with Rockenau, based on the upstream flows from Lauffen
respect to forecast stations Gundelsheim, Rockenau and (Neckar), and the tributaries Kocher, Jagst and Elz. However,
Heidelberg for the upstream stations in the Neckar river and although the network functioned quite well for the training
the tributaries are given in Table 2. and validation data sets, it did not perform well for the test
data sets.
As a functioning HN model is available for the study area,
Table 2. Lag time with respect to forecast stations it was decided to integrate the HN simulated results from
Gundelsheim for the ANN training. It was observed that
Forecast station Upstream stations Lag time (hrs) the integration of HN model results from Gundelsheim
improved the performance of river flow prediction at
Gundelsheim (Neckar) Lauffen (Neckar) 4
Rockenau. Accordingly, the river reach was divided into
Stein (Kocher) 3
three sub-reaches represented by independently trained
Untergriesheim (Jagst) 2
ANN blocks. The observed flows at Lauffen, Rockenau and
Rockenau (Neckar) Gundelsheim (Neckar) 3 Heidelberg stations, together with the tributaries and HN
Mosbach (Elz) 2 model results from Gundelsheim, were integrated for the
Heidelberg (Neckar) Rockenau (Neckar) 2 ANN training. The inflows and the desired outflows for each
Eschelbronn (Schwarzbach) 2 of the ANN blocks are summarised in Table 3. Outputs of
Eberbach (Itter) 2 the best performing networks from previous blocks were
Meckesheim (Elsenz) 2 used as inputs to next blocks.
316
Simulation of flood flow in a river system using ar tificial neural networks
ANN block 1 Lauffen Gundelsheim Measured flows from gauging stations at Simulated flows from the HN
Lauffen, and tributaries Jagst and Kocher model at Gundelsheim
ANN block 2 Gundelsheim Rockenau Simulated flows from the ANN block 1 at Measured flows from gauging
Gundelsheim, and measured flow from stations at Rockenau
gauging station at the tributary Enz
ANN block 3 Rockenau Heidelberg Simulated flows from the ANN block 2 at Measured flows from gauging
Rockenau, and measured flows from stations at Heidelberg
gauging stations at the tributaries Schwarzbach,
Elsenz, and Itter
The input data sets for the ANN trainings were scaled in performing network blocks in each of the sub-reaches (with
the range [0.2 0.8]. Each of the ANN blocks was trained the hyperbolic tangent and linear function in the first hidden
with one input layer, two hidden layers and one output layer. layer for the first and third blocks and hyperbolic tangent
The number of neurons in the networks was kept to a function in the first and second hidden layers for the second
minimum of eight in the first hidden layer, four in the second block) were combined in the Simulink environment and an
hidden layer and one in the output layer. There was no ANN simulation model was formulated. The combined ANN
significant improvement of the model performance with the simulation model is schematised in Fig. 4.
increase in number of neurons. Each of the networks
consisted of a linear activation function in the output layer.
The networks were trained with four different activation Error Measurement
functions in the first hidden layer, namely linear, sigmoidal, Table 4 shows the statistics of the error comparison used in
hyperbolic tangent and a hyperbolic tangent + linear this study. The error measurement process consists of
function. The weighing factor ± for the hyperbolic tangent analysis of errors between observed and calculated values.
+ linear function was varied between 0.4 and 0.8 during The overall performance of trained networks can be judged
training process. with respect to criteria such as the coefficient of efficiency
The networks were trained using the procedures from (CE) and coefficient of determination (R 2 ). These
MATLAB neural network toolbox. This involved network coefficients are independent of the scale of data used and
designing using text files containing MATLAB code (M- are useful in assessing the goodness of fit of the model
files). The training is done using a backpropagation (Dawson et al., 2002; Dawson and Wilby, 1999). The root
algorithm with Bayesian regularisation of the Levenberg- mean square error (RMSE) evaluates the error independent
Marquardt approximation. The early stopping criteria of sample size and can give useful insights into amplitude
provided by the validation data sets were used to prevent errors. The difference in peak flow between observed and
overtraining. The test data sets were used independently for calculated flows was considered to assess the prediction
the evaluation of the model performance. The best capability of the trained networks beyond the calibrated range.
Itter
Kocher
Elsenz
Gundelsheim
Rockenau
Heidelberg
ANN ANN
Neckar(Lauffen) ANN
Block 1 Block 2 Block 3
Jagst
Elz Schwarzbach
317
Rajesh Raj Shrestha, Stephan Theobald and Franz Nestmann
¦(Q
i 1
obs Qav ) 2
2000
Runoff (m3/s)
2
ª n º
Coefficient of determination R2 «¦ (Q
¬i 1
obs Qav )(Qcal Qcal _ av ) »
¼ 1500
ª n ºª n º
«¦ (Q
¬i 1
obs Qav ) » « ¦ (Q
¼¬ i 1
cal Qcal _ av ) »
¼
1000
Root mean square errors RMSE 1 n
¦ ( Qobs Qcal ) 2
n i1
Activation functions Coefficient of efficiency Coefficient of determination Root mean square error Difference in peak flow
CE R2 RMSE (m3 s1) (m3 s1)
318
Simulation of flood flow in a river system using ar tificial neural networks
Activation functions Coefficient of efficiency Coefficient of determination Root mean square error Difference in peak flow
CE R2 RMSE (m3 s1) (m3 s1)
Activation functions Coefficient of efficiency Coefficient of determination Root mean square error) Difference in peak flow
CE R2 RMSE (m3 s1) (m3 s1)
Activation functions Coefficient of efficiency Coefficient of determination Root mean square error Difference in peak flow
CE R2 RMSE (m3 s1) (m3 s1)
ANN model, which do not integrate the HN model results Linear function
Hyperbolic tangent+ linear function
from Gundelsheim (Table 5 and 7). The statistical 2500 Hyperbolic tangent function
Sigmoidal function
performance in terms of CE, R2, RMSE and difference in
peak flow of the Gundelsheim to Rockenau ANN models
Runoff (m3/s)
2000
using all activation functions are found to be superior.
The performance ANN block 3 between Rockenau and
Heidelberg also improved with the application of activation 1500
319
Rajesh Raj Shrestha, Stephan Theobald and Franz Nestmann
3000
Rockenau containing the best performing ANN blocks in the previous
HN Simulated
Observed
section was used. Simulations using the HN models were
Hyperbolic tangent function in 2 layers also made by multiplying the upstream flows by 1.5. The
Linear function
2500
Hyperbolic tangent + linear function outputs of the HN model and ANN simulated results were
Hyperbolic tangent function
Sigmoidal function compared with each other. Figures 8, 9 and 10 show the
2000
comparison of the results at Gundelsheim, Rockenau and
Runoff (m3/s)
500
90 100 110 120 130 140 150 160 170 180
Time (hrs) Gundelsheim
4000
NN-Simulated
Fig. 7. Comparison of model performance of different activation HN-Simulated
functions at Rockenau (Block 2) 3500
3000
Heidelberg
Runoff (m3/s)
3000
Observed 2500
HN-Simulated
Linear function
Hyperbolic tangent + linear function 2000
2500 Hyperblic tangent function
Sigmoidal function
1500
2000
Runoff (m3/s)
1000
1500 500
90 100 110 120 130 140 150 160 170 180
Time (hrs)
ANNs results are compared with the simulated flows from 3000
2500
the comparison with both HN model results and measured
flow series. 2000
It is to be noted that the statistical performance of the
ANN model for block 1 is not consistent with blocks 2 and 1500
500
90 100 110 120 130 140 150 160 170 180
ANN MODELS FOR EXTREME FLOWS Time (hrs)
320
Simulation of flood flow in a river system using ar tificial neural networks
4000
Heidelberg from observations and numerical model results. This also
NN-Simulated provides guidance to the network training and enhances the
HN-Simulated
overall model performance. The assessment of results of
3500
the trained networks shows that a combination of hyperbolic
tangent and linear transfer functions at the first hidden layer
3000
generally produced the best performance. This function has
Runoff (m3/s)
1000
90 100 110 120 130 140
Time (hrs)
150 160 170 180
References
ASCE Task Committee on Application of Artificial Neural
Networks in Hydrology, 2000. Artificial neural networks in
Fig. 11. Comparison of model performance at Heidelberg using 1993
hydrology II: Hydrologic applications. J. Hydrolog. Eng.-ASCE,
flows multiplied by 1.5 (Hyperbolic tangent + linear activation
function)
5, 124137.
Dawson, C.W. and Wilby, R.B., 1999. A comparison of artificial
neural networks for flow forecasting. Hydrol. Earth Syst. Sci.,
3, 529540.
overestimation at Rockenau (ANN block 2). It is interesting Dawson, C.W., Harpham C., Wilby, R.B. and Chen, Y., 2002.
Evaluation of artificial neural network techniques for flow
to note here that ANN blocks 1 and 3 have a combination of
forecasting in River Yangtze, China. Hydrol. Earth Syst. Sci.,
linear and hyperbolic transfer functions at the first hidden 6, 619626.
layers and ANN block 2 has hyperbolic transfer functions Demuth, H. and Beale M., 2000. Neural network toolbox users
at the first and second hidden layers. guide. The MathWorks Inc. Online documentation: http://
www.mathworks.com/access/helpdesk/help/toolbox/nnet/
The result highlighted a random behaviour of the ANNs Dolling, O.R. and Veras, E.A., 2002. Artificial neural networks
when used to predict extreme flow events. It might function for streamflow prediction. J. Hydraul. Res., 40, 547554.
quite well in some cases and not so well in other cases. Haykin, S., 1994. Neural networks a comprehensive foundation
(1st Edition). Macmillan College Publishing Company, Inc.,
Hence caution needs to be exercised in the use of ANNs for New York.
forecasting extreme events. It is also important to specify Imrie, C. E., Durucan, S. and Korre, A., 2000. River flow prediction
the forecasting range of the trained ANNs. using artificial neural networks: generalisation beyond
calibration range. J. Hydrol., 233, 138153.
Lekkas, D.F., Imrie, C.E. and Lees M.J., 2001. Improved nonlinear
transfer function and neural network methods for flow routing
Conclusions for real-time flood forecasting. J. Hydroinformatics, 3, 153164.
This paper has presented an ANN-based approach for the Minns, A.W., 1996. Extended rainfall-runoff modelling using
artificial neural networks, A. Müller (Ed.), Proc.
simulation of flood flows in the Neckar River in Germany. Hydroinformatics 96, Balkema, Rotterdam, the Netherlands.
The river reach was divided into three sub-reaches for the 207213.
ANN trainings. The effects of different activation functions Shamseldin, A.Y., Nasr, A.E. and OConnor, K.M., 2002.
Comparison of different forms of the multi-layer feed-forward
at the first hidden layer of multilayer perceptron (MLP)
neural network method used for river flow forecasting. Hydrol.
neural networks were evaluated for predicting flows beyond Earth Syst. Sci., 6, 671684.
a calibrated range. This evaluation was made in terms of Shrestha, R.R., 2003. Flood routing using artificial neural
test data sets with higher peaks, above the range of training networks. Proc. XXX IAHR Congress, JF Kennedy Student
Paper Competition, Thessaloniki, Greece.
data sets. Four different activation functions, the sigmoidal, Sivakumar, B., Jayawardena, A.W. and Fernando, T.M.K.G., 2002.
hyperbolic tangent, linear, and a combination of hyperbolic River flow forecasting: use of phase-space reconstruction and
tangent and linear functions were investigated in this study. artificial neural networks approaches. J. Hydrol., 265, 225245.
Solas, J.D., Markus, M. and Tokar, A.S., 2000. Streamflow
The results of this study indicate that the ANNs provide forecasting based on artificial neural networks. In: Artificial
an efficient means of flood flow forecasting. Compared to neural networks in hydrology, R.S. Govindaraju and A.
a HN model, which requires a lot of cross-sectional data, Ramachandra Rao (Eds.), Kluwer Academic Publishers,
Dordrecht, The Netherlands. 2351.
the ANN model can be quickly trained to forecast flows at
Thirumalaiah, K. and Deo, M.C., 1998. River stage forecasting
specific sections in the river reach. The division of river using artificial neural networks. J. Hydrolog. Eng.-ASCE, 3,
reach into sub-reaches facilitates the integration of data 2631.
321