Skip to content

Commit

Permalink
Merge pull request #418 from bwheelz36/html_docs
Browse files Browse the repository at this point in the history
SPHINX based html docs
  • Loading branch information
bwheelz36 committed May 15, 2023
2 parents 698ca60 + ab3c41f commit 434ac43
Show file tree
Hide file tree
Showing 12 changed files with 278 additions and 26 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/build_docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: build docs

on:
push:
branches:
- main
pull_request:

jobs:
deploy:
runs-on: ubuntu-20.04
permissions:
contents: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
steps:
- uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v3
with:
python-version: '3.10'
- name: Install pandoc
run: sudo apt-get install -y pandoc
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install sphinx
pip install nbsphinx
pip install sphinx_rtd_theme
pip install jupyter
- name: Install package
run: |
pip install -e .
- name: build sphinx docs
run: |
cd docsrc
make github
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
if: ${{ github.ref == 'refs/heads/main' }}
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ venv/
ENV/
env.bak/
venv.bak/
*temp*
*temp*

docs/*
docsrc/.ipynb_checkpoints/*
docsrc/*.ipynb
24 changes: 24 additions & 0 deletions docsrc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = ../docs

# Put it first so that "make" without argument is like "make help".
# help:
# @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

github:
@make html
@cp -a ../docs/html/. ../docs

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
34 changes: 34 additions & 0 deletions docsrc/code_docs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Code Documentation
==================

This page shows the documentation generated by sphinx automatically scanning our source code

Bayesian Optimization
---------------------

.. automodule:: bayes_opt.bayesian_optimization
:members:

Acquisition function
--------------------

.. autoclass:: bayes_opt.util.UtilityFunction
:members:

Target Space
------------

.. autoclass:: bayes_opt.target_space.TargetSpace
:members:

Domain reduction
----------------

.. autoclass:: bayes_opt.domain_reduction.SequentialDomainReductionTransformer
:members:

Constraints
-----------

.. autoclass:: bayes_opt.constraint.ConstraintModel
:members:
70 changes: 70 additions & 0 deletions docsrc/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- 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
import shutil
from glob import glob
from pathlib import Path
# sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.abspath('..'))

# copy the latest example files:
this_file_loc = Path(__file__).parent
notebooks = glob(str(this_file_loc.parent / 'examples' / '*.ipynb'))
for notebook in notebooks:
shutil.copy(notebook, this_file_loc)


# -- Project information -----------------------------------------------------

project = 'Bayesian Optimization'
author = 'Fernando Nogueira'


# -- General configuration ---------------------------------------------------

# 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',
'sphinx.ext.coverage',
'sphinx.ext.githubpages',
'nbsphinx',
'IPython.sphinxext.ipython_console_highlighting',
'sphinx.ext.mathjax']

source_suffix = {
'.rst': 'restructuredtext',
'.md': 'markdown',
}
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# 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 = []


# -- 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 = 'sphinx_rtd_theme'

# 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']
13 changes: 13 additions & 0 deletions docsrc/examples.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Examples
========

.. toctree::
:maxdepth: 2
:caption: Examples:

/basic-tour
/advanced-tour
/exploitation_vs_exploration
/visualization
/constraints
/domain_reduction
16 changes: 16 additions & 0 deletions docsrc/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Bayesian Optimization
=====================

.. toctree::
:maxdepth: 2
:caption: Contents:

/examples
/code_docs

Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
44 changes: 44 additions & 0 deletions docsrc/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=../docs

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

if "%1" == "github" (
%SPHINXBUILD% -M html %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
robocopy %BUILDDIR%/html ../docs /E > nul
echo.Generated files copied to ../docs
goto end
)


%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end


:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
3 changes: 3 additions & 0 deletions docsrc/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sphinx
nbsphinx
sphinx_rtd_theme
4 changes: 2 additions & 2 deletions examples/constraints.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"2. Expensive constraints - in other situations, you may not know whether or not a given solution violates your constraints until you have explicitly evaluate the objective function there - which is typically an expensive operation. In such situations, it is desirable to **learn** the constrained regions on the fly in order to avoid unnecessary expensive calls to the objective function. The way to handle these situations is described in **2. Advanced Constrained Optimization**\n",
"\n",
"\n",
"# 1. Simple Constrained Optimization\n",
"## 1. Simple Constrained Optimization\n",
"\n",
"In situations where you know in advance whether or not a given point violates your constraints, you can normally simply code them directly into the objective function. To demonstrate this, let's start with a standard non-constrained optimization:"
]
Expand Down Expand Up @@ -161,7 +161,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# 2. Advanced Constrained Optimization"
"## 2. Advanced Constrained Optimization"
]
},
{
Expand Down
38 changes: 19 additions & 19 deletions examples/exploitation_vs_exploration.ipynb

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions examples/visualization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Target Function\n",
"# Visualization\n",
"\n",
"Lets create a target 1-D function with multiple local maxima to test and visualize how the [BayesianOptimization](https://github.com/fmfn/BayesianOptimization) package works. The target function we will try to maximize is the following:\n",
"\n",
Expand Down Expand Up @@ -66,7 +66,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Create a BayesianOptimization Object\n",
"## Create a BayesianOptimization Object\n",
"\n",
"Enter the target function to be maximized, its variable(s) and their corresponding ranges. A minimum number of 2 initial guesses is necessary to kick start the algorithms, these can either be random or user defined."
]
Expand Down Expand Up @@ -114,7 +114,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Plotting and visualizing the algorithm at each step"
"## Plotting and visualizing the algorithm at each step"
]
},
{
Expand Down Expand Up @@ -486,7 +486,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Stopping\n",
"## Stopping\n",
"\n",
"After just a few points the algorithm was able to get pretty close to the true maximum. It is important to notice that the trade off between exploration (exploring the parameter space) and exploitation (probing points near the current known maximum) is fundamental to a succesful bayesian optimization procedure. The utility function being used here (Upper Confidence Bound - UCB) has a free parameter $\\kappa$ that allows the user to make the algorithm more or less conservative. Additionally, the larger the initial set of random points explored, the less likely the algorithm is to get stuck in local minima due to being too conservative."
]
Expand Down

0 comments on commit 434ac43

Please sign in to comment.