diff --git a/hyppopy/plugins/hyperopt_settings_plugin.py b/hyppopy/plugins/hyperopt_settings_plugin.py index a188ef6..9aad0ac 100644 --- a/hyppopy/plugins/hyperopt_settings_plugin.py +++ b/hyppopy/plugins/hyperopt_settings_plugin.py @@ -1,103 +1,105 @@ # DKFZ # # # Copyright (c) German Cancer Research Center, # Division of Medical and Biological Informatics. # All rights reserved. # # This software is distributed WITHOUT ANY WARRANTY; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. # # See LICENSE.txt or http://www.mitk.org for details. # # Author: Sven Wanner (s.wanner@dkfz.de) import os import logging import numpy as np from hyppopy.globals import DEBUGLEVEL LOG = logging.getLogger(os.path.basename(__file__)) LOG.setLevel(DEBUGLEVEL) from pprint import pformat try: from hyperopt import hp from yapsy.IPlugin import IPlugin except: LOG.warning("hyperopt package not installed, will ignore this plugin!") print("hyperopt package not installed, will ignore this plugin!") from hyppopy.settingspluginbase import SettingsPluginBase from hyppopy.settingsparticle import SettingsParticle class hyperopt_Settings(SettingsPluginBase, IPlugin): def __init__(self): SettingsPluginBase.__init__(self) LOG.debug("initialized") def convert_parameter(self, input_dict): LOG.debug("convert input parameter\n\n\t{}\n".format(pformat(input_dict))) solution_space = {} for name, content in input_dict.items(): particle = hyperopt_SettingsParticle(name=name) for key, value in content.items(): if key == 'domain': particle.domain = value elif key == 'data': particle.data = value elif key == 'type': particle.dtype = value solution_space[name] = particle.get() return solution_space class hyperopt_SettingsParticle(SettingsParticle): def __init__(self, name=None, domain=None, dtype=None, data=None): SettingsParticle.__init__(self, name, domain, dtype, data) def convert(self): if self.domain == "uniform": if self.dtype == "float" or self.dtype == "double": return hp.uniform(self.name, self.data[0], self.data[1]) elif self.dtype == "int": data = list(np.arange(int(self.data[0]), int(self.data[1]+1))) return hp.choice(self.name, data) else: msg = "cannot convert the type {} in domain {}".format(self.dtype, self.domain) LOG.error(msg) raise LookupError(msg) elif self.domain == "loguniform": if self.dtype == "float" or self.dtype == "double": return hp.loguniform(self.name, self.data[0], self.data[1]) else: msg = "cannot convert the type {} in domain {}".format(self.dtype, self.domain) LOG.error(msg) raise LookupError(msg) elif self.domain == "normal": if self.dtype == "float" or self.dtype == "double": - return hp.normal(self.name, self.data[0], self.data[1]) + mu = (self.data[1] - self.data[0])/2.0 + sigma = mu/3 + return hp.normal(self.name, mu, sigma) else: msg = "cannot convert the type {} in domain {}".format(self.dtype, self.domain) LOG.error(msg) raise LookupError(msg) elif self.domain == "categorical": if self.dtype == 'str': return hp.choice(self.name, self.data) elif self.dtype == 'bool': data = [] for elem in self.data: if elem == "true" or elem == "True" or elem == 1 or elem == "1": data .append(True) elif elem == "false" or elem == "False" or elem == 0 or elem == "0": data .append(False) else: msg = "cannot convert the type {} in domain {}, unknown bool type value".format(self.dtype, self.domain) LOG.error(msg) raise LookupError(msg) return hp.choice(self.name, data) diff --git a/setup.py b/setup.py index feb0e7d..2486574 100644 --- a/setup.py +++ b/setup.py @@ -1,63 +1,63 @@ # -*- coding: utf-8 -*- import os from setuptools import setup, find_packages with open('README.rst') as f: readme = f.read() with open('LICENSE') as f: license = f.read() -VERSION = "0.3.0" +VERSION = "0.3.1" ROOT = os.path.dirname(os.path.realpath(__file__)) new_init = [] with open(os.path.join(ROOT, *("hyppopy", "__init__.py")), "r") as infile: for line in infile: new_init.append(line) for n in range(len(new_init)): if new_init[n].startswith("__version__"): split = line.split("=") new_init[n] = "__version__ = '" + VERSION + "'\n" with open(os.path.join(ROOT, *("hyppopy", "__init__.py")), "w") as outfile: outfile.writelines(new_init) setup( name='hyppopy', version=VERSION, description='Hyper-Parameter Optimization Toolbox for Blackboxfunction Optimization', long_description=readme, # if you want, put your own name here # (this would likely result in people sending you emails) author='Sven Wanner', author_email='s.wanner@dkfz.de', url='', license=license, packages=find_packages(exclude=('*test*', 'doc')), package_data={ 'hyppopy.plugins': ['*.yapsy-plugin'] }, # the requirements to install this project. # Since this one is so simple this is empty. install_requires=[ 'dicttoxml>=1.7.4', 'xmltodict>=0.11.0', 'hyperopt>=0.1.1', 'Optunity>=1.1.1', 'numpy>=1.16.0', 'matplotlib>=3.0.2', 'scikit-learn>=0.20.2', 'scipy>=1.2.0', 'Sphinx>=1.8.3', 'xmlrunner>=1.7.7', 'Yapsy>=1.11.223', 'pandas>=0.24.1', 'seaborn>=0.9.0', 'deap>=1.2.2', 'bayesian-optimization>=1.0.1' ], )