Commit 72d5d27b authored by Marius Kriegerowski's avatar Marius Kriegerowski

preliminary bug fixes

parent bc685a75
......@@ -4,17 +4,19 @@ 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()
......@@ -101,17 +103,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,7 +122,8 @@ 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)
......@@ -135,18 +138,20 @@ class Optimizer(Object):
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