-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinvert_bodyforce.m
executable file
·255 lines (172 loc) · 6.57 KB
/
invert_bodyforce.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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Input Section
%specify range of beta values (weights on minimizing body forces)
betas = [40 45 50];
%compute uncertainties? set ucertainty = true or false
%computing uncertainties is slow
uncertainty = false;
%number of realizations of strain rate for each beta value
num = 500;
%relative weight on fitting creep rate data (creeping faults)
Wcreep = 1;
% optional two-step minimization of strain rates below threshold value
% set twostep = true or false
% relative weight (gamma) on minimizing strain rates below strain_threshold
%(micro-strain per year)
twostep = false;
gamma = 400;
strain_threshold = 9e-3; %micro-strain per year
%x and y boundaries for strain rate minimization (strain rates not
%minimized outside of these boundaries)
minimize_xbound = [-600 1000];
minimize_ybound = [-800 1000];
%name of mat file for saving inversion results
savename = 'test_inversion';
%% No need to modify below
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% find cells with data
ind = ~isnan(Ve_centroids);
G = [Ge_x(ind,:) Ge_y(ind,:);Gn_x(ind,:) Gn_y(ind,:)];
d = [Ve_centroids(ind);Vn_centroids(ind)];
Sige = Sige_centroids(ind);
Sign = Sign_centroids(ind);
%build creep matrix
if ~isempty(PatchEnds)
build_creepG
end
%% regularization weights
%build_triangle_weights -- L, to penalize magnitude of body forces
I = eye(size(Ge_x,2));
%I = diag(w_tri);
%I = con_tri.*repmat(w_tri,1,size(con_tri,2));
L = [I 0*I;0*I I];
if ~isempty(PatchEnds)
L = [L zeros(size(L,1),length(PatchCreepRates))];
Lcreep = [zeros(length(PatchCreepRates),size(G,2)) eye(length(PatchCreepRates))];
end
sig = [Sige;Sign];
%matrix for computing strain rates
if ~isempty(PatchEnds)
GExx = [GExx_x GExx_y GExx_creep];
GExy = [GExy_x GExy_y GExy_creep];
GEyy = [GEyy_x GEyy_y GEyy_creep];
else
GExx = [GExx_x GExx_y];
GExy = [GExy_x GExy_y];
GEyy = [GEyy_x GEyy_y];
end
%velocities
if ~isempty(PatchEnds)
GVe = [Ge_x Ge_y Geast_creep];
GVn = [Gn_x Gn_y Gnorth_creep];
else
GVe = [Ge_x Ge_y];
GVn = [Gn_x Gn_y];
end
%build realizations
Exx_realizations = [];
Exy_realizations = [];
Eyy_realizations = [];
Ve_realizations = [];
Vn_realizations = [];
if ~isempty(PatchEnds)
GG = [G Gcreep([ind;ind],:)];
else
GG = G;
end
GG = GG./repmat(sig,1,size(GG,2));
dd = d./sig;
for k=1:length(betas)
disp(['Beginning ' num2str(k) ' of ' num2str(length(betas)) ' inversions'])
beta = betas(k);
if ~isempty(PatchEnds)
GL = sparse([GG;[beta*L;Wcreep*Lcreep]]);
d0 = sparse([dd;zeros(size(L,1),1);Wcreep*PatchCreepRates]);
else
GL = sparse([GG;beta*L]);
d0 = sparse([dd;zeros(size(L,1),1)]);
end
tic; mhat0 = GL\d0; T = toc;
disp(['Completed first inversion step in ' num2str(T) ' seconds.']);
if twostep
Exxs = GExx*mhat0;
Exys = GExy*mhat0;
Eyys = GEyy*mhat0;
max_shear = sqrt((Exxs-Eyys).^2 + Exys.^2);
ind_boundaries = tri_centroids(:,1)>minimize_xbound(1) & tri_centroids(:,1)<minimize_xbound(2) & tri_centroids(:,2)>minimize_ybound(1) & tri_centroids(:,2)<minimize_ybound(2);
ind_threshold = (max_shear < strain_threshold) & ind_boundaries;
disp(['Minimizing strain rates in ' num2str(sum(ind_threshold)/length(ind_threshold)*100) ' % of cells.'])
L_iter = [GExx(ind_threshold,:);GExy(ind_threshold,:);GEyy(ind_threshold,:)];
GL_iterate = [GL; gamma*L_iter] ;
d0_iterate = [d0; zeros(3*sum(ind_threshold),1)];
tic; mhat = lsqr(GL_iterate,d0_iterate,[],1500,[],[],mhat0); T = toc;
disp(['Completed second (minimization) inversion step in ' num2str(T) ' seconds.']);
else
mhat = mhat0; %use first step as solution
end
%predicted velocities using mhat computed above
if ~isempty(PatchEnds)
dhat = [G Gcreep([ind;ind],:)]*mhat;
else
dhat = G*mhat;
end
%propogate errors to strain rate
if uncertainty
if twostep
if ~isempty(PatchEnds)
Ginv = (GG'*GG+beta^2*L'*L + Wcreep^2*Lcreep'*Lcreep + gamma*L_iter'*L_iter);
else
Ginv = (GG'*GG+beta^2*L'*L + gamma*L_iter'*L_iter);
end
else
if ~isempty(PatchEnds)
Ginv = (GG'*GG+beta^2*L'*L + Wcreep^2*Lcreep'*Lcreep);
else
Ginv = (GG'*GG+beta^2*L'*L);
end
end
Gsharp = Ginv\GG';
%error propagation for strain rates
Cov_bf = Gsharp*Gsharp'; %note, data covariance is excluded because Gw is weighted
Cov_exx = GExx*Cov_bf*GExx';
Cov_exy = GExy*Cov_bf*GExy';
Cov_eyy = GEyy*Cov_bf*GEyy';
%error propagation for velocities
Cov_Ve = GVe*Cov_bf*GVe';
Cov_Vn = GVn*Cov_bf*GVn';
end
%computed strain rates and velocities
Exxs = GExx*mhat;
Exys = GExy*mhat;
Eyys = GEyy*mhat;
Ves = GVe*mhat;
Vns = GVn*mhat;
Mhats(:,k) = mhat; %store all solutions
%chi-squared
chi_2(k) = sum((d./sig - dhat./sig).^2)/(length(d))
if uncertainty
%draw realizations from multivariate Gaussian distribution
tic
J = size(Cov_exx,1);
noise = mvnrnd(zeros(1,J),full(Cov_exx),num);
Exx_realizations = [Exx_realizations repmat(Exxs,1,num) + noise'];
noise = mvnrnd(zeros(1,J),full(Cov_exy),num);
Exy_realizations = [Exy_realizations repmat(Exys,1,num) + noise'];
noise = mvnrnd(zeros(1,J),full(Cov_eyy),num);
Eyy_realizations = [Eyy_realizations repmat(Eyys,1,num) + noise'];
noise = mvnrnd(zeros(1,J),full(Cov_Ve),num);
Ve_realizations = [Ve_realizations repmat(Ves,1,num) + noise'];
noise = mvnrnd(zeros(1,J),full(Cov_Vn),num);
Vn_realizations = [Vn_realizations repmat(Vns,1,num) + noise'];
T = toc;
disp(['Completed ' num2str(num) ' realizations in ' num2str(T) ' seconds.']);
else
Exx_realizations = [Exx_realizations Exxs];
Exy_realizations = [Exy_realizations Exys];
Eyy_realizations = [Eyy_realizations Eyys];
Ve_realizations = [Ve_realizations Ves];
Vn_realizations = [Vn_realizations Vns];
end
save(savename,'chi_2','Mhats','Exx_realizations','Exy_realizations','Eyy_realizations','Ve_realizations','Vn_realizations')
disp(['Completed ' num2str(k) ' of ' num2str(length(betas)) ' inversions'])
end