Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f4b4c10
Repository was moved to https://github.com/NREL/bbopt
Jun 24, 2024
c2bb6ab
Fix problem 26 in GOSAC benchmark
Jun 21, 2024
d940b09
Update copyright information
Jun 21, 2024
1ba9f5f
Update to version 0.4.0
Jun 21, 2024
56a11fd
Update documentation and license
Jun 24, 2024
f57e986
Create gh-pages.yml
weslleyspereira Jun 24, 2024
7f99475
Push to test gh-pages
Jun 24, 2024
0106e27
Update gh-pages.yml
weslleyspereira Jun 24, 2024
fee9e5b
Limit version of numpy because of pymoo
Jun 24, 2024
5dfe689
Adds more requirements to the sphinx docs
Jun 24, 2024
7476f7d
Move pages to https://nrel.github.io/bbopt
Jun 24, 2024
9d43fd7
Update to v0.4.1
Jun 24, 2024
61f5677
Add more kernel functions to the RBF model
Jun 28, 2024
c7c1eec
Fix bug in the target_value_optimization
Jun 28, 2024
11ee6fe
Merge branch 'main' into improve_rbf
weslleyspereira Jun 28, 2024
4e76af2
Adds smoothing parameter as an option to the RBF model
Jun 28, 2024
8df0af0
Adds scaling of ranges to improve conditioning
Jun 29, 2024
eb553b1
Adds epsilon param to complete kernels
Jul 9, 2024
937e90b
Fixes bugs in the mu meas and jac of RBF
Jul 9, 2024
ee17caa
Revert f4b4c105dce5d26e00f3135fc88e7051c518fe4e
Jul 9, 2024
5f8210e
Merge branch 'main' into improve_rbf
weslleyspereira Jul 11, 2024
10b019d
Create dir if doesnt exist in vlse_bench
weslleyspereira Jul 11, 2024
91e7a0a
Adds more tests to RBF and improve docs
Jul 11, 2024
cdeed1f
Be more flexible in the GOSAC benchmark. Delete wrong known info
Jul 11, 2024
2997278
Avoids recomputing scaled x by keeping it as an attribute
Aug 14, 2024
40b933d
Update to v0.4.2
Aug 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,31 @@ Surrogate models and active learning for scientific applications.

## Building

This project uses [pdm](https://pdm-project.org/en/stable/) as its package manager. With pdm installed, run `pdm install` at the root of this repository to install the dependencies. The file [pyproject.toml](pyproject.toml) has the list of dependencies and configurations for the project. Use `pdm build` to build the project. The build artifacts will be in the `dist` directory. Please, find more information about pdm in its website.
### Binaries

The binaries for the latest version are available at https://github.com/NREL/bbopt/releases/latest. They can be installed through standard installation, e.g.,

using pip (https://pip.pypa.io/en/stable/cli/pip_install/):

```sh
python -m pip install
https://github.com/NREL/bbopt/archive/refs/tags/v0.4.2.tar.gz
```

using conda (https://docs.anaconda.com/working-with-conda/packages/install-packages/):

```sh
conda install
https://github.com/NREL/bbopt/archive/refs/tags/v0.4.2.tar.gz
```

### From source

This package contains a [pyproject.toml](pyproject.toml) with the list of requirements and dependencies (More about `pyproject.toml` at https://packaging.python.org/en/latest/specifications/pyproject-toml/). This project is configured to use the package manager [pdm](https://pdm-project.org/en/stable/). With pdm installed, run `pdm install` at the root of this repository to install the dependencies. The file [pyproject.toml](pyproject.toml) has the list of dependencies and configurations for the project. Use `pdm build` to build the packages binaries in the `dist` directory. Then follow the steps in the [Binaries section](#binaries) to install.

### For developers

Install the package manager [pdm](https://pdm-project.org/en/stable/). To install all the dependencies listted in the [pyproject.toml](pyproject.toml), run `pdm install`.

## Documentation

Expand Down
2 changes: 1 addition & 1 deletion blackboxopt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

__all__ = ["acquisition", "optimize", "sampling", "rbf"]
__version__ = "0.4.1"
__version__ = "0.4.2"

from . import acquisition
from . import optimize
Expand Down
50 changes: 19 additions & 31 deletions blackboxopt/acquisition.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"Haoyu Jia",
"Weslley S. Pereira",
]
__version__ = "0.4.1"
__version__ = "0.4.2"
__deprecated__ = False

import numpy as np
Expand All @@ -53,7 +53,7 @@

# Local imports
from .sampling import NormalSampler, Sampler
from .rbf import RbfModel, RbfType
from .rbf import RbfModel, RbfKernel
from .problem import (
ProblemWithConstraint,
ProblemNoConstraint,
Expand Down Expand Up @@ -376,13 +376,13 @@ def acquire(
# Evaluate candidates
if not listOfSurrogates:
samples = surrogateModel.samples()
fx, _ = surrogateModel.eval(x)
fx, _ = surrogateModel(x)
else:
samples = surrogateModel[0].samples()
objdim = len(surrogateModel)
fx = np.empty((nCand, objdim))
for i in range(objdim):
fx[:, i], _ = surrogateModel[i].eval(x)
fx[:, i], _ = surrogateModel[i](x)

# Create scaled x and scaled distx
xlow = np.array([bounds[i][0] for i in range(dim)])
Expand Down Expand Up @@ -494,13 +494,13 @@ def acquire(
# Evaluate candidates
if not listOfSurrogates:
samples = surrogateModel.samples()
fx, _ = surrogateModel.eval(x)
fx, _ = surrogateModel(x)
else:
samples = surrogateModel[0].samples()
objdim = len(surrogateModel)
fx = np.empty((nCand, objdim))
for i in range(objdim):
fx[:, i], _ = surrogateModel[i].eval(x)
fx[:, i], _ = surrogateModel[i](x)

# Create scaled x and scaled distx
xlow = np.array([bounds[i][0] for i in range(dim)])
Expand Down Expand Up @@ -601,7 +601,7 @@ def acquire(
else np.random.choice(self.cycleLength + 2)
)
if sample_stage == 0: # InfStep - minimize Mu_n
LDLt = ldl(surrogateModel.get_RBFmatrix())
LDLt = ldl(surrogateModel.get_RBFmatrix(smoothing=0))
problem = ProblemWithConstraint(
lambda x: surrogateModel.mu_measure(x, LDLt=LDLt),
lambda x: self.tol
Expand Down Expand Up @@ -636,7 +636,7 @@ def acquire(
assert len(fbounds) == 2
# find min of surrogate model
problem = ProblemNoConstraint(
lambda x: surrogateModel.eval(x)[0],
lambda x: surrogateModel(x)[0],
bounds,
surrogateModel.iindex,
)
Expand All @@ -657,7 +657,7 @@ def acquire(
) # target for objective function value

# use GA method to minimize bumpiness measure
LDLt = ldl(surrogateModel.get_RBFmatrix())
LDLt = ldl(surrogateModel.get_RBFmatrix(smoothing=0))
problem = ProblemWithConstraint(
lambda x: surrogateModel.bumpiness_measure(
x, f_target, LDLt
Expand Down Expand Up @@ -691,7 +691,7 @@ def acquire(
assert len(fbounds) == 2
# find the minimum of RBF surface
problem = ProblemNoConstraint(
lambda x: surrogateModel.eval(x)[0],
lambda x: surrogateModel(x)[0],
bounds,
surrogateModel.iindex,
)
Expand Down Expand Up @@ -723,7 +723,7 @@ def acquire(
fbounds[0]
) # target value
# use GA method to minimize bumpiness measure
LDLt = ldl(surrogateModel.get_RBFmatrix())
LDLt = ldl(surrogateModel.get_RBFmatrix(smoothing=0))
problem = ProblemWithConstraint(
lambda x: surrogateModel.bumpiness_measure(
x, f_target, LDLt
Expand Down Expand Up @@ -871,9 +871,7 @@ def acquire(
].T

# Evaluate the surrogate model on the candidate points and sort them
fcand[iStart:iEnd], _ = surrogateModel.eval(
candidates[iStart:iEnd, :]
)
fcand[iStart:iEnd], _ = surrogateModel(candidates[iStart:iEnd, :])
ids = np.argsort(fcand[0:iEnd])
remevals -= iEnd - iStart

Expand All @@ -899,26 +897,18 @@ def acquire(
def func_continuous_search(x):
x_ = xi.copy()
x_[cindex] = x
return surrogateModel.eval(x_)[0]
return surrogateModel(x_)[0]

def dfunc_continuous_search(x):
x_ = xi.copy()
x_[cindex] = x
return surrogateModel.jac(x_)[cindex]

# def hessp_continuous_search(x, p):
# x_ = xi.copy()
# x_[cindex] = x
# p_ = np.zeros(dim)
# p_[cindex] = p
# return surrogateModel.hessp(x_, p_)[cindex]

res = minimize(
func_continuous_search,
xi[cindex],
method="L-BFGS-B",
jac=dfunc_continuous_search,
# hessp=hessp_continuous_search,
bounds=cbounds,
options={
"maxfun": remevals,
Expand Down Expand Up @@ -1025,7 +1015,7 @@ def pareto_front_target(self, paretoFront: np.ndarray) -> np.ndarray:
assert objdim > 1

# Create a surrogate model for the Pareto front in the objective space
paretoModel = RbfModel(RbfType.LINEAR)
paretoModel = RbfModel(kernel=RbfKernel.LINEAR)
k = np.random.choice(objdim)
paretoModel.update_samples(
np.array([paretoFront[:, i] for i in range(objdim) if i != k]).T
Expand All @@ -1046,13 +1036,13 @@ def pareto_front_target(self, paretoFront: np.ndarray) -> np.ndarray:
)

def delta_f(tau):
tauk, _ = paretoModel.eval(tau)
tauk, _ = paretoModel(tau)
_tau = np.concatenate((tau[0:k], tauk, tau[k:]))
return -tree.query(_tau)[0]

# Minimize delta_f
res = differential_evolution(delta_f, boundsPareto)
tauk, _ = paretoModel.eval(res.x)
tauk, _ = paretoModel(res.x)
tau = np.concatenate((res.x[0:k], tauk, res.x[k:]))

return tau
Expand Down Expand Up @@ -1175,7 +1165,7 @@ def acquire(
endpoints = np.empty((objdim, dim))
for i in range(objdim):
minimumPointProblem = ProblemNoConstraint(
lambda x: surrogateModels[i].eval(x)[0], bounds, iindex
lambda x: surrogateModels[i](x)[0], bounds, iindex
)
res = pymoo_minimize(
minimumPointProblem,
Expand Down Expand Up @@ -1421,9 +1411,7 @@ def acquire(
fnondominatedAndBestCandidates = np.concatenate(
(
paretoFront,
np.array(
[s.eval(bestCandidates)[0] for s in surrogateModels]
).T,
np.array([s(bestCandidates)[0] for s in surrogateModels]).T,
),
axis=0,
)
Expand Down Expand Up @@ -1508,7 +1496,7 @@ def acquire(
cheapProblem = ProblemWithConstraint(
self.fun,
lambda x: np.transpose(
[surrogateModels[i].eval(x)[0] for i in range(gdim)]
[surrogateModels[i](x)[0] for i in range(gdim)]
),
bounds,
iindex,
Expand Down
16 changes: 10 additions & 6 deletions blackboxopt/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"Haoyu Jia",
"Weslley S. Pereira",
]
__version__ = "0.4.1"
__version__ = "0.4.2"
__deprecated__ = False

from typing import Callable, Optional, Union
Expand Down Expand Up @@ -781,9 +781,9 @@ def multistart_stochastic_response_surface(
if out_local.fx < out.fx:
out.x[:] = out_local.x
out.fx = out_local.fx
out.samples[
out.nfev : out.nfev + out_local.nfev, :
] = out_local.samples
out.samples[out.nfev : out.nfev + out_local.nfev, :] = (
out_local.samples
)
out.fsamples[out.nfev : out.nfev + out_local.nfev] = out_local.fsamples
out.nfev = out.nfev + out_local.nfev

Expand Down Expand Up @@ -898,7 +898,11 @@ def target_value_optimization(

# max value of f
if surrogateModel.nsamples() - out.nfev > 0:
maxf = np.max(surrogateModel.get_fsamples()[: -out.nfev]).item()
maxf = np.max(
surrogateModel.get_fsamples()[
0 : surrogateModel.nsamples() - out.nfev
]
).item()
else:
maxf = -np.Inf
if out.nfev > 0:
Expand Down Expand Up @@ -1681,7 +1685,7 @@ def gosac(
# Evaluate the surrogate at the best candidates
sCandidates = np.empty((len(bestCandidates), gdim))
for i in range(gdim):
sCandidates[:, i], _ = surrogateModels[i].eval(bestCandidates)
sCandidates[:, i], _ = surrogateModels[i](bestCandidates)

# Find the minimum number of constraint violations
constraintViolation = [
Expand Down
6 changes: 3 additions & 3 deletions blackboxopt/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
__maintainer__ = "Weslley S. Pereira"
__email__ = "weslley.dasilvapereira@nrel.gov"
__credits__ = ["Weslley S. Pereira"]
__version__ = "0.4.1"
__version__ = "0.4.2"
__deprecated__ = False

import numpy as np
Expand Down Expand Up @@ -161,7 +161,7 @@ def _evaluate(self, X, out):
out["F"] = np.empty((x.shape[0], self.n_obj))
for i in range(self.n_obj):
out["F"][:, i] = np.absolute(
self.surrogateModels[i].eval(x)[0] - self.tau[i]
self.surrogateModels[i](x)[0] - self.tau[i]
)


Expand All @@ -185,4 +185,4 @@ def _evaluate(self, X, out):
x = _dict_to_array(X)
out["F"] = np.empty((x.shape[0], self.n_obj))
for i in range(self.n_obj):
out["F"][:, i] = self.surrogateModels[i].eval(x)[0]
out["F"][:, i] = self.surrogateModels[i](x)[0]
Loading