Skip to content

Commit c861a5f

Browse files
committed
Initial commit of code and documentation
1 parent c98c8f6 commit c861a5f

33 files changed

+6471
-2
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.pyc
2+
*/__pycache__
3+
*.egg-info
4+
docs/_build

LICENSE.txt

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

README.rst

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
==================================================================================
2+
Py-BOBYQA: Derivative-Free Solver for Bound-Constraint Minimization |PyPI Version|
3+
==================================================================================
4+
Py-BOBYQA is a flexible package for solving bound-constrained general objective minimization, without requiring derivatives of the objective. It is a Python implementation of the BOBYQA algorithm by Powell.
5+
6+
More details about Py-BOBYQA can be found in our paper: C. Cartis, J. Fiala, B. Marteau and L. Roberts, Improving the Flexibility and Robustness of Model-Based Derivative-Free Optimization Solvers, technical report, University of Oxford, (2018).
7+
8+
The original paper by Powell is: M. J. D. Powell, The BOBYQA algorithm for bound constrained optimization without derivatives, technical report DAMTP 2009/NA06, University of Cambridge (2009), and the original Fortran implementation is available `here <http://mat.uc.pt/~zhang/software.html>`_.
9+
10+
Documentation
11+
-------------
12+
See manual.pdf or `here <http://people.maths.ox.ac.uk/robertsl/pybobyqa>`_.
13+
14+
Requirements
15+
------------
16+
Py-BOBYQA requires the following software to be installed:
17+
18+
* Python 2.7 or Python 3 (http://www.python.org/)
19+
20+
Additionally, the following python packages should be installed (these will be installed automatically if using *pip*, see `Installation using pip`_):
21+
22+
* NumPy 1.11 or higher (http://www.numpy.org/)
23+
* SciPy 0.18 or higher (http://www.scipy.org/)
24+
* Pandas 0.17 or higher (http://pandas.pydata.org/)
25+
26+
Installation using pip
27+
----------------------
28+
For easy installation, use *pip* (http://www.pip-installer.org/) as root::
29+
30+
$ [sudo] pip install pybobyqa
31+
32+
or alternatively *easy_install*::
33+
34+
$ [sudo] easy_install pybobyqa
35+
36+
If you do not have root privileges or you want to install Py-BOBYQA for your private use, you can use::
37+
38+
$ pip install --user pybobyqa
39+
40+
which will install Py-BOBYQA in your home directory.
41+
42+
Note that if an older install of Py-BOBYQA is present on your system you can use::
43+
44+
$ [sudo] pip install --upgrade pybobyqa
45+
46+
to upgrade Py-BOBYQA to the latest version.
47+
48+
Manual installation
49+
-------------------
50+
Alternatively, you can download the source code from `Github <https://github.com/numericalalgorithmsgroup/pybobyqa>`_ and unpack as follows:
51+
52+
.. code-block:: bash
53+
54+
$ git clone https://github.com/numericalalgorithmsgroup/pybobyqa
55+
$ cd pybobyqa
56+
57+
Py-BOBYQA is written in pure Python and requires no compilation. It can be installed using:
58+
59+
.. code-block:: bash
60+
61+
$ [sudo] pip install .
62+
63+
If you do not have root privileges or you want to install Py-BOBYQA for your private use, you can use:
64+
65+
.. code-block:: bash
66+
67+
$ pip install --user .
68+
69+
instead.
70+
71+
Testing
72+
-------
73+
If you installed Py-BOBYQA manually, you can test your installation by running:
74+
75+
.. code-block:: bash
76+
77+
$ python setup.py test
78+
79+
Alternatively, the HTML documentation provides some simple examples of how to run Py-BOBYQA.
80+
81+
Examples
82+
--------
83+
Examples of how to run Py-BOBYQA are given in the `documentation <http://people.maths.ox.ac.uk/robertsl/pybobyqa>`_, and the `examples <https://github.com/numericalalgorithmsgroup/pybobyqa/tree/master/examples>`_ directory in Github.
84+
85+
Uninstallation
86+
--------------
87+
If Py-BOBYQA was installed using *pip* you can uninstall as follows:
88+
89+
.. code-block:: bash
90+
91+
$ [sudo] pip uninstall pybobyqa
92+
93+
If Py-BOBYQA was installed manually you have to remove the installed files by hand (located in your python site-packages directory).
94+
95+
Bugs
96+
----
97+
Please report any bugs using GitHub's issue tracker.
98+
99+
License
100+
-------
101+
This algorithm is released under the GNU GPL license.
102+
103+
.. |PyPI Version| image:: https://img.shields.io/pypi/v/PyBOBYQA.svg
104+
:target: https://pypi.python.org/pypi/PyBOBYQA

docs/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line.
5+
SPHINXOPTS =
6+
SPHINXBUILD = python3 -msphinx
7+
SPHINXPROJ = DFO-Gen
8+
SOURCEDIR = .
9+
BUILDDIR = _build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/advanced.rst

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
Advanced Usage
2+
==============
3+
This section describes different optional user parameters available in Py-BOBYQA.
4+
5+
In the last section (:doc:`userguide`), we introduced :code:`pybobyqa.solve()`, which has the optional input :code:`user_params`. This is a Python dictionary of user parameters. We will now go through the settings which can be changed in this way. More details are available in the paper [CFMR2018]_.
6+
7+
The default values, used if no override is given, in some cases vary depending on whether :code:`objfun` has stochastic noise; that is, whether evaluating :code:`objfun(x)` several times at the same :code:`x` gives the same result or not. Whether or not this is the case is determined by the :code:`objfun_has_noise` input to :code:`pybobyqa.solve()` (and not by inspecting :code:`objfun`, for instance).
8+
9+
General Algorithm Parameters
10+
----------------------------
11+
* :code:`general.rounding_error_constant` - Internally, all interpolation points are stored with respect to a base point :math:`x_b`; that is, we store :math:`\{y_t-x_b\}`, which reduces the risk of roundoff errors. We shift :math:`x_b` to :math:`x_k` when :math:`\|s_k\| \leq \text{const}\|x_k-x_b\|`, where 'const' is this parameter. Default is 0.1.
12+
* :code:`general.safety_step_thresh` - Threshold for when to call the safety step, :math:`\|s_k\| \leq \gamma_S \rho_k`. Default is :math:`\gamma_S =0.5`.
13+
* :code:`general.check_objfun_for_overflow` - Whether to cap the value of :math:`r_i(x)` when they are large enough that an OverflowError will be encountered when trying to evaluate :math:`f(x)`. Default is :code:`True`.
14+
15+
Logging and Output
16+
------------------
17+
* :code:`logging.n_to_print_whole_x_vector` - If printing all function evaluations to screen/log file, the maximum :code:`len(x)` for which the full vector :code:`x` should be printed also. Default is 6.
18+
* :code:`logging.save_diagnostic_info` - Flag so save diagnostic information at each iteration. Default is :code:`False`.
19+
* :code:`logging.save_poisedness` - If saving diagnostic information, whether to include the :math:`\Lambda`-poisedness of :math:`Y_k` in the diagnostic information. This is the most computationally expensive piece of diagnostic information. Default is :code:`True`.
20+
* :code:`logging.save_xk` - If saving diagnostic information, whether to include the full vector :math:`x_k`. Default is :code:`False`.
21+
22+
Initialization of Points
23+
------------------------
24+
* :code:`init.random_initial_directions` - Build the initial interpolation set using random directions (as opposed to coordinate directions). Default is :code:`True`.
25+
* :code:`init.random_directions_make_orthogonal` - If building initial interpolation set with random directions, whether or not these should be orthogonalized. Default is :code:`True`.
26+
* :code:`init.run_in_parallel` - If using random directions, whether or not to ask for all :code:`objfun` to be evaluated at all points without any intermediate processing. Default is :code:`False`.
27+
28+
Trust Region Management
29+
-----------------------
30+
* :code:`tr_radius.eta1` - Threshold for unsuccessful trust region iteration, :math:`\eta_1`. Default is 0.1.
31+
* :code:`tr_radius.eta2` - Threshold for very successful trust region iteration, :math:`\eta_2`. Default is 0.7.
32+
* :code:`tr_radius.gamma_dec` - Ratio to decrease :math:`\Delta_k` in unsuccessful iteration, :math:`\gamma_{dec}`. Default is 0.5 for smooth problems or 0.98 for noisy problems (i.e. :code:`objfun_has_noise = True`).
33+
* :code:`tr_radius.gamma_inc` - Ratio to increase :math:`\Delta_k` in very successful iterations, :math:`\gamma_{inc}`. Default is 2.
34+
* :code:`tr_radius.gamma_inc_overline` - Ratio of :math:`\|s_k\|` to increase :math:`\Delta_k` by in very successful iterations, :math:`\overline{\gamma}_{inc}`. Default is 4.
35+
* :code:`tr_radius.alpha1` - Ratio to decrease :math:`\rho_k` by when it is reduced, :math:`\alpha_1`. Default is 0.1 for smooth problems or 0.9 for noisy problems (i.e. :code:`objfun_has_noise = True`).
36+
* :code:`tr_radius.alpha2` - Ratio of :math:`\rho_k` to decrease :math:`\Delta_k` by when :math:`\rho_k` is reduced, :math:`\alpha_2`. Default is 0.5 for smooth problems or 0.95 for noisy problems (i.e. :code:`objfun_has_noise = True`).
37+
38+
Termination on Small Objective Value
39+
------------------------------------
40+
* :code:`model.abs_tol` - Tolerance on :math:`f(x_k)`; quit if :math:`f(x_k)` is below this value. Default is :math:`-10^{20}`.
41+
42+
Termination on Slow Progress
43+
----------------------------
44+
* :code:`slow.history_for_slow` - History used to determine whether the current iteration is 'slow'. Default is 5.
45+
* :code:`slow.thresh_for_slow` - Threshold for objective decrease used to determine whether the current iteration is 'slow'. Default is :math:`10^{-8}`.
46+
* :code:`slow.max_slow_iters` - Number of consecutive slow successful iterations before termination (or restart). Default is :code:`20*len(x0)`.
47+
48+
Stochastic Noise Information
49+
----------------------------
50+
* :code:`noise.quit_on_noise_level` - Flag to quit (or restart) if all :math:`f(y_t)` are within noise level of :math:`f(x_k)`. Default is :code:`False` for smooth problems or :code:`True` for noisy problems.
51+
* :code:`noise.scale_factor_for_quit` - Factor of noise level to use in termination criterion. Default is 1.
52+
* :code:`noise.multiplicative_noise_level` - Multiplicative noise level in :math:`f`. Can only specify one of multiplicative or additive noise levels. Default is :code:`None`.
53+
* :code:`noise.additive_noise_level` - Additive noise level in :math:`f`. Can only specify one of multiplicative or additive noise levels. Default is :code:`None`.
54+
55+
Interpolation Management
56+
--------------------------------
57+
* :code:`interpolation.precondition` - whether or not to scale the interpolation linear system to improve conditioning. Default is :code:`True`.
58+
* :code:`interpolation.minimum_change_hessian` - whether to solve the underdetermined quadratic interpolation problem by minimizing the Frobenius norm of the Hessian, or change in Hessian. Default is :code:`True`.
59+
60+
Multiple Restarts
61+
-----------------
62+
* :code:`restarts.use_restarts` - Whether to do restarts when :math:`\rho_k` reaches :math:`\rho_{end}`, or (optionally) when all points are within noise level of :math:`f(x_k)`. Default is :code:`False` for smooth problems or :code:`True` for noisy problems.
63+
* :code:`restarts.max_unsuccessful_restarts` - Maximum number of consecutive unsuccessful restarts allowed (i.e.~restarts which did not reduce the objective further). Default is 10.
64+
* :code:`restarts.rhoend_scale` - Factor to reduce :math:`\rho_{end}` by with each restart. Default is 1.
65+
* :code:`restarts.use_soft_restarts` - Whether to use soft or hard restarts. Default is :code:`True`.
66+
* :code:`restarts.soft.num_geom_steps` - For soft restarts, the number of points to move. Default is 3.
67+
* :code:`restarts.soft.move_xk` - For soft restarts, whether to preserve :math:`x_k`, or move it to the best new point evaluated. Default is :code:`True`.
68+
* :code:`restarts.hard.use_old_fk` - If using hard restarts, whether or not to recycle the objective value at the best iterate found when performing a restart. This saves one objective evaluation. Default is :code:`True`.
69+
* :code:`restarts.soft.max_fake_successful_steps` - The maximum number of successful steps in a given run where the new (smaller) objective value is larger than the best value found in a previous run. Default is :code:`maxfun`, the input to :code:`pybobyqa.solve()`.
70+
* :code:`restarts.auto_detect` - Whether or not to automatically determine when to restart. This is an extra condition, and restarts can still be triggered by small trust region radius, etc. Default is :code:`True`.
71+
* :code:`restarts.auto_detect.history` - How many iterations of data on model changes and trust region radii to store. There are two criteria used: trust region radius decreases (no increases over the history, more decreases than no changes), and change in model Jacobian (consistently increasing trend as measured by slope and correlation coefficient of line of best fit). Default is 30.
72+
* :code:`restarts.auto_detect.min_chg_model_slope` - Minimum rate of increase of :math:`\log(\|g_k-g_{k-1}\|)` and :math:`\log(\|H_k-H_{k-1}\|_F)` over the past iterations to cause a restart. Default is 0.015.
73+
* :code:`restarts.auto_detect.min_correl` - Minimum correlation of the data sets :math:`(k, \log(\|g_k-g_{k-1}\|))` and :math:`(k, \log(\|H_k-H_{k-1}\|_F))` required to cause a restart. Default is 0.1.
74+
75+
76+
References
77+
----------
78+
79+
.. [CFMR2018]
80+
C. Cartis, J. Fiala, B. Marteau and L. Roberts, Improving the Flexibility and Robustness of Model-Based Derivative-Free Optimization Solvers, technical report, University of Oxford, (2018).
81+

docs/conf.py

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Py-BOBYQA documentation build configuration file, created by
5+
# sphinx-quickstart on Wed Nov 8 10:59:20 2017.
6+
#
7+
# This file is execfile()d with the current directory set to its
8+
# containing dir.
9+
#
10+
# Note that not all possible configuration values are present in this
11+
# autogenerated file.
12+
#
13+
# All configuration values have a default; values that are commented out
14+
# serve to show the default.
15+
16+
# If extensions (or modules to document with autodoc) are in another directory,
17+
# add these directories to sys.path here. If the directory is relative to the
18+
# documentation root, use os.path.abspath to make it absolute, like shown here.
19+
#
20+
import os
21+
import sys
22+
sys.path.insert(0, '../pybobyqa/')
23+
from version import __version__
24+
25+
26+
# -- General configuration ------------------------------------------------
27+
28+
# If your documentation needs a minimal Sphinx version, state it here.
29+
#
30+
# needs_sphinx = '1.0'
31+
32+
# Add any Sphinx extension module names here, as strings. They can be
33+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
34+
# ones.
35+
extensions = ['sphinx.ext.mathjax']
36+
37+
# Add any paths that contain templates here, relative to this directory.
38+
templates_path = ['_templates']
39+
40+
# The suffix(es) of source filenames.
41+
# You can specify multiple suffix as a list of string:
42+
#
43+
# source_suffix = ['.rst', '.md']
44+
source_suffix = '.rst'
45+
46+
# The master toctree document.
47+
master_doc = 'index'
48+
49+
# General information about the project.
50+
project = 'Py-BOBYQA'
51+
copyright = '2017, Lindon Roberts'
52+
author = 'Lindon Roberts'
53+
54+
# The version info for the project you're documenting, acts as replacement for
55+
# |version| and |release|, also used in various other places throughout the
56+
# built documents.
57+
#
58+
# The short X.Y version.
59+
version = __version__
60+
# The full version, including alpha/beta/rc tags.
61+
release = __version__
62+
63+
# The language for content autogenerated by Sphinx. Refer to documentation
64+
# for a list of supported languages.
65+
#
66+
# This is also used if you do content translation via gettext catalogs.
67+
# Usually you set "language" from the command line for these cases.
68+
language = None
69+
70+
# There are two options for replacing |today|: either, you set today to some
71+
# non-false value, then it is used:
72+
#today = '20 June, 2016'
73+
# Else, today_fmt is used as the format for a strftime call.
74+
today_fmt = '%d %B %Y'
75+
76+
# List of patterns, relative to source directory, that match files and
77+
# directories to ignore when looking for source files.
78+
# This patterns also effect to html_static_path and html_extra_path
79+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
80+
81+
# The name of the Pygments (syntax highlighting) style to use.
82+
pygments_style = 'sphinx'
83+
84+
# If true, `todo` and `todoList` produce output, else they produce nothing.
85+
todo_include_todos = False
86+
87+
88+
# -- Options for HTML output ----------------------------------------------
89+
90+
# The theme to use for HTML and HTML Help pages. See the documentation for
91+
# a list of builtin themes.
92+
#
93+
html_theme = 'alabaster'
94+
95+
# The name for this set of Sphinx documents. If None, it defaults to
96+
# "<project> v<release> documentation".
97+
html_title = 'Py-BOBYQA v%s documentation' % __version__
98+
99+
# Theme options are theme-specific and customize the look and feel of a theme
100+
# further. For a list of options available for each theme, see the
101+
# documentation.
102+
#
103+
# html_theme_options = {}
104+
105+
# Add any paths that contain custom static files (such as style sheets) here,
106+
# relative to this directory. They are copied after the builtin static files,
107+
# so a file named "default.css" will overwrite the builtin "default.css".
108+
html_static_path = ['_static']
109+
110+
# Custom sidebar templates, must be a dictionary that maps document names
111+
# to template names.
112+
#
113+
# This is required for the alabaster theme
114+
# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars
115+
html_sidebars = {
116+
'**': [
117+
'about.html',
118+
'navigation.html',
119+
'relations.html', # needs 'show_related': True theme option to display
120+
'searchbox.html',
121+
'donate.html',
122+
]
123+
}
124+
125+
126+
# -- Options for HTMLHelp output ------------------------------------------
127+
128+
# Output file base name for HTML help builder.
129+
htmlhelp_basename = 'Py-BOBYQAdoc'
130+
131+
132+
# -- Options for LaTeX output ---------------------------------------------
133+
134+
latex_elements = {
135+
# The paper size ('letterpaper' or 'a4paper').
136+
#
137+
# 'papersize': 'letterpaper',
138+
139+
# The font size ('10pt', '11pt' or '12pt').
140+
#
141+
# 'pointsize': '10pt',
142+
143+
# Additional stuff for the LaTeX preamble.
144+
#
145+
# 'preamble': '',
146+
147+
# Latex figure (float) alignment
148+
#
149+
# 'figure_align': 'htbp',
150+
}
151+
152+
# Grouping the document tree into LaTeX files. List of tuples
153+
# (source start file, target name, title,
154+
# author, documentclass [howto, manual, or own class]).
155+
latex_documents = [
156+
(master_doc, 'Py-BOBYQA.tex', 'Py-BOBYQA Documentation',
157+
'Lindon Roberts', 'manual'),
158+
]
159+
160+
161+
# -- Options for manual page output ---------------------------------------
162+
163+
# One entry per manual page. List of tuples
164+
# (source start file, name, description, authors, manual section).
165+
man_pages = [
166+
(master_doc, 'py-bobyqa', 'Py-BOBYQA Documentation',
167+
[author], 1)
168+
]
169+
170+
171+
# -- Options for Texinfo output -------------------------------------------
172+
173+
# Grouping the document tree into Texinfo files. List of tuples
174+
# (source start file, target name, title, author,
175+
# dir menu entry, description, category)
176+
texinfo_documents = [
177+
(master_doc, 'Py-BOBYQA', 'Py-BOBYQA Documentation',
178+
author, 'Py-BOBYQA', 'One line description of project.',
179+
'Miscellaneous'),
180+
]
181+
182+
183+

0 commit comments

Comments
 (0)