To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit 16f9e927 authored by Feliks Kiszkurno's avatar Feliks Kiszkurno
Browse files

Added normalization, normalized classes, AdaBoost, KNN.

parent c62bd5c2
File mode changed from 100644 to 100755
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/data" /> <excludeFolder url="file://$MODULE_DIR$/data" />
</content> </content>
<orderEntry type="jdk" jdkName="Python 3.7 (MasterEnv)" jdkType="Python SDK" /> <orderEntry type="jdk" jdkName="Python 3.7 (SlopeStability)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
<component name="PyDocumentationSettings"> <component name="PyDocumentationSettings">
......
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (MasterEnv)" project-jdk-type="Python SDK" /> <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (SlopeStability)" project-jdk-type="Python SDK" />
</project> </project>
\ No newline at end of file
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
...@@ -6,25 +6,17 @@ Created on Fri Jan 8 10:29:00 2021 ...@@ -6,25 +6,17 @@ Created on Fri Jan 8 10:29:00 2021
@author: Feliks Kiszkurno @author: Feliks Kiszkurno
""" """
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import slopestabilitytools
import slopestabilitytools.datamanagement import slopestabilitytools.datamanagement
import slopestabilityML import slopestabilityML
import slostabcreatedata import slostabcreatedata
import numpy as np
import settings
import pygimli as pg settings.init()
import pygimli.meshtools as mt
import pygimli.physics.ert as ert
# Config # Config
create_new_data = False create_new_data = True
create_new_data_only = False create_new_data_only = True
# Prepare folder structure for output
is_success = slopestabilitytools.folder_structure.create_folder_structure()
if not create_new_data: if not create_new_data:
...@@ -32,46 +24,69 @@ if not create_new_data: ...@@ -32,46 +24,69 @@ if not create_new_data:
else: else:
# Prepare folder structure for output
is_success = slopestabilitytools.folder_structure.create_folder_structure()
# TODO Put this part into a function # TODO Put this part into a function
# Settings # Settings
number_of_tests = 50 number_of_tests = 5
rho_spread_factor = 1.5 rho_spread_factor = 1.5
rho_max = 20 rho_max = 20
layers_min = 1 layers_min = 1
layers_max = 2 layers_max = 2
min_depth = 4 min_depth = 4
max_depth = 10 max_depth = 8
# Generate parameters for tests # Generate parameters for tests
tests_horizontal = slopestabilitytools.model_params(number_of_tests, # tests_horizontal = slopestabilitytools.model_params(number_of_tests,
rho_spread_factor, rho_max, # rho_spread_factor, rho_max,
layers_min, layers_max, # layers_min, layers_max,
min_depth, max_depth) # min_depth, max_depth)
# tests_horizontal = {'hor_1': {'layer_n': 1, 'rho_values': [[1, 5], [2, 15]], 'layers_pos': np.array([-5])}, tests_horizontal = {'hor_01': {'layer_n': 1, 'rho_values': [[1, 5], [2, 15]], 'layers_pos': np.array([-5])},
# 'hor_2': {'layer_n': 1, 'rho_values': [[1, 5], [2, 50]], 'layers_pos': np.array([-5])}, 'hor_02': {'layer_n': 1, 'rho_values': [[1, 5], [2, 50]], 'layers_pos': np.array([-5])},
# 'hor_3': {'layer_n': 1, 'rho_values': [[1, 15], [2, 20]], 'layers_pos': np.array([-8])}, 'hor_03': {'layer_n': 1, 'rho_values': [[1, 15], [2, 20]], 'layers_pos': np.array([-8])},
# 'hor_4': {'layer_n': 1, 'rho_values': [[1, 5], [2, 10]], 'layers_pos': np.array([-3])}, 'hor_04': {'layer_n': 1, 'rho_values': [[1, 5], [2, 10]], 'layers_pos': np.array([-3])},
# 'hor_5': {'layer_n': 1, 'rho_values': [[1, 5], [2, 25]], 'layers_pos': np.array([-3])}} 'hor_05': {'layer_n': 1, 'rho_values': [[1, 5], [2, 25]], 'layers_pos': np.array([-3])},
'hor_06': {'layer_n': 1, 'rho_values': [[1, 2], [2, 10]], 'layers_pos': np.array([-4])},
'hor_07': {'layer_n': 1, 'rho_values': [[1, 10], [2, 20]], 'layers_pos': np.array([-6])},
'hor_08': {'layer_n': 1, 'rho_values': [[1, 5], [2, 25]], 'layers_pos': np.array([-3])},
'hor_09': {'layer_n': 1, 'rho_values': [[1, 3], [2, 25]], 'layers_pos': np.array([-3])},
'hor_10': {'layer_n': 1, 'rho_values': [[1, 5], [2, 25]], 'layers_pos': np.array([-7])},
'hor_11': {'layer_n': 1, 'rho_values': [[1, 10], [2, 12]], 'layers_pos': np.array([-4])},
'hor_12': {'layer_n': 1, 'rho_values': [[1, 15], [2, 50]], 'layers_pos': np.array([-5])},
'hor_13': {'layer_n': 2, 'rho_values': [[1, 3], [2, 5], [3, 15]],
'layers_pos': np.array([-3, -6])},
'hor_14': {'layer_n': 2, 'rho_values': [[1, 2], [2, 4], [3, 8]],
'layers_pos': np.array([-4, -8])},
'hor_15': {'layer_n': 1, 'rho_values': [[1, 4], [2, 15], [3, 25]],
'layers_pos': np.array([-4, -8])},
'hor_16': {'layer_n': 1, 'rho_values': [[1, 5], [2, 20], [3, 50]],
'layers_pos': np.array([-4, -8])}
}
# tests_horizontal = {'hor_9': {'layer_n': 1, 'rho_values': [[1, 3], [2, 25]], 'layers_pos': np.array([-3])},}
# Create models and invert them # Create models and invert them
test_results = {} test_results = {}
for test_name in tests_horizontal.keys(): for test_name in tests_horizontal.keys():
test_result_curr, test_rho_max, test_rho_min = slostabcreatedata.create_data(test_name, tests_horizontal[test_name], max_depth) test_result_curr, test_rho_max, test_rho_min = slostabcreatedata.create_data(test_name,
tests_horizontal[test_name],
max_depth)
test_results.update({test_name: test_result_curr}) test_results.update({test_name: test_result_curr})
del test_result_curr del test_result_curr
# Plot and save figures # Plot and save figures
slopestabilitytools.plot_and_save(test_name, test_results[test_name], 'Test: ' + test_name, test_rho_max, test_rho_min) slopestabilitytools.plot_and_save(test_name, test_results[test_name], 'Test: ' + test_name, test_rho_max,
test_rho_min)
if not create_new_data_only: if not create_new_data_only:
print('Running ML stuff...')
#for test_name in test_results.keys():
#slopestabilitytools.plot_and_save(test_name, test_results[test_name], 'Test: ' + test_name)
print('Running ML stuff...')
ml_results = slopestabilityML.run_all_tests(test_results) ml_results = slopestabilityML.run_all_tests(test_results)
# svm_accuracy_score, svm_accuracy_labels = slopestabilityML.svm_run(test_results)
elif create_new_data_only: elif create_new_data_only:
print('Done') print('Done')
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Jan 8 10:29:00 2021
@author: felikskrno
"""
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import slopestabilitytools
import slopestabilityML
import slostabcreatedata
import pygimli as pg
import pygimli.meshtools as mt
import pygimli.physics.ert as ert
is_success = slopestabilitytools.folder_structure.create_folder_structure()
number_of_tests = 10
rho_spread_factor = 1.5
rho_max = 150
layers_min = 1
layers_max = 3
min_depth = 1
max_depth = 10
tests_horizontal = slopestabilitytools.model_params(number_of_tests,
rho_spread_factor, rho_max,
layers_min, layers_max,
min_depth, max_depth)
world_boundary_v = [-200, 0] # [right, left border] relatively to the middle
world_boundary_h = [200, -100] # [top, bottom border]
test_results = {}
test_results_grid = {}
test_input = {}
test_name = 'hor_1'
#tests_horizontal['layers_pos'][test_name] = [-5]
# INPUT MODEL - SUBSURFACE START #
world = mt.createWorld(start=world_boundary_v, end=world_boundary_h, layers=tests_horizontal['layers_pos'][test_name])#,
#marker=np.linspace(1, tests_horizontal['layer_n']['hor_1'],
# tests_horizontal['layer_n']['hor_1']))
geometry = world # +block
measurement_scheme = ert.createERTData(elecs=np.linspace(start=-45, stop=45, num=91), schemeName='dd')
for electrode in measurement_scheme.sensors():
geometry.createNode(electrode)
geometry.createNode(electrode - [0, 0.1]) # What does it do?
mesh = mt.createMesh(geometry, quality=34) # , area=2)#
resistivity_map = tests_horizontal['rho_values'][test_name] # [0]
#resistivity_map[0] = [1, 50.0]
#resistivity_map[1] = [2, 150.0]
input_model = pg.solver.parseMapToCellArray(resistivity_map, mesh) # rename to input_mesh
# INPUT MODEL - SUBSURFACE MODEL END ###
# SIMULATE ERT MEASUREMENT - START ###
mesh_pd = [] # add new mesh
data = ert.simulate(mesh, scheme=measurement_scheme, res=resistivity_map, noiseLevel=1, noiseAbs=1e-6, seed=1337)
data.remove(data['rhoa'] < 0)
# SIMULATE ERT MEASUREMENT - END ###
ert_manager = ert.ERTManager(sr=False, useBert=True, verbose=True, debug=False)
# RUN INVERSION #
k0 = pg.physics.ert.createGeometricFactors(data)
model_inverted = ert_manager.invert(data=data, lam=20, paraDX=0.25, paraMaxCellSize=5, paraDepth=10, quality=34,
zPower=0.4)
result = ert_manager.inv.model
result_array = result.array()
input_model2 = pg.interpolate(srcMesh=mesh, inVec=input_model, destPos=ert_manager.paraDomain.cellCenters())
input_model2_array = input_model2.array()
experiment_results = pd.DataFrame(data={'X': ert_manager.paraDomain.cellCenters().array()[:, 0],
'Y': ert_manager.paraDomain.cellCenters().array()[:, 1],
'Z': ert_manager.paraDomain.cellCenters().array()[:, 2],
'INM': input_model2_array,
'RES': result_array})
test_results[test_name] = experiment_results
fig, ax = plt.subplots(3)
fig.suptitle(test_name)
pg.show(ert_manager.paraDomain, input_model2, ax=ax[0])
ax[0].set_title("Model on the output mesh")
pg.show(ert_manager.paraDomain, result, ax=ax[1])
ax[1].set_title("Inverted")
pg.show(ert_manager.paraDomain, result - input_model2, ax=ax[2])
ax[2].set_title("Diff")
fig.savefig('results/figs/hor_{}_results.eps'.format(test_name))
fig.savefig('results/figs/hor_{}_results.png'.format(test_name))
fig_input, ax_input = plt.subplots(1)
pg.show(mesh, input_model, ax=ax_input)
ax_input.set_title('1 Geometry of the model')
fig_input.savefig('results/figs/hor_{}_input.eps'.format(test_name))
fig_input.savefig('results/figs/hor_{}_input.png'.format(test_name))
This diff is collapsed.
File mode changed from 100644 to 100755
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 26.03.2021
@author: Feliks Kiszkurno
"""
def init():
global settings
settings = {}
# Normalization and classes
settings['norm_class'] = True # True to use normalized classes, False to use class_ids
settings['norm_class_num'] = 5 # Number of classes for normalized data
settings['norm'] = False # True to use normalized data, False to use raw data
# Include sensitivity
settings['sen'] = False # True - include sensitivity, False - ignore sensitivity
# Paths
settings['results_folder'] = "results"
# Plots
settings['plot_formats'] = ['png']
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 26.03.2021
@author: Feliks Kiszkurno
"""
from .adaboost_run import adaboost_run
\ No newline at end of file
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 26.03.2021
@author: Feliks Kiszkurno
"""
import slopestabilityML.plot_results
import slopestabilityML.split_dataset
import slopestabilityML.run_classi
from sklearn.ensemble import AdaBoostClassifier
def adaboost_run(test_results, random_seed):
test_training, test_prediction = slopestabilityML.split_dataset(test_results.keys(), random_seed)
clf = AdaBoostClassifier(n_estimators=50, random_state=0)
# Train classifier
accuracy_labels, accuracy_score, accuracy_labels_training, accuracy_score_training = \
slopestabilityML.run_classification(test_training, test_prediction, test_results, clf, 'ADA')
# Plot
slopestabilityML.plot_results(accuracy_labels, accuracy_score, 'ADA_prediction')
slopestabilityML.plot_results(accuracy_labels_training, accuracy_score_training, 'ADA_training')
return accuracy_score, accuracy_labels, accuracy_score_training, accuracy_labels_training
File mode changed from 100644 to 100755
...@@ -9,7 +9,7 @@ Created on 19.01.2021 ...@@ -9,7 +9,7 @@ Created on 19.01.2021
from sklearn import ensemble from sklearn import ensemble
import slopestabilityML.plot_results import slopestabilityML.plot_results
import slopestabilityML.split_dataset import slopestabilityML.split_dataset
import slopestabilityML.run_classification import slopestabilityML.run_classi
# TODO: as in svm_run # TODO: as in svm_run
......
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" """
Created on Created on 26.03.2021
@author: @author: Feliks Kiszkurno
""" """
# https://letsfigureout.com/2020/03/08/nearest-neighbor-algorithm-with-python-and-numpy/ # https://letsfigureout.com/2020/03/08/nearest-neighbor-algorithm-with-python-and-numpy/
from .knn_run import knn_run
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment