-
Notifications
You must be signed in to change notification settings - Fork 4
/
gen_dist.m
83 lines (57 loc) · 1.81 KB
/
gen_dist.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
%%% Coded by Song, S. (April 2013)
%%% Generate 2D distributions of source parameters
%%% using the Cholesky factorization
%%% based on 1-point and 2-point statistics
function [rup] = gen_dist(rup)
tic
N = rup.nx*rup.nz;
N1 = (rup.nx1)*(rup.nz1);
str_N = sprintf('=> Number of subfaults (fine grid): %d',N);
disp(str_N), disp(' ')
str_N = sprintf('=> Number of subfaults (coarse grid): %d',N1);
disp(str_N), disp(' ')
[XX ZZ] = meshgrid(rup.lx1{1},rup.lz1{1});
X = single(XX(:));
Z = single(ZZ(:));
Z1 = repmat(Z ,1,N1); clear Z
r.z = (Z1' - Z1); clear Z1
X1 = repmat(X ,1,N1); clear X
r.x = (X1' - X1); clear X1
rho = gen_rho(rup,r); %clear r
Cm = [rho{1}{1} rho{1}{2} rho{1}{3}; ...
rho{1}{2}' rho{2}{2} rho{2}{3}; ...
rho{1}{3}' rho{2}{3}' rho{3}{3}]; %clear rho
t1 = toc;
str_t1 = sprintf('=> Elapsed time for constructing Cm: %10.2f',t1);
disp(str_t1)
%removing negative eigen values for positivity constraints
[eig_v eig_d] = eig(Cm);
rup.eigen = diag(eig_d);
eigen = rup.eigen;
eigen(eigen<0.01) = 0.01;
Cm = eig_v*diag(eigen)*(eig_v)';
t2 = toc;
str_t2 = sprintf('=> Elapsed time for Eigen decomposition: %10.2f',t2-t1);
disp(str_t2)
L = chol(Cm,'lower'); clear Cm
t3 = toc;
str_t3 = sprintf('=> Elapsed time for Cholesky Factorization: %10.2f',t3-t2);
disp(str_t3)
randn('state',rup.seed.seed);
%randn('state',sum(100*clock));
for iter=1:rup.num
s0 = randn(3*N1,1);
s = L*s0; %clear L
slip1 = s(1:N1);
Vr1 = s(N1+1:2*N1);
psv1 = s(2*N1+1:end);
slip1 = reshape(slip1,rup.nz1,rup.nx1);
Vr1 = reshape(Vr1 ,rup.nz1,rup.nx1);
psv1 = reshape(psv1,rup.nz1,rup.nx1);
rup.slip1.dist{iter} = slip1;
rup.Vr1.dist{iter} = Vr1;
rup.psv1.dist{iter} = psv1;
end
t4 = toc;
str_t4 = sprintf('=> Elapsed time for random sampling: %10.2f',t4-t3);
disp(str_t4)