-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdate_data.m
377 lines (330 loc) · 13.8 KB
/
update_data.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
function [probdata,gfundata,analysisopt] = update_data(lsf,probdata,analysisopt,gfundata,femodel)
% clear potential persistent variables
clear custom_pdf custom_cdf custom_invcdf
clear nonparametric_pdf nonparametric_cdf nonparametric_invcdf
% Assigns names to probdata.marg variables if not defined
marg = probdata.marg;
if ~isfield(probdata, 'name')
eval([ 'margname = {' sprintf(' ''x%d''',[1:size(marg,1)]) ' };']);
else
margname = probdata.name;
end
if size(margname,1) > size(margname,2)
margname = margname';
end
correlation = probdata.correlation;
% Assigns names to gfundata(lsf).thetag variables if not defined
if isfield(gfundata(lsf), 'thetag')
thetag = gfundata(lsf).thetag;
if size(thetag,1) < size(thetag,2)
thetag = thetag';
end
if ~isfield(gfundata(lsf), 'thetagname')
eval([ 'thetagname = {' sprintf(' ''thetag%d''',[1:length(thetag)]) ' };']);
else
thetagname = gfundata(lsf).thetagname;
end
if size(thetagname,1) > size(thetagname,2)
thetagname = thetagname';
end
else
thetagname = [];
thetag = [];
end
% Assigns names to gfundata(lsf).cg variables if not defined
if isfield(gfundata(lsf), 'cg')
cg = gfundata(lsf).cg;
if size(cg,1) < size(cg,2)
cg = cg';
end
if ~isfield(gfundata(lsf), 'cgname')
eval([ 'cgname = {' sprintf(' ''cg%d''',[1:length(cg)]) ' };']);
else
cgname = gfundata(lsf).cgname;
end
if size(cgname,1) > size(cgname,2)
cgname = cgname';
end
else
cgname = [];
cg = [];
end
% Looks for redundant parameters in gfundata(lsf).thetag and probdata.marg
% Eliminates those in gfundata(lsf).thetag
if ~isempty(thetag)
Itoremove = [];
for i = 1:length(thetag)
if ~isempty(strmatch(thetagname(i),margname,'exact'))
Itoremove = [ Itoremove i ];
end
end
if ~isempty(Itoremove)
thetag(Itoremove) = [];
thetagname(Itoremove) = [];
end
end
% Looks for redundant parameters in gfundata(lsf).cg and probdata.marg
% Eliminates those in gfundata(lsf).cg
if ~isempty(cg)
Itoremove = [];
for i = 1:length(cg)
if ~isempty(strmatch(cgname(i),margname,'exact'))
Itoremove = [ Itoremove i ];
end
end
if ~isempty(Itoremove)
cg(Itoremove) = [];
cgname(Itoremove) = [];
end
end
switch lower(gfundata(lsf).evaluator)
case 'basic'
% Identifies r.v.'s, reliability parameters and deterministic parameters in probdata.marg
Ix = find(marg(:,1)>0);
Ithetag = find(marg(:,1)==-1);
Icg = find(marg(:,1)==0);
% Looks for reliability parameters in probdata.marg and transfers them to gfundata(lsf).thetag
if ~isempty(Ithetag)
thetagname = [ thetagname margname(Ithetag) ];
thetag = [ thetag; marg(Ithetag,2) ];
end
% Looks for deterministic parameters in probdata.marg and transfers them to gfundata(lsf).cg
if ~isempty(Icg)
cgname = [ cgname margname(Icg) ];
cg = [ cg; marg(Icg,2) ];
end
margname = margname(Ix);
marg = marg(Ix,:);
correlation = correlation(Ix,Ix);
if isfield(gfundata(lsf), 'dgdq')
gfundata(lsf).dgdq = gfundata(lsf).dgdq(Ix);
end
otherwise
if ~isempty(femodel)
data = femodel.data;
dataname = femodel.dataname;
if size(dataname,1) > size(dataname,2)
dataname = dataname';
end
[data,I] = sortrows(data,2);
dataname = dataname(I);
% Looks for redundant parameters in gfundata(lsf).thetag and femodel.data
% Eliminates those in gfundata(lsf).thetag
if ~isempty(thetag)
Itoremove = [];
for i = 1:length(thetag)
if ~isempty(strmatch(thetagname(i),dataname,'exact'))
Itoremove = [ Itoremove i ];
end
end
if ~isempty(Itoremove)
thetag(Itoremove) = [];
thetagname(Itoremove) = [];
end
end
% Looks for redundant parameters in gfundata(lsf).cg and femodel.data
% Eliminates those in gfundata(lsf).cg
if ~isempty(cg)
Itoremove = [];
for i = 1:length(cg)
if ~isempty(strmatch(cgname(i),dataname,'exact'))
Itoremove = [ Itoremove i ];
end
end
if ~isempty(Itoremove)
cg(Itoremove) = [];
cgname(Itoremove) = [];
end
end
% Updates probdata.marg and femodel.data
for i = 1:size(data,1)
% Forces type of variable in probdata.marg according to femodel.data
if ~isnan(data(i,2))
marg(data(i,2),1) = data(i,1);
end
% Assign deterministic values from means of r.v.'s
if isnan(data(i,3))
data(i,3) = marg(data(i,2),2);
end
end
% Identifies r.v.'s, reliability parameters and deterministic parameters in probdata.marg
Ix = find(marg(:,1)>0);
Ithetag = find(marg(:,1)==-1);
Icg = find(marg(:,1)==0);
% Looks for reliability parameters in probdata.marg and transfers them to gfundata(lsf).thetag
if ~isempty(Ithetag)
for i=1:length(Ithetag)
if isempty(strmatch(margname(Ithetag(i)),dataname,'exact'))
thetagname = [ thetagname margname(Ithetag(i)) ];
thetag = [ thetag; marg(Ithetag(i),2) ];
end
end
end
% Looks for deterministic parameters in probdata.marg and transfers them to gfundata(lsf).cg
if ~isempty(Icg)
for i=1:length(Icg)
if isempty(strmatch(margname(Icg(i)),dataname,'exact'))
cgname = [ cgname margname(Icg(i)) ];
cg = [ cg; marg(Icg(i),2) ];
end
end
end
% Identifies r.v.'s, reliability parameters and deterministic parameters in femodel.data
Ifex = find(data(:,1)>0);
Ifethetag = find(data(:,1)==-1);
Ifecg = find(data(:,1)==0);
% Looks for reliability parameters in femodel.data and transfers them to gfundata(lsf).thetag
% Sets Ithetag1, Ithetag2
if ~isempty(Ifethetag)
if isempty(thetag)
Ithetag1 = [];
if size(data,2)>3, thetagpara1 = []; end
if size(data,2)>4, thetagpara2 = []; end
else
Ithetag1 = 1:length(thetag);
if size(data,2)>3, thetagpara1 = nan*ones(length(thetag),1); end
if size(data,2)>4, thetagpara2 = nan*ones(length(thetag),1); end
end
thetagname = [ thetagname dataname(Ifethetag) ];
thetag = [ thetag; data(Ifethetag,3) ];
Ithetag2 = (length(Ithetag1)+1):(length(Ithetag1)+length(Ifethetag));
if size(data,2)>3, thetagpara1 = [ thetagpara1; data(Ifethetag,4) ]; end
if size(data,2)>4, thetagpara2 = [ thetagpara2; data(Ifethetag,5) ]; end
else
if isempty(thetag)
Ithetag1 = [];
if size(data,2)>3, thetagpara1 = []; end
else
Ithetag1 = 1:length(thetag);
if size(data,2)>3, thetagpara1 = nan*ones(length(thetag),1); end
end
Ithetag2 = [];
if size(data,2)>4, thetagpara2 = []; end
end
% Looks for deterministic parameters in femodel.data and transfer them into gfundata(lsf).cg
% Sets Icg1, Icg2
if ~isempty(Ifecg)
if isempty(cg)
Icg1 = [];
if size(data,2)>3, cgpara1 = []; end
if size(data,2)>4, cgpara2 = []; end
else
Icg1 = 1:length(cg);
if size(data,2)>3, cgpara1 = nan*ones(length(cg),1); end
if size(data,2)>4, cgpara2 = nan*ones(length(cg),1); end
end
cgname = [ cgname dataname(Ifecg) ];
cg = [ cg; data(Ifecg,3) ];
Icg2 = (length(Icg1)+1):(length(Icg1)+length(Ifecg));
if size(data,2)>3, cgpara1 = [ cgpara1; data(Ifecg,4) ]; end
if size(data,2)>4, cgpara2 = [ cgpara2; data(Ifecg,5) ]; end
else
if isempty(cg)
Icg1 = [];
if size(data,2)>3, cgpara1 = []; end
else
Icg1 = 1:length(cg);
if size(data,2)>3, cgpara1 = nan*ones(length(cg),1); end
end
Icg2 = [];
if size(data,2)>4, cgpara2 = []; end
end
Ifexinmarg = data(Ifex,2);
Inonfexinmarg = (1:size(marg,1))';
Inonfexinmarg([Ithetag; Icg; Ifexinmarg]) = [];
Ix1 = 1:length(Inonfexinmarg);
Ix2 = (length(Inonfexinmarg)+1):(length(Inonfexinmarg)+length(Ifexinmarg));
if size(data,2)>3, xpara1 = [ nan*ones(length(Ix1),1); data(Ifex,4) ]; end
if size(data,2)>4, xpara2 = [ nan*ones(length(Ix1),1); data(Ifex,5) ]; end
margname = margname([Inonfexinmarg; Ifexinmarg]);
marg = marg([Inonfexinmarg; Ifexinmarg],:);
correlation = correlation([Inonfexinmarg; Ifexinmarg],[Inonfexinmarg; Ifexinmarg]);
end % if ~isempty(femodel)
end % switch lower(gfundata(lsf).evaluator)
probdata.name = margname;
probdata.marg = marg;
probdata.correlation = correlation;
switch lower(gfundata(lsf).evaluator)
case 'basic'
otherwise
if ~isempty(femodel)
probdata.Ix1 = Ix1;
probdata.Ix2 = Ix2;
if size(data,2)>3, probdata.xpara1 = xpara1; end
if size(data,2)>4, probdata.xpara2 = xpara2; end
end % if ~isempty(femodel)
end
if isempty(thetag)
if isfield(gfundata(lsf),'thetag')
gfundata = rmfield(gfundata(lsf),{'thetag' 'thetagname'});
end
else
gfundata(lsf).thetagname = thetagname;
gfundata(lsf).thetag = thetag;
switch lower(gfundata(lsf).evaluator)
case 'basic'
otherwise
if ~isempty(femodel)
gfundata(lsf).Ithetag1 = Ithetag1;
gfundata(lsf).Ithetag2 = Ithetag2;
if size(data,2)>3, gfundata(lsf).thetagpara1 = thetagpara1; end
if size(data,2)>4, gfundata(lsf).thetagpara2 = thetagpara2; end
end % if ~isempty(femodel)
end
end
if isempty(cg)
if isfield(gfundata(lsf),'cg')
gfundata = rmfield(gfundata(lsf),{'cg' 'cgname'});
end
else
gfundata(lsf).cgname = cgname;
gfundata(lsf).cg = cg;
switch lower(gfundata(lsf).evaluator)
case 'basic'
otherwise
if ~isempty(femodel)
gfundata(lsf).Icg1 = Icg1;
gfundata(lsf).Icg2 = Icg2;
if size(data,2)>3, gfundata(lsf).cgpara1 = cgpara1; end
if size(data,2)>4, gfundata(lsf).cgpara2 = cgpara2; end
end % if ~isempty(femodel)
end
end
% Error check,
% thetaf sensitivity calculation is not implemented for some dsitribution function
% filters them out and throw an error message
if probdata.flag_sens == 1
for i = 1:length(probdata.marg(:,1))
type = probdata.marg(i,1);
p4 = probdata.marg(i,8);
% for these distribution types the sensitivities w.r.t. means, standard deviations, parameters and correlation coefficients
% is not implemented
if any(type == [20, 25, 30, 31])
error(['For random variable number:',num2str(i), ' distribution type (20,30,31) the sensitivity calculation w.r.t. means, standard deviations, parameters and correlation coefficients is not yet implemented!'])
end
if all(type ~= [7, 51]) && not(p4 == 0 || isnan(p4))
error(['For powered distribution, random variable number:',num2str(i), ', the sensitivity calculation w.r.t. means, standard deviations, parameters and correlation coefficients is not yet implemented!'])
end
end
end
% Error check,
% Nataf transformation is not implemented for some dsitribution function
% filters them out and throw an error message
for i = 1:length(probdata.marg(:,1))
type = probdata.marg(i,1);
p4 = probdata.marg(i,8);
corr_i = probdata.correlation(i,:);
corr_i(i) = [];
% check whether the random variable is correlated with some other
if any(corr_i ~=0)
% for these distribution types the Nataf transformation is not implemented
if any(type == [20, 25, 30])
error(['For random variable number: ',num2str(i), ' (has distribution type: ', num2str(type) ,') the Nataf transformation is not yet implemented!'])
end
% powered distributions
if all(type ~= [7, 51]) && not(p4 == 0 || isnan(p4) || p4 == 1)
error(['For powered distribution, random variable number: ',num2str(i), ', the Nataf transformation is not yet implemented!'])
end
end
end
analysisopt.already_updated = 1;