diff --git a/.gitignore b/.gitignore index 224a2ee..507df4e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,110 +1,111 @@ # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class # latex *.aux *.bbl *.blg *.log *.tcp # solver_comparison examples/solver_comparison/gfx/data_I examples/solver_comparison/gfx/data_II examples/solver_comparison/gfx/data_III *.vpp.lck .pytest_cache/ *.vpp.bak_* python_tests_xml +doc/CHANGELOG.md # C extensions *.so # Distribution / packaging .Python env/ build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ lib/ lib64/ parts/ sdist/ var/ *.egg-info/ .installed.cfg *.egg .idea/ # PyInstaller # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec # Installer logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .coverage .coverage.* .cache nosetests.xml coverage.xml *,cover .hypothesis/ # Translations *.mo *.pot # Django stuff: *.log # Sphinx documentation doc/_build/ doc/LICENSE.rst doc/README.md # PyBuilder target/ #Ipython Notebook .ipynb_checkpoints #Pycharm files *.iml # merging stuff *.orig *~ # Paths in repository mcml.py # images etc *.tif *.nrrd *.caffemodel # C++ stuff build* *.user hyppopy/tests/test_snipped_000.py hyppopy/tests/test_snipped_001.py hyppopy/tests/test_snipped_002.py hyppopy/tests/test_snipped_003.py hyppopy/tests/test_snipped_004.py hyppopy/tests/test_snipped_005.py hyppopy/tests/test_snipped_006.py diff --git a/CHANGELOG.md b/CHANGELOG.md index d245baa..5093a4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,16 +1,18 @@ +# Changelog + Release 0.5.0.0 - settings structure changed, additional settings now can be addded as additional entries in the config dict or using the methods add_setting or set_settings - sections solver and custom in config dict are removed completely - use_solver setting in config dict is renamed to solver - hyperparameter type now a native type, not a string anymore - automatic consistency check between config and solver conditions, each solver defines now it's interface which is checked when executing the solver throwing exceptions if the project instance and the solvers interface doesn't work together - bayesOpt solver removed, extremely slow and not very good Release 0.4.2.0 New feature QuasiRandomSolver added. The QuasiRandomSolver provides a randomized gridsampling. This means that depending on max_iterations a grid over all numerical parameter is spanned and each cell is populated with a random value within the the cell bounds for numerical and a random draw for each categorical parameter. This ensures a random sampling of the parameter space and a good space coverage without random cluster building. The solver also supports normal and loguniform sampling. \ No newline at end of file diff --git a/doc/api.rst b/doc/api.rst new file mode 100644 index 0000000..1f9ef36 --- /dev/null +++ b/doc/api.rst @@ -0,0 +1,77 @@ +*********** +Hyppopy API +*********** + +Main Classes +############ + +HyppopyProject +************** +.. automodule:: hyppopy.HyppopyProject + :members: + +BlackboxFunction +**************** +.. automodule:: hyppopy.BlackboxFunction + :members: + +HyppopySolver +************* +.. automodule:: hyppopy.solvers.HyppopySolver + :members: + +SolverPool +********** +.. automodule:: hyppopy.SolverPool + :members: + +Solver Classes +############## + +HyperoptSolver +************** +.. automodule:: hyppopy.solvers.HyperoptSolver + :members: + +OptunitySolver +************** +.. automodule:: hyppopy.solvers.OptunitySolver + :members: + +OptunaSolver +************** +.. automodule:: hyppopy.solvers.OptunaSolver + :members: + +RandomsearchSolver +****************** +.. automodule:: hyppopy.solvers.RandomsearchSolver + :members: + +QuasiRandomsearchSolver +*********************** +.. automodule:: hyppopy.solvers.QuasiRandomsearchSolver + :members: + +RandomsearchSolver +****************** +.. automodule:: hyppopy.solvers.RandomsearchSolver + :members: + +Helpers +####### + +VisdomViewer +************ +.. automodule:: hyppopy.VisdomViewer + :members: + +FunctionSimulator +***************** +.. automodule:: hyppopy.FunctionSimulator + :members: + +Singleton +********* +.. automodule:: hyppopy.Singleton + :members: \ No newline at end of file diff --git a/doc/conf.py b/doc/conf.py index f181e57..1eda279 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -1,208 +1,223 @@ # -*- coding: utf-8 -*- # # Configuration file for the Sphinx documentation builder. # # This file does only contain a selection of the most common options. For a # full list see the documentation: # http://www.sphinx-doc.org/en/master/config # -- Path setup -------------------------------------------------------------- # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. # import os import sys from shutil import copyfile ROOT = os.path.abspath('../') sys.path.insert(0, os.path.abspath('.')) sys.path.insert(0, ROOT) README_PATH_SRC = os.path.join(ROOT, "README.md") README_PATH_DST = os.path.join(ROOT, *("doc", "README.md")) print("copy", README_PATH_SRC, "to", README_PATH_DST) try: copyfile(README_PATH_SRC, README_PATH_DST) except: print("Missing README.md file in subdir!") LICENSE_PATH_SRC = os.path.join(ROOT, "LICENSE") LICENSE_PATH_DST = os.path.join(ROOT, *("doc", "LICENSE.rst")) print("copy", LICENSE_PATH_SRC, "to", LICENSE_PATH_DST) try: copyfile(LICENSE_PATH_SRC, LICENSE_PATH_DST) except: print("Missing LICENSE file in subdir!") + +CHANGELOG_PATH_SRC = os.path.join(ROOT, "CHANGELOG.md") +CHANGELOG_PATH_DST = os.path.join(ROOT, *("doc", "CHANGELOG.md")) +print("copy", CHANGELOG_PATH_SRC, "to", CHANGELOG_PATH_DST) +try: + copyfile(CHANGELOG_PATH_SRC, CHANGELOG_PATH_DST) +except: + print("Missing CHANGELOG.md file in subdir!") # -- Project information ----------------------------------------------------- project = 'Hyppopy' copyright = '2019, DKFZ' author = 'S. Wanner' # The short X.Y version version = '0.5' # The full version, including alpha/beta/rc tags release = '0.5.0' # -- General configuration --------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. # # needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. -extensions = [ - 'sphinx.ext.autodoc', - 'recommonmark', - 'autoapi.extension', - 'sphinx.ext.napoleon', -] - -autoapi_type = 'python' -autoapi_dirs = [ROOT, ''] +#extensions = [ + # 'sphinx.ext.autodoc', +# 'recommonmark', +# 'autoapi.extension', +# 'sphinx.ext.napoleon' +#] + +extensions = ['recommonmark', + 'sphinx.ext.autodoc', + 'sphinx.ext.coverage', + 'sphinx.ext.napoleon', + #'autoapi.extension', + 'sphinx.ext.inheritance_diagram'] + +#autoapi_type = 'python' +#autoapi_dirs = [ROOT, ''] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] # The suffix(es) of source filenames. # You can specify multiple suffix as a list of string: # # source_suffix = ['.rst', '.md'] source_suffix = '.rst' # The master toctree document. master_doc = 'index' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. language = None # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This pattern also affects html_static_path and html_extra_path. -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'doc', 'tests'] # The name of the Pygments (syntax highlighting) style to use. pygments_style = None # -- Options for HTML output ------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # html_theme = 'alabaster' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. # # html_theme_options = {} # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] # Custom sidebar templates, must be a dictionary that maps document names # to template names. # # The default sidebars (for documents that don't match any pattern) are # defined by theme itself. Builtin themes are using these templates by # default: ``['localtoc.html', 'relations.html', 'sourcelink.html', # 'searchbox.html']``. # # html_sidebars = {} # -- Options for HTMLHelp output --------------------------------------------- # Output file base name for HTML help builder. htmlhelp_basename = 'Hyppopydoc' # -- Options for LaTeX output ------------------------------------------------ latex_elements = { # The paper size ('letterpaper' or 'a4paper'). # # 'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). # # 'pointsize': '10pt', # Additional stuff for the LaTeX preamble. # # 'preamble': '', # Latex figure (float) alignment # # 'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ (master_doc, 'Hyppopy.tex', 'Hyppopy Documentation', 'S. Wanner', 'manual'), ] # -- Options for manual page output ------------------------------------------ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ (master_doc, 'hyppopy', 'Hyppopy Documentation', [author], 1) ] # -- Options for Texinfo output ---------------------------------------------- # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ (master_doc, 'Hyppopy', 'Hyppopy Documentation', author, 'Hyppopy', 'One line description of project.', 'Miscellaneous'), ] # -- Options for Epub output ------------------------------------------------- # Bibliographic Dublin Core info. epub_title = project # The unique identifier of the text. This can be a ISBN number # or the project homepage. # # epub_identifier = '' # A unique identification for the text. # # epub_uid = '' # A list of files that should not be packed into the epub file. epub_exclude_files = ['search.html'] # -- Extension configuration ------------------------------------------------- # -- Options for todo extension ---------------------------------------------- # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = True diff --git a/doc/developer_guide.rst b/doc/developer_guide.rst index 0d0c402..4308c07 100644 --- a/doc/developer_guide.rst +++ b/doc/developer_guide.rst @@ -1,13 +1,3 @@ +**************** Developers Guide -================ - -Goals Achieved --------------- - -Goal 1 - Whohoo -Goal 2 - Moep Moep - -Lessons Learned ---------------- - -I know that I know nothing \ No newline at end of file +**************** diff --git a/doc/index.rst b/doc/index.rst index 2cf2a5b..92e6a66 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -1,24 +1,19 @@ -.. Hyppopy documentation master file, created by - sphinx-quickstart on Tue Apr 30 13:26:17 2019. - You can adapt this file completely to your liking, but it should at least - contain the root `toctree` directive. - Welcome to Hyppopy's documentation! =================================== .. toctree:: - :maxdepth: 2 + :maxdepth: 3 :caption: Contents: README + api developer_guide + CHANGELOG LICENSE - - Indices and tables ================== * :ref:`genindex` * :ref:`modindex` -* :ref:`search` +* :ref:`search` \ No newline at end of file diff --git a/hyppopy/HyppopyProject.py b/hyppopy/HyppopyProject.py index 2d3e116..719f386 100644 --- a/hyppopy/HyppopyProject.py +++ b/hyppopy/HyppopyProject.py @@ -1,146 +1,147 @@ # Hyppopy - A Hyper-Parameter Optimization Toolbox # # Copyright (c) German Cancer Research Center, # Division of Medical Image Computing. # 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 __all__ = ['HyppopyProject'] -import copy +import copy from hyppopy.globals import * + LOG = logging.getLogger(os.path.basename(__file__)) LOG.setLevel(DEBUGLEVEL) class HyppopyProject(object): """ The HyppopyProject class takes care of the optimization settings. An instance can be configured using a config dictionary or by using the hyperparameter and settings methods. In case of initializing via dicts those can be passed to the constructor or by using the set_config method. After initialization a HyppopyProject instance is passed to a solver class which internally checks for consistency with it's needs. The class distinguished between two categories, hyperparameter and general settings. The hyperparameter are a dictionary structure as follows and can be accessed via hyperparameter {'param_name: {'domain': 'uniform', ...}, ...} General settings are internally converted to class attributes and can accessed directly or via settings An example config could look like: config = {'hyperparameter': {'myparam': {'domain': 'uniform', 'data': [0, 100], 'type': float}, ...}, 'my_setting_1': 3.1415, 'my_setting_2': 'hello world'} project = HyppopyProject(config) The same can be achieved using: project = HyppopyProject() project.add_hyperparameter(name='myparam', domain='uniform', data=[0, 100], type=float}) project.add_setting('my_setting_1', 3.1415) project.add_setting('my_setting_2', 'hello world') """ def __init__(self, config=None): """ Constructor :param config: [dict] config dictionary of the form {'hyperparameter': {...}, ...} """ self._data = {HYPERPARAMETERPATH: {}, SETTINGSPATH: {}} if config is not None: self.set_config(config) def __parse_members(self): """ The function converts settings into class attributes """ for name, value in self.settings.items(): if name not in self.__dict__.keys(): setattr(self, name, value) else: self.__dict__[name] = value def set_config(self, config): """ Set a config dict :param config: [dict] configuration dict defining hyperparameter and general settings """ assert isinstance(config, dict), "precondition violation, config needs to be of type dict, got {}".format(type(config)) confic_cp = copy.deepcopy(config) if HYPERPARAMETERPATH in confic_cp.keys(): self._data[HYPERPARAMETERPATH] = confic_cp[HYPERPARAMETERPATH] del confic_cp[HYPERPARAMETERPATH] self._data[SETTINGSPATH] = confic_cp self.__parse_members() def set_hyperparameter(self, params): """ This function can be used to set the hyperparameter description directly by passing the hyperparameter section of a config dict (see class description). Alternatively use add_hyperparameter to add one after each other. :param params: [dict] configuration dict defining hyperparameter """ assert isinstance(params, dict), "precondition violation, params needs to be of type dict, got {}".format(type(params)) self._data[HYPERPARAMETERPATH] = params def add_hyperparameter(self, name, **kwargs): """ This function can be used to set hyperparameter descriptions. Alternatively use set_hyperparameter to set all at once. :param name: [str] hyperparameter name - :param **kwargs: [dict] configuration dict defining a hyperparameter e.g. domain='uniform', data=[1,100], ... + :param kwargs: [dict] configuration dict defining a hyperparameter e.g. domain='uniform', data=[1,100], ... """ assert isinstance(name, str), "precondition violation, name needs to be of type str, got {}".format(type(name)) self._data[HYPERPARAMETERPATH][name] = kwargs def set_settings(self, **kwargs): """ This function can be used to set the general settings directly by passing the settings as name=value pairs. Alternatively use add_setting to add one after each other. - :param **kwargs: [dict] settings dict e.g. my_setting_1=3.1415, my_setting_2='hello world', ... + :param kwargs: [dict] settings dict e.g. my_setting_1=3.1415, my_setting_2='hello world', ... """ self._data[SETTINGSPATH] = kwargs self.__parse_members() def add_setting(self, name, value): """ This function can be used to set a general settings. Alternatively use set_settings to set all at once. :param name: [str] setting name :param value: [object] settings value """ assert isinstance(name, str), "precondition violation, name needs to be of type str, got {}".format(type(name)) self._data[SETTINGSPATH][name] = value self.__parse_members() def get_typeof(self, name): """ Returns a hyperparameter type by name :param name: [str] hyperparameter name :return: [type] hyperparameter type """ if not name in self.hyperparameter.keys(): raise LookupError("Typechecking failed, couldn't find hyperparameter {}!".format(name)) if not "type" in self.hyperparameter[name].keys(): raise LookupError("Typechecking failed, couldn't find hyperparameter signature type!") dtype = self.hyperparameter[name]["type"] return dtype @property def hyperparameter(self): return self._data[HYPERPARAMETERPATH] @property def settings(self): return self._data[SETTINGSPATH] diff --git a/requirements.txt b/requirements.txt index 4ffe08c..2c5bae8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,11 +1,12 @@ hyperopt>=0.1.2 matplotlib>=3.0.3 numpy>=1.16.2 optuna>=0.9.0 Optunity>=1.1.1 pandas>=0.24.2 pytest>=4.3.1 scikit-learn>=0.20.3 scipy>=1.2.1 visdom>=0.1.8.8 -xmlrunner>=1.7.7 \ No newline at end of file +xmlrunner>=1.7.7 +Sphinx>=1.8.3 \ No newline at end of file