-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2-results.py
178 lines (126 loc) · 4.98 KB
/
2-results.py
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
#!/usr/bin/env python
# coding: utf-8
# # Apply cross validation
# In[1]:
import os
import numpy as np
import pandas as pd
from sklearn.model_selection import GridSearchCV
from sklearn.model_selection import StratifiedKFold
from sklearn.dummy import DummyClassifier
from geone.img import readImageGslib, readPointSetGslib
from geone.deesseinterface import DeesseClassifier
from geone.imgplot import drawImage2D
from mpstool.cv_metrics import brier_score, zero_one_score, balanced_linear_score, SkillScore
# In[2]:
DATA_DIR = 'data_roussillon/'
SAMPLES_DIR = DATA_DIR
OUTPUT_DIR = 'output/'
COLOR_SCHEME_BINARY = [
[x/255 for x in [166,206,227]],
[x/255 for x in [31,120,180]],
]
# In[3]:
# Stratified 5-fold cross-validation with randomly shuffled data
cv = StratifiedKFold(n_splits=5,
shuffle=True,
random_state=20191201,
)
scoring = {
'brier':brier_score,
'skill_brier':SkillScore(DummyClassifier(strategy='prior'), 0, brier_score),
}
# ### Training image selection
# ## Roussillon
# In[4]:
ti_true = readImageGslib(DATA_DIR+'trueTI.gslib')
mask = readImageGslib(DATA_DIR+'mask.gslib')
trend = readImageGslib(DATA_DIR+'trend.gslib')
im_angle = readImageGslib(DATA_DIR+'orientation.gslib')
# In[5]:
nx, ny, nz = mask.nx, mask.ny, mask.nz # number of cells
sx, sy, sz = mask.sx, mask.sy, mask.sz # cell unit
ox, oy, oz = mask.ox, mask.oy, mask.oz # origin (corner of the "first" grid cell)
deesse_roussillon = DeesseClassifier(
varnames=['X','Y','Z','Facies'],
nx=nx, ny=ny, nz=nz,
sx=sx, sy=sy, sz=sz,
ox=ox, oy=oy, oz=oz,
nv=2, varname=['Facies', 'trend'],
nTI=1, TI=ti_true,
mask=mask.val,
rotationUsage=1, # use rotation without tolerance
rotationAzimuthLocal=True, # rotation according to azimuth: local
rotationAzimuth=im_angle.val[0,:,:,:], # rotation azimuth: map of values
dataImage=trend,
outputVarFlag=[True, False],
distanceType=[0,1],
nneighboringNode=[50,1],
distanceThreshold=[0.05, 0.05],
maxScanFraction=0.5,
npostProcessingPathMax=1,
seed=20191201,
nrealization=40,
nthreads=40,
)
# In[6]:
# fill here
scan_fractions = [0.1, 0.2, 0.4, 0.8]
eps=1e-5
parameter_selector = GridSearchCV(deesse_roussillon,
param_grid=[{'maxScanFraction': scan_fractions,
'nneighboringNode': [[8, 1]],
'distanceThreshold': [[t+eps, 0.1] for t in [2/16, 4/16]]},
{'maxScanFraction': scan_fractions,
'nneighboringNode': [[16, 1]],
'distanceThreshold': [[t+eps, 0.1] for t in [2/16, 3/16, 4/16]]},
{'maxScanFraction': scan_fractions,
'nneighboringNode': [[32, 1]],
'distanceThreshold': [[t+eps, 0.1] for t in [1/16, 2/16, 3/16, 4/16]]},
{'maxScanFraction': scan_fractions,
'nneighboringNode': [[64, 1]],
'distanceThreshold': [[t+eps, 0.1] for t in [1/32, 1/16, 2/16, 3/16, 4/16]]},
],
scoring=scoring,
n_jobs=1,
cv=cv,
refit=False,
verbose=0,
error_score='raise',
return_train_score=False,
)
# In[7]:
try:
results = pd.read_csv('df_roussillon.csv', index_col=0)
except FileNotFoundError:
df = pd.DataFrame(readPointSetGslib(SAMPLES_DIR + 'roussillon_observations_600.gslib').to_dict())
parameter_selector.fit(df[['X','Y','Z']], df['Facies_real00000'])
results = pd.DataFrame(parameter_selector.cv_results_)
results.to_csv('df_roussillon.csv')
# In[8]:
results.head()
# In[9]:
# fill here
scan_fractions = [0.001, 0.002, 0.004, 0.006, 0.008, 0.01, 0.02, 0.04, 0.06, 0.08, 0.1, 0.2, 0.4, 0.6]
eps=1e-5
parameter_selector_dsbc = GridSearchCV(deesse_roussillon,
param_grid={'maxScanFraction': scan_fractions,
'nneighboringNode': [[64, 1], [32, 1], [16,1], [8, 1]],
'distanceThreshold': [[eps, 0.1]]},
scoring=scoring,
n_jobs=1,
cv=cv,
refit=False,
verbose=0,
error_score='raise',
return_train_score=False,
)
# In[ ]:
try:
results_dsbc = pd.read_csv('df_dsbc_roussillon.csv', index_col=0)
except FileNotFoundError:
df = pd.DataFrame(readPointSetGslib(SAMPLES_DIR + 'roussillon_observations_600.gslib').to_dict())
parameter_selector_dsbc.fit(df[['X','Y','Z']], df['Facies_real00000'])
results_dsbc = pd.DataFrame(parameter_selector_dsbc.cv_results_)
results_dsbc.to_csv('df_dsbc_roussillon.csv')
# In[ ]: