Commit 0007d6f6 authored by Marius Kriegerowski's avatar Marius Kriegerowski

Merge branch 'master' of gitext.gfz-potsdam.de:sec2.1_ml/deeplearning

parents f88c1e68 9a64146e
......@@ -18,3 +18,21 @@ You can dump your examples to TFRecordDatasets to accelerate io operations:
and use the newly created config file to run `--train`
Tests
-----
- basic learning (synthetics, real data)
# TODO: split data -> training, evaluation
- synthetics, layered cake, train with top and bottom layer containing events.
Validate with events within middle layer
- evaluation using 'unknown' velocity model
- test extrapolation with fault plane geometry
- synthetic pretraining
- hyperparameter optimization using skopt
Outlook
-------
- increase z error weight -> improve z estimates
......@@ -68,6 +68,8 @@ class Model(Object):
:param kernel_width: convolution kernel size accross time axis
(Needs some debugging and checking)
TODO:
- cross_channel_kernel
'''
_, n_channels, n_samples, _ = input.shape
......@@ -113,7 +115,7 @@ class Model(Object):
# tf.summary.image('input', features)
for ilayer in range(params.get('n_layers', 3)):
input = self.time_axis_cnn(input, n_filters, 1,
input = self.time_axis_cnn(input, n_filters * (1 + ilayer), 1,
kernel_width=int(kernel_width + ilayer*kernel_width_factor),
name='conv_%s' % ilayer, training=training)
# conv = self.time_axis_cnn(conv, n_filters*2, 1, kernel_width=2, name='conv2',
......
import matplotlib as mpl
mpl.use('PDF')
import os
from .util import delete_if_exists
from skopt import gp_minimize
from skopt import dump as dump_result
from skopt import load as load_result
from skopt.space import Real, Categorical, Integer
from skopt.plots import plot_convergence, plot_objective_2D
# from skopt.plots import plot_convergence, plot_objective_2D
from skopt.plots import plot_convergence, plot_objective
from skopt.plots import plot_objective, plot_evaluations
import matplotlib.pyplot as plt
import logging
from pyrocko.guts import Object, Int, Float, List, Tuple, String
try:
from skopt.plots import plot_histogram
_plot_histogram_error = False
except ImportError as e:
_plot_histogram_error = e
logger.debug(e)
from pyrocko.guts import Object, Int, Float, List, Tuple, String
import logging
logging.debug(e)
logger = logging.getLogger()
......@@ -30,6 +35,12 @@ class Optimizer(Object):
path_out = String.T(default='optimizer-results', help='base path where to store results, plots and logs')
def __init__(self, **kwargs):
'''
TODO:
- optimize kernel heigth (cross_channel_kernel)
'''
super().__init__(**kwargs)
self.model = None
self.result = None
......@@ -101,17 +112,17 @@ class Optimizer(Object):
n_calls=self.n_calls,
x0=self.optimizer_values)
dump_result(self.result, self.fn_result)
# dump_result(self.result, self.fn_result)
self.evaluate_result()
self.plot_results()
def ensure_result(self):
''' Load and set minimizer result.'''
if self.result is None:
if self.fn_result is None:
logger.warn(
'Cannot load results from filename: %s' % self.fn_result)
self.result = load_result(self.fn_result)
else:
logger.warn(
'Cannot load results from filename: %s' % self.fn_result)
def extend_path(self, *path):
'''Prepend `self.path_out` to `path`.'''
......@@ -120,33 +131,41 @@ class Optimizer(Object):
def evaluate_result(self):
self.ensure_result()
best = self.result.space.point_to_dict(self.result.x)
# best = self.result.space.point_to_dict(self.result.x)
best = self.result.x
logger.info('Best parameter set:')
logger.info(best)
logger.info('Best parameter loss:')
logger.info(self.result.fun)
def ensure_directory(self, directory):
if not os.path.exists(directory):
os.makedirs(directory)
def plot_results(self):
'''Produce and save result plots. '''
self.ensure_result()
self.ensure_directory(self.extend_path('plots'))
if _plot_histogram_error:
logger.warn(_plot_histogram_error)
else:
for dim_name in self.optimizer_keys:
fig, ax = plot_histogram(result=self.result, dimension_name=dim_name)
fig.savefig(extend_path('plots/histogram_%s.pdf' % dim_name))
fig, ax = plot_objective(
result=self.result,
dimension_names=self.non_categorical_dimensions)
fig.savefig(extend_path('plots/objectives.pdf'))
fig, ax = plot_evaluations(
result=self.result,
dimension_names=self.non_categorical_dimensions)
fig.savefig(extend_path('plots/evaluations.pdf'))
fig, ax = plot_histogram(result=self.result) #, dimension_name=dim_name)
fig.savefig(self.extend_path('plots/histogram_%s.pdf' % dim_name))
ax = plot_objective(
result=self.result,)
# dimension_names=self.non_categorical_dimensions)
fig = plt.gcf()
fig.savefig(self.extend_path('plots/objectives.pdf'))
ax = plot_evaluations(
result=self.result,)
# dimension_names=self.non_categorical_dimensions)
fig = plt.gcf()
fig.savefig(self.extend_path('plots/evaluations.pdf'))
def log_dir_name(self, params):
'''Helper function to transform `params` into a logging directory
......
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