forked from seismicreservoirmodeling/SeReM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FaciesClassificationDriver.m
133 lines (118 loc) · 3.54 KB
/
FaciesClassificationDriver.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
%% Facies Classification Driver %%
% In this script we illustrate Bayesian facies classification using
% two assumptions:
% Example 1: Gaussian model
% Example 2: non-parametric model estimated using KDE
% available data
addpath(genpath('../SeReM/'))
load Data/data4.mat
data = [Vp Rho];
ns = size(data,1);
nv = size(data,2);
% domain
v = (3:0.005:5);
r = (2:0.01:2.8);
[V, R] = meshgrid(v,r);
domain = [V(:) R(:)];
%% Gaussian model (2 components)
nf = max(unique(Facies));
fp = zeros(nf,1);
mup = zeros(nf,nv);
sp = zeros(nv,nv,nf);
for k=1:nf
fp(k) = sum(Facies==k)/ns;
mup(k,:) = mean(data(Facies==k,:));
sp(:,:,k) = cov(data(Facies==k,:));
end
% likelihood function
GaussLikeFun = zeros(length(r),length(v),nf);
for k=1:nf
lf = mvnpdf(domain,mup(k,:),sp(:,:,k));
lf = lf/sum(lf);
GaussLikeFun(:,:,k) = reshape(lf,length(r),length(v));
end
% plot likelihood
figure(1)
plot(data(:,1), data(:,2), '.k')
hold on
for k=1:nf
contour(V,R,GaussLikeFun(:,:,k), 'LineWidth', 2);
end
grid on; box on;
xlabel('P-wave velocity (km/s)'); ylabel('Density (g/cm^3)');
% classification
[fmap, fpost] = BayesGaussFaciesClass(data, fp, mup, sp);
% confusion matrix (absolute frequencies)
confmat = ConfusionMatrix(Facies, fmap, nf);
% reconstruction rate
reconstrate = confmat./repmat(sum(confmat,2),1,nf);
% recognition rate
recognrate = confmat./repmat(sum(confmat,1),nf,1);
% estimation index
estimindex = reconstrate-recognrate; %#ok<*NASGU>
% plot results
figure(2)
subplot(141)
plot(Vp, Depth, 'k', 'LineWidth', 2);
xlabel('P-wave velocity (km/s)'); ylabel('Depth (m)');
grid on; box on; set(gca, 'YDir', 'reverse')
subplot(142)
plot(Rho, Depth, 'k', 'LineWidth', 2);
xlabel('Density (g/cm^3)'); set(gca, 'YTickLabel', []);
grid on; box on; set(gca, 'YDir', 'reverse')
subplot(143)
plot(fpost,Depth, 'LineWidth', 2);
xlabel('Facies probability'); set(gca, 'YTickLabel', []); legend('Sand', 'Shale');
grid on; box on; set(gca, 'YDir', 'reverse')
subplot(144)
imagesc([],Depth,fmap);
xlabel('Predicted facies'); set(gca, 'YTickLabel', []);
grid on; box on;
%% Non parametric model (2 components)
% training data
dtrain = data;
ftrain = Facies;
% likelihood function
KDElikefun = zeros(length(r),length(v),nf);
for k=1:nf
lf = ksdensity(data(Facies==k,:),domain, 'Kernel', 'epanechnikov');
lf = lf/sum(lf);
KDElikefun(:,:,k) = reshape(lf,length(r),length(v));
end
% plot likelihood
figure(3)
plot(data(:,1), data(:,2), '.k')
hold on
for k=1:nf
contour(V,R,KDElikefun(:,:,k), 'LineWidth', 2);
end
grid on; box on;
xlabel('P-wave velocity (km/s)'); ylabel('Density (g/cm^3)');
% classification
[fmap, fpost] = BayesKDEFaciesClass(data, dtrain, ftrain, fp, domain);
% confusion matrix (absolute frequencies)
confmat = ConfusionMatrix(Facies, fmap, nf);
% reconstruction rate
reconstrate = confmat./repmat(sum(confmat,2),1,nf);
% recognition rate
recognrate = confmat./repmat(sum(confmat,1),nf,1);
% estimation index
estimindex = reconstrate-recognrate;
% plot results
figure(4)
subplot(141)
plot(Vp, Depth, 'k', 'LineWidth', 2);
xlabel('P-wave velocity (km/s)'); ylabel('Depth (m)');
grid on; box on; set(gca, 'YDir', 'reverse')
subplot(142)
plot(Rho, Depth, 'k', 'LineWidth', 2);
xlabel('Density (g/cm^3)'); set(gca, 'YTickLabel', []);
grid on; box on; set(gca, 'YDir', 'reverse')
subplot(143)
plot(fpost,Depth, 'LineWidth', 2);
xlabel('Facies probability'); set(gca, 'YTickLabel', []); legend('Sand', 'Shale');
grid on; box on; set(gca, 'YDir', 'reverse')
subplot(144)
imagesc([],Depth,fmap);
xlabel('Predicted facies'); set(gca, 'YTickLabel', []);
grid on; box on;