Skip to content

Commit

Permalink
Merge pull request #419 from leandrobbraga/fix-typos
Browse files Browse the repository at this point in the history
Fix some typos
  • Loading branch information
bwheelz36 committed May 9, 2023
2 parents af1adc6 + 08c7bdc commit 04aea8b
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ optimizer.maximize(
)
```

By default the previous data in the json file is removed. If you want to keep working with the same logger, the `reset` paremeter in `JSONLogger` should be set to False.
By default the previous data in the json file is removed. If you want to keep working with the same logger, the `reset` parameter in `JSONLogger` should be set to False.

### 4.2 Loading progress

Expand Down
8 changes: 4 additions & 4 deletions bayes_opt/domain_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def transform(self, target_space: TargetSpace):

class SequentialDomainReductionTransformer(DomainTransformer):
"""
A sequential domain reduction transformer bassed on the work by Stander, N. and Craig, K:
A sequential domain reduction transformer based on the work by Stander, N. and Craig, K:
"On the robustness of a simple domain reduction scheme for simulation‐based optimization"
"""

Expand Down Expand Up @@ -68,8 +68,8 @@ def initialize(self, target_space: TargetSpace) -> None:

self.r = self.contraction_rate * self.r

# check if the minimum window fits in the orignal bounds
self._window_bounds_compatiblity(self.original_bounds)
# check if the minimum window fits in the original bounds
self._window_bounds_compatibility(self.original_bounds)

def _update(self, target_space: TargetSpace) -> None:

Expand Down Expand Up @@ -121,7 +121,7 @@ def _trim(self, new_bounds: np.array, global_bounds: np.array) -> np.array:
new_bounds[i, 1] += ddw_r
return new_bounds

def _window_bounds_compatiblity(self, global_bounds: np.array) -> bool:
def _window_bounds_compatibility(self, global_bounds: np.array) -> bool:
"""Checks if global bounds are compatible with the minimum window sizes."""
for i, entry in enumerate(global_bounds):
global_window_width = abs(entry[1] - entry[0])
Expand Down
2 changes: 1 addition & 1 deletion bayes_opt/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def acq_max(ac, gp, y_max, bounds, random_state, constraint=None, n_warmup=10000
x_max = x_tries[ys.argmax()]
max_acq = ys.max()

# Explore the parameter space more throughly
# Explore the parameter space more thoroughly
x_seeds = random_state.uniform(bounds[:, 0], bounds[:, 1],
size=(n_iter, bounds.shape[0]))

Expand Down
5 changes: 3 additions & 2 deletions examples/advanced-tour.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Let's start by defining our function, bounds, and instanciating an optimization object.\n",
"# Let's start by defining our function, bounds, and instantiating an optimization object.\n",
"def black_box_function(x, y):\n",
" return -x ** 2 - (y - 1) ** 2 + 1"
]
Expand Down Expand Up @@ -347,12 +347,13 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### 3.3 Changing kernels\n",
"\n",
"By default this package uses the Mattern 2.5 kernel. Depending on your use case you may find that tunning the GP kernel could be beneficial. You're on your own here since these are very specific solutions to very specific problems."
"By default this package uses the Matern 2.5 kernel. Depending on your use case you may find that tunning the GP kernel could be beneficial. You're on your own here since these are very specific solutions to very specific problems."
]
},
{
Expand Down
12 changes: 8 additions & 4 deletions examples/basic-tour.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1. Specifying the function to be optimized\n",
"\n",
"This is a function optimization package, therefore the first and most important ingreedient is, of course, the function to be optimized.\n",
"This is a function optimization package, therefore the first and most important ingredient is, of course, the function to be optimized.\n",
"\n",
"**DISCLAIMER:** We know exactly how the output of the function below depends on its parameter. Obviously this is just an example, and you shouldn't expect to know it in a real scenario. However, it should be clear that you don't need to. All you need in order to use this package (and more generally, this technique) is a function `f` that takes a known set of parameters and outputs a real number."
]
Expand All @@ -43,12 +44,13 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2. Getting Started\n",
"\n",
"All we need to get started is to instanciate a `BayesianOptimization` object specifying a function to be optimized `f`, and its parameters with their corresponding bounds, `pbounds`. This is a constrained optimization technique, so you must specify the minimum and maximum values that can be probed for each parameter in order for it to work"
"All we need to get started is to instantiate a `BayesianOptimization` object specifying a function to be optimized `f`, and its parameters with their corresponding bounds, `pbounds`. This is a constrained optimization technique, so you must specify the minimum and maximum values that can be probed for each parameter in order for it to work"
]
},
{
Expand Down Expand Up @@ -306,12 +308,13 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## 4. Saving, loading and restarting\n",
"\n",
"By default you can follow the progress of your optimization by setting `verbose>0` when instanciating the `BayesianOptimization` object. If you need more control over logging/alerting you will need to use an observer. For more information about observers checkout the advanced tour notebook. Here we will only see how to use the native `JSONLogger` object to save to and load progress from files.\n",
"By default you can follow the progress of your optimization by setting `verbose>0` when instantiating the `BayesianOptimization` object. If you need more control over logging/alerting you will need to use an observer. For more information about observers checkout the advanced tour notebook. Here we will only see how to use the native `JSONLogger` object to save to and load progress from files.\n",
"\n",
"### 4.1 Saving progress"
]
Expand All @@ -327,14 +330,15 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"The observer paradigm works by:\n",
"1. Instantiating an observer object.\n",
"2. Tying the observer object to a particular event fired by an optimizer.\n",
"\n",
"The `BayesianOptimization` object fires a number of internal events during optimization, in particular, everytime it probes the function and obtains a new parameter-target combination it will fire an `Events.OPTIMIZATION_STEP` event, which our logger will listen to.\n",
"The `BayesianOptimization` object fires a number of internal events during optimization, in particular, every time it probes the function and obtains a new parameter-target combination it will fire an `Events.OPTIMIZATION_STEP` event, which our logger will listen to.\n",
"\n",
"**Caveat:** The logger will not look back at previously probed points."
]
Expand Down
2 changes: 1 addition & 1 deletion examples/constraints.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@
" else:\n",
" c_labels = [f\"constraint {i+1}\" for i in range(n_constraints)]\n",
" labels_top = [\"target\"] + c_labels + [\"masked target\"]\n",
" labels_bot = [\"target estimate\"] + [c + \" estimate\" for c in c_labels] + [\"acqusition function\"]\n",
" labels_bot = [\"target estimate\"] + [c + \" estimate\" for c in c_labels] + [\"acquisition function\"]\n",
" labels = [labels_top, labels_bot]\n",
"\n",
" # Setup the grid to plot on\n",
Expand Down
11 changes: 7 additions & 4 deletions examples/domain_reduction.ipynb
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Sequential Domain Reduction\n",
"\n",
"## Background\n",
"Sequential domain reduction is a process where the bounds of the optimization problem are mutated (typically contracted) to reduce the time required to converge to an optimal value. The advantage of this method is typically seen when a cost function is particularly expensive to calculate, or if the optimization routine oscilates heavily. \n",
"Sequential domain reduction is a process where the bounds of the optimization problem are mutated (typically contracted) to reduce the time required to converge to an optimal value. The advantage of this method is typically seen when a cost function is particularly expensive to calculate, or if the optimization routine oscillates heavily. \n",
"\n",
"## Basics\n",
"\n",
"The basic steps are a *pan* and a *zoom*. These two steps are applied at one time, therefore updating the problem search space evey iteration.\n",
"The basic steps are a *pan* and a *zoom*. These two steps are applied at one time, therefore updating the problem search space every iteration.\n",
"\n",
"**Pan**: recentering the region of interest around the most optimal point found.\n",
"\n",
Expand Down Expand Up @@ -122,10 +123,11 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we can set up two idential optimization problems, except one has the `bound_transformer` variable set."
"Now we can set up two identical optimization problems, except one has the `bound_transformer` variable set."
]
},
{
Expand Down Expand Up @@ -182,10 +184,11 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"After both have completed we can plot to see how the objectives performed. It's quite obvious to see that the Sequential Domain Reduction technique contracted onto the optimal point relativly quickly."
"After both have completed we can plot to see how the objectives performed. It's quite obvious to see that the Sequential Domain Reduction technique contracted onto the optimal point relatively quick."
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion examples/sklearn_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def rfc_cv(n_estimators, min_samples_split, max_features, data, targets):
of cross validation is returned.
Our goal is to find combinations of n_estimators, min_samples_split, and
max_features that minimzes the log loss.
max_features that minimizes the log loss.
"""
estimator = RFC(
n_estimators=n_estimators,
Expand Down
3 changes: 2 additions & 1 deletion examples/visualization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -25,7 +26,7 @@
"\n",
"$$f(x) = e^{-(x - 2)^2} + e^{-\\frac{(x - 6)^2}{10}} + \\frac{1}{x^2 + 1}, $$ its maximum is at $x = 2$ and we will restrict the interval of interest to $x \\in (-2, 10)$.\n",
"\n",
"Notice that, in practice, this function is unknown, the only information we have is obtained by sequentialy probing it at different points. Bayesian Optimization works by contructing a posterior distribution of functions that best fit the data observed and chosing the next probing point by balancing exploration and exploitation."
"Notice that, in practice, this function is unknown, the only information we have is obtained by sequentially probing it at different points. Bayesian Optimization works by constructing a posterior distribution of functions that best fit the data observed and choosing the next probing point by balancing exploration and exploitation."
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion tests/test_bayesian_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def test_callback(event, instance):
optimizer._events[Events.OPTIMIZATION_START].values()
])

# Check that prime subscriptions won't overight manual subscriptions
# Check that prime subscriptions won't overwrite manual subscriptions
optimizer._prime_subscriptions()
assert all([
k == test_subscriber for k in
Expand Down
2 changes: 1 addition & 1 deletion tests/test_constraint.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from bayes_opt import BayesianOptimization, ConstraintModel
from bayes_opt import BayesianOptimization
from pytest import approx, raises
from scipy.optimize import NonlinearConstraint

Expand Down
2 changes: 1 addition & 1 deletion tests/test_seq_domain_red.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def dummy_function(x1, x2, x3, x4, x5):
trimmed_bounds = bounds_transformer._trim(new_bounds, global_bounds)
# check that the bounds are trimmed to the minimum window
# raises ValueError if the bounds are not trimmed correctly
bounds_transformer._window_bounds_compatiblity(trimmed_bounds)
bounds_transformer._window_bounds_compatibility(trimmed_bounds)


def test_exceeded_bounds():
Expand Down
14 changes: 7 additions & 7 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def brute_force_maximum(MESH, GP, kind='ucb', kappa=1.0, xi=1.0):
X, Y, GP, MESH = GLOB['x'], GLOB['y'], GLOB['gp'], GLOB['mesh']


def test_utility_fucntion():
def test_utility_function():
util = UtilityFunction(kind="ucb", kappa=1.0, xi=1.0)
assert util.kind == "ucb"

Expand All @@ -70,7 +70,7 @@ def test_utility_fucntion():

def test_acq_with_ucb():
util = UtilityFunction(kind="ucb", kappa=1.0, xi=1.0)
episilon = 1e-2
epsilon = 1e-2
y_max = 2.0

max_arg = acq_max(
Expand All @@ -83,12 +83,12 @@ def test_acq_with_ucb():
)
_, brute_max_arg = brute_force_maximum(MESH, GP, kind='ucb', kappa=1.0, xi=1.0)

assert all(abs(brute_max_arg - max_arg) < episilon)
assert all(abs(brute_max_arg - max_arg) < epsilon)


def test_acq_with_ei():
util = UtilityFunction(kind="ei", kappa=1.0, xi=1e-6)
episilon = 1e-2
epsilon = 1e-2
y_max = 2.0

max_arg = acq_max(
Expand All @@ -101,12 +101,12 @@ def test_acq_with_ei():
)
_, brute_max_arg = brute_force_maximum(MESH, GP, kind='ei', kappa=1.0, xi=1e-6)

assert all(abs(brute_max_arg - max_arg) < episilon)
assert all(abs(brute_max_arg - max_arg) < epsilon)


def test_acq_with_poi():
util = UtilityFunction(kind="poi", kappa=1.0, xi=1e-4)
episilon = 1e-2
epsilon = 1e-2
y_max = 2.0

max_arg = acq_max(
Expand All @@ -119,7 +119,7 @@ def test_acq_with_poi():
)
_, brute_max_arg = brute_force_maximum(MESH, GP, kind='poi', kappa=1.0, xi=1e-4)

assert all(abs(brute_max_arg - max_arg) < episilon)
assert all(abs(brute_max_arg - max_arg) < epsilon)


def test_logs():
Expand Down

0 comments on commit 04aea8b

Please sign in to comment.