-
Notifications
You must be signed in to change notification settings - Fork 2
/
get_target_distribution_upload.m
executable file
·210 lines (179 loc) · 9.3 KB
/
get_target_distribution_upload.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
function [Tgt_distro_output,Database_afterScaling]=get_target_distribution_upload(Input, s_input, ds_input, data_after_preslection, PerTgt_input_from_main, T1_from_main, max_Scalefactor,GM)
% This function is used to get target distribution
% This code is only used for a test case (only SA and 5-95DS are considered)
% This code can be easily generalized to account for different intensity measures
% The Campbell and Bozorgnia (2008) Ground Motion Model is used in this code for SA.
% The Bommer, Stafford and Alarcón (2009) Ground Motion Model (GMM) is used in this code for Ds595.
% The Baker and Jayaram (2008) Correlation function is used to calculation correlation of SA
% The Bradley (2011) Correlation function is used to calculation correlation between SA and Ds595
% Tgt_distro_output : A structure with parameters that specify output of target distribution
% .TargetMean_plot : Target mean for plot
% .TargetCov_plot : Target Covariance for plot
% .TgtIM_plot : Target intensity vector for plot
% .TargetCov_PD : Target Covariance which is positive definite
% .Max_change1_Corr : Maximum changes on correlation matrix due to nearest positive definite matrix algorithm applied
% Database_afterScaling : A structure with parameters that specify output of database after scaling
% .GM_plot : Database after scaling for plot
% .GMID : Record ID corresponding to database after preselection on limitation of scaling
% .GMMR : Magnitude and distance corresponding to database after preselection on limitation of scaling
% .SF : Scale factor corresponding to database after preselection on limitation of scaling
% Inputs
Mmagnitude = Input.Mmagnitude; % Magnitude
Rrupture = Input.Rrupture; % Distance (km)
Rjb = Input.Rrupture; % Assumed same for example
% Inputs for ground motion prediction equation (right lateral strike slip)
deltainput = Input.deltainput; % Average dip of the rupture place (degree)
lambdainput = Input.lambdainput; % Rake angle (degree)
Vs30input = Input.Vs30input; % Shear wave velocity averaged over top 30 m (m/s)
Zvsinput = Input.Zvsinput; % Depth to the 2.5 km/s shear-wave velocity horizon (km)
arbinput = Input.arbinput; % 1 for arbitrary component sigma, 0 for average component sigma
Ztor = Input.Ztor; % Depth to the top of coseismic rupture (km)
Epsilon = Input.Epsilon; % Epsilon is assumed 2
s = s_input; % Short name of SA
ds = ds_input; % Short name of Ds595
T1 = T1_from_main; % conditional period
PerTgt = PerTgt_input_from_main; % interesting period range
% Input end
% Target IM vector
TgtIM = [PerTgt,100]; % 100 is set here for plotting Ds5-95;
% Identify conditional IM
Index_T1 = find(PerTgt == T1);
% Matrix to save intensity measures' name
IMiNames = cell(1,length(TgtIM));
% Build intensity names vector
for i = 1:length(TgtIM)
if i <= length(PerTgt)
IMiNames(i) = {s};
else
IMiNames(i) = {ds};
end
end
% Matrix to save mean and standard deviation
MeanIM = zeros(1,length(TgtIM));
SdIM = zeros(1,length(TgtIM));
% Calculation of mean and standard deviation on intensity vector
for i = 1:length(TgtIM)
if strcmp(IMiNames(i),'SA') == 1
[MeanIM(i),SdIM(i)] = CampbellBozorgnia_2008_SA (Mmagnitude, PerTgt(i), Rrupture, Rjb, Ztor, deltainput, lambdainput, Vs30input, Zvsinput, arbinput);
else
[MeanIM(i),SdIM(i)] = BSA_09_Ds(Mmagnitude,Rrupture,Vs30input,Ztor,arbinput);
end
end
% Covariance
% Matrix to save rho and unconditional covariance
rho = zeros(length(TgtIM));
Uncondition_Cov = zeros(length(TgtIM));
% Unconditional covariance
for i = 1:length(TgtIM)
for j = 1:length(TgtIM)
if strcmp(IMiNames(i),'SA')==1
if strcmp(IMiNames(j),'Ds595')==1
rho(i,j)=Bradley2011_SA_Ds595_correlation(TgtIM(i));
else
rho(i,j)=Baker_Jayaram_correlation(TgtIM(i),TgtIM(j));
end
else
if strcmp(IMiNames(j),'Ds595')==1
rho(i,j)=1;
else
rho(i,j)=Bradley2011_SA_Ds595_correlation(TgtIM(j));
end
end
Uncondition_Cov(i,j)=rho(i,j)*SdIM(i)*SdIM(j);
end
end
% Matrix to save correlation and Covariance between IMi and IMj
rho_T1 = zeros(length(TgtIM),1);
Cov_T1_other = zeros(length(TgtIM),1);
% Covariance between T1 and other intensity measures
for i = 1:length(TgtIM)
if strcmp(IMiNames(i),'SA') == 1
rho_T1(i) = Baker_Jayaram_correlation(PerTgt(i),T1);
else
rho_T1(i) = Bradley2011_SA_Ds595_correlation(T1);
end
Cov_T1_other(i,:) = rho_T1(i)*SdIM(i)*SdIM(TgtIM == T1);
end
Cov_T1_other_save = Cov_T1_other*(1/SdIM(TgtIM == T1)^2)*(Cov_T1_other)';
% Conditional correlation matrix
% Parameters used in covariance modify
TgtIM_PD_modify = TgtIM;
rho_PD_modify = rho;
rho_T1_PD_modify = rho_T1;
SdIM_PD_modify = SdIM;
% Delete conditional IM content
TgtIM_PD_modify(Index_T1) = [];
rho_PD_modify(Index_T1,:) = [];
rho_PD_modify(:,Index_T1) = [];
rho_T1_PD_modify(Index_T1) = [];
SdIM_PD_modify(Index_T1) = [];
% Matrix to save
corr_codition = zeros(length(TgtIM_PD_modify));
for i = 1:length(TgtIM_PD_modify)
for k = 1:length(TgtIM_PD_modify)
corr_codition(i,k) = (rho_PD_modify(i,k) - rho_T1_PD_modify(i)*rho_T1_PD_modify(k))/(sqrt(1 - rho_T1_PD_modify(i)^2)*sqrt(1 - rho_T1_PD_modify(k)^2));
end
end
[~,p] = chol(corr_codition);
if p ~= 0
b = ones(length(rho_PD_modify(1,:)),1); % Initialize parameters for function call
tau = 1.0e-2; % Initialize parameters for function call
tol = 1.0e-2; % Initialize parameters for function call
% Identify the nearest positive definite correlation matrix
corr_codition_modify = nearestCorrelationMatrix(corr_codition, b, tau, tol);
% Matrix used to save covariance obtained with and without PD modifying correlation matrix
TargetCov = zeros(length(TgtIM_PD_modify));
TargetCov_unchanged = zeros(length(TgtIM_PD_modify));
for i = 1:length(TgtIM_PD_modify)
for k = 1:length(TgtIM_PD_modify)
TargetCov(i,k) = (sqrt(1 - rho_T1_PD_modify(i)^2)*sqrt(1 - rho_T1_PD_modify(k)^2))*(SdIM_PD_modify(i)*SdIM_PD_modify(k))*corr_codition_modify(i,k);
TargetCov_unchanged(i,k) = (sqrt(1 - rho_T1_PD_modify(i)^2)*sqrt(1 - rho_T1_PD_modify(k)^2))*(SdIM_PD_modify(i)*SdIM_PD_modify(k))*corr_codition(i,k);
end
end
Tgt_distro_output.Max_change1_Corr = max(abs(TargetCov-TargetCov_unchanged));
TargetCov_PDmodify = TargetCov;
% set covariance zero at IMj
TargetCov_PDmodify = [TargetCov_PDmodify(1:Index_T1-1,:);zeros(1,length(TargetCov));TargetCov_PDmodify(Index_T1:end,:)];
TargetCov_PDmodify = [TargetCov_PDmodify(:,1:Index_T1-1),zeros(length(TargetCov)+1,1),TargetCov_PDmodify(:,Index_T1:end)];
% Target Covariance obtained based Eq 4 shown in the article which is equal to TargetCov_unchanged used here.
TargetCov_Eq_4 = Uncondition_Cov - Cov_T1_other_save;
else
TargetCov_Eq_4 = Uncondition_Cov - Cov_T1_other_save;
TargetCov_PDmodify = TargetCov_Eq_4;
Tgt_distro_output.Max_change1_Corr = 0;
end
% Matrix to save target mean
TargetMean = zeros(1,length(TgtIM));
% Conditional mean
for i = 1:length(TgtIM)
TargetMean(i) = log(MeanIM(i))+rho_T1(i)*Epsilon*SdIM(i);
end
% Save the location of conditional intensity in the intensity measure vector
lnSa1 = TargetMean(PerTgt == T1);
% Target distribution obtained
% Matrix to save database after scaling
database_SA_afterScaling = zeros([length(data_after_preslection.SA(:,1)) length(PerTgt)]);
% Matrix to save scale factor
Scalefactor = zeros(1,length(data_after_preslection.SA(:,1)));
% Database after scaling
for i = 1:length(data_after_preslection.SA(:,1))
Scalefactor(i) = exp(lnSa1)/data_after_preslection.SA(i,Index_T1);
database_SA_afterScaling(i,:) = log(data_after_preslection.SA(i,:)*Scalefactor(i));% log database (SA)
end
% Remove records due to maximum scale factor limitation (ID MR and scale factor matrix modified)
remove_ID_data = find(Scalefactor >= max_Scalefactor);
Scalefactor(remove_ID_data) = [];
database_afterScaling = [database_SA_afterScaling,log(data_after_preslection.Ds)]; % log database (DS) and scale factor for duration is one
database_afterScaling(remove_ID_data,:) = [];
GM.GMID_after_preselection(remove_ID_data) = [];
GM.MR_after_preselection(remove_ID_data,:) = [];
% Save scale factor, record ID and magnitude-distance matrix for output
Database_afterScaling.SF = Scalefactor;
Database_afterScaling.GMID = GM.GMID_after_preselection;
Database_afterScaling.GMMR = GM.MR_after_preselection;
% Save matrixes for plotting or selecting GMs before deleting values corresponding to conditional intensity measure
Database_afterScaling.GM_plot = database_afterScaling;
Tgt_distro_output.TgtIM_plot = TgtIM;
Tgt_distro_output.TargetMean_plot = TargetMean;
Tgt_distro_output.TargetCov_plot = TargetCov_Eq_4;
Tgt_distro_output.TargetCov_PD = TargetCov_PDmodify;