forked from SAFEtoolbox/SAFE-matlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
workflow_glue_hymod.m
149 lines (120 loc) · 4.09 KB
/
workflow_glue_hymod.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
% This script provides an application example of the Generalized Likelihood
% Uncertainty Estimation (GLUE) method (see help GLUE.m for more details
% about this Uncertainty Analysis method and references).
%
% MODEL AND STUDY AREA
%
% The model under study is the rainfall-runoff model Hymod
% (see help of function hymod_sim.m for more details)
% applied to the Leaf catchment in Mississipi, USA
% (see header of file LeafCatch.txt for more details).
% The inputs subject to SA are the 5 model parameters, and the scalar
% output for SA is (one or multiple) performance metric.
% This script prepared by Francesca Pianosi and Fanny Sarrazin
% University of Bristol, 2014
% mail to: [email protected]
my_dir = pwd ; % use the 'pwd' command if you have already setup the Matlab
% current directory to the SAFE directory. Otherwise, you may define
% 'my_dir' manually by giving the path to the SAFE directory, e.g.:
% my_dir = '/Users/francescapianosi/Documents/safe_R1.0';
% Set current directory to 'my_dir' and add path to sub-folders:
cd(my_dir)
addpath(genpath(my_dir))
% Load data:
load -ascii LeafCatch.txt
rain = LeafCatch(1:365,1) ;
evap = LeafCatch(1:365,2) ;
flow = LeafCatch(1:365,3) ;
% Plot data:
figure
subplot(311)
plot(rain)
subplot(312)
plot(evap)
subplot(313)
plot(flow)
xlabel('time (days)')
%%%% EXPERIMENT SETUP
M = 5 ; % number of uncertain parameters [ Sm beta alfa Rs Rf ]
DistrFun = 'unif' ; % Parameter distribution
% Parameter ranges:
xmin = [ 0 0 0 0 0.1 ] ; % minimum values
xmax = [ 400 2 1 0.1 1 ] ; % maximum values
%%%% SAMPLING INPUT SPACE
% Sample the input space using the 'AAT_sampling' function
% (see help AAT_sampling.m for more details)
addpath('sampling')
SampStrategy = 'lhs' ; % sampling strategy (other options is 'rsu')
N = 3000 ; % sample size
% Create data structure for parameter ranges
% as required by AAT_sampling
for i=1:M; DistrPar{i} = [xmin(i) xmax(i) ] ; end % this is to resort to
% the format required by AAT_sampling function.
% Perform sampling:
X = AAT_sampling(SampStrategy,M,DistrFun,DistrPar,N);
% Plot results (for instance samples of param.1 vs param. 2):
figure; plot(X(:,1),X(:,2),'ob')
%%%% MODEL EVALUATION
% Define output function:
myfun = 'hymod_sim' ;
% (in the first place we just want to simulate the model and look at the
% time series of simulated flows)
warmup = 30 ; % lenght of model warmup period (days)
% (sensitivity indices will not be computed for the warmup period)
% Run the model and compute selected model output at sampled parameter
% sets:
Qsim = model_execution(myfun,X,rain,evap,warmup) ;
% Check size of 'Qsim':
size(Qsim)
% Plot simulated time series:
figure
plot(Qsim','b')
hold on; plot(flow,'ok') % add flow observations as black circles
xlabel('time (days)'); ylabel('flow (m3/s)')
%%%% GLUE
% Find 'behavioural' parameterizations and associated prediction limits
% by the 'GLUE' function
% (see help GLUE.m for more details)
addpath('GLUE')
% Compute Root Mean Squared Error for each time series:
Y = RMSE(Qsim,flow') ;
% Check size of 'Y':
size(Y)
% Plot the distribution of the output samples:
figure
plot_cdf(Y,'RMSE (m3/s)')
% Apply GLUE
threshold = 2.5 ; % threshold value
% (tip: make sure the sign of 'Y' and 'threshold' is consistent
% with the inequality assumption (above/below threshold)
% of the GLUE function)
[ idx, Llim, Ulim ] = GLUE(Y,threshold,Qsim) ;
% Plot 'behavioural' time series:
figure
plot(Qsim','b')
hold on
plot(Qsim(idx,:)','r')
plot(flow,'ok')
xlabel('time (days)'); ylabel('flow (m3/s)')
% Plot prediction limits by GLUE:
figure
plot([Llim Ulim],'m','LineWidth',2)
hold on
plot(flow,'ok')
xlabel('time (days)'); ylabel('flow (m3/s)')
%%%% VISUALIZATION TOOLS
% Use some visualization functions to gain further insights
% (see help scatter_plots.m
% and help parcoor.m)
% Scatter plots:
figure
scatter_plots(X,Y)
% customize the plot:
X_Labels = {'Sm','beta','alfa','Rs','Rf'} ;
figure
scatter_plots(X,Y,[],'RMSE',X_Labels)
% Highlight 'behavioural parameterizations' in different colour:
figure
scatter_plots(X,Y,[],'RMSE',X_Labels,idx)
% Parallel coordinate plots:
parcoor(X,X_Labels,[],idx);