Data Types & Structures
The following diagram showcases the type hierarchy of all BOSS inputs and hyperparameters.
![]() | ||||
This reminder of this page contains documentation for all exported types and structures.
Problem Definition
The BossProblem
structure contains the whole problem definition, the model definition, and the data together with the current parameter and hyperparameter values.
BOSS.BossProblem
— TypeBossProblem(; kwargs...)
Defines the whole optimization problem for the BOSS algorithm.
Problem Definition
There is some (noisy) blackbox function `y = f(x) = f_true(x) + ϵ` where `ϵ ~ Normal`.
We have some surrogate model `y = model(x) ≈ f_true(x)`
describing our knowledge (or lack of it) about the blackbox function.
We wish to find `x ∈ domain` such that `fitness(f(x))` is maximized
while satisfying the constraints `f(x) <= y_max`.
Keywords
fitness::Fitness
: TheFitness
function.f::Union{Function, Missing}
: The objective blackbox function.model::SurrogateModel
: TheSurrogateModel
.data::ExperimentData
: The initial data of objective function evaluations. SeeExperimentDataPrior
.domain::Domain
: TheDomain
ofx
.y_max::AbstractVector{<:Real}
: The constraints ony
. (See the definition above.)
See also: bo!
Fitness
The Fitness
type is used to define the fitness function $\text{fit}(y) \rightarrow \mathbb{R}$.
The NoFitness
can be used in problems without defined fitness (such as active learning problems). It is the default option used if no fitness is provided to BossProblem
. The NoFitness
can only be used with AcquisitionFunction
that does not require fitness.
The LinFitness
can be used to define a simple linear fitness function
\[\text{fit}(y) = \alpha^T y \;.\]
Using LinFitness
instead of NonlinFitness
may allow for simpler/faster computation of some acquisition functions.
The NonlinFitness
can be used to define an arbitrary fitness function
\[\text{fit}(y) \rightarrow \mathbb{R} \;.\]
BOSS.Fitness
— TypeAn abstract type for a fitness function measuring the quality of an output y
of the objective function.
Fitness is used by the AcquisitionFunction
to determine promising points for future evaluations.
All fitness functions should implement:
- (::CustomFitness)(y::AbstractVector{<:Real}) -> fitness::Real
An exception is the NoFitness
, which can be used for problem without a well defined fitness. In such case, an AcquisitionFunction
which does not depend on Fitness
must be used.
See also: NoFitness
, LinFitness
, NonlinFitness
, AcquisitionFunction
BOSS.NoFitness
— TypeNoFitness()
Placeholder for problems with no defined fitness.
BossProblem
defined with NoFitness
can only be solved with AcquisitionFunction
not dependent on Fitness
.
BOSS.LinFitness
— TypeLinFitness(coefs::AbstractVector{<:Real})
Used to define a linear fitness function measuring the quality of an output y
of the objective function.
May provide better performance than the more general NonlinFitness
as some acquisition functions can be calculated analytically with linear fitness functions whereas this may not be possible with a nonlinear fitness function.
See also: NonlinFitness
Example
A fitness function f(y) = y[1] + a * y[2] + b * y[3]
can be defined as:
julia> LinFitness([1., a, b])
BOSS.NonlinFitness
— TypeNonlinFitness(fitness::Function)
Used to define a general nonlinear fitness function measuring the quality of an output y
of the objective function.
If your fitness function is linear, use LinFitness
which may provide better performance.
See also: LinFitness
Example
julia> NonlinFitness(y -> cos(y[1]) + sin(y[2]))
Input Domain
The Domain
structure is used to define the input domain $x \in \text{Domain}$. The domain is formalized as
\[\begin{aligned} & lb < x < ub \\ & d_i \implies (x_i \in \mathbb{Z}) \\ & \text{cons}(x) > 0 \;. \end{aligned}\]
BOSS.Domain
— TypeDomain(; kwargs...)
Describes the optimization domain.
Keywords
bounds::AbstractBounds
: The basic box-constraints onx
. This field is mandatory.discrete::AbstractVector{<:Bool}
: Can be used to designate some dimensions of the domain as discrete.cons::Union{Nothing, Function}
: Used to define arbitrary nonlinear constraints onx
. Feasible pointsx
must satisfyall(cons(x) .> 0.)
. An appropriate acquisition maximizer which can handle nonlinear constraints must be used ifcons
is provided. (SeeAcquisitionMaximizer
.)
BOSS.AbstractBounds
— Typeconst AbstractBounds = Tuple{<:AbstractVector{<:Real}, <:AbstractVector{<:Real}}
Defines box constraints.
Example: ([0, 0], [1, 1]) isa AbstractBounds
Output Constraints
Constraints on output vector y
can be defined using the y_max
field. Providing y_max
to BossProblem
defines the linear constraints y < y_max
.
Arbitrary nonlinear constraints can be defined by augmenting the objective function. For example to define the constraint y[1] * y[2] < c
, one can define an augmented objective function
function f_c(x)
y = f(x) # the original objective function
y_c = [y..., y[1] * y[2]]
return y_c
end
and use
y_max = [fill(Inf, y_dim)..., c]
where y_dim
is the output dimension of the original objective function. Note that defining nonlinear constraints this way increases the output dimension of the objective function and thus the model definition has to be modified accordingly.
Surrogate Model
The surrogate model is defined using the SurrogateModel
type.
BOSS.SurrogateModel
— TypeAn abstract type for a surrogate model approximating the objective function.
Example usage: struct CustomModel <: SurrogateModel ... end
All models should implement:
make_discrete(model::CustomModel, discrete::AbstractVector{<:Bool}) -> discrete_model::CustomModel
model_posterior(model::CustomModel, data::ExperimentDataMAP) -> (x -> mean, std)
model_loglike(model::CustomModel, data::ExperimentData) -> (::ModelParams -> ::Real)
sample_params(model::CustomModel) -> ::ModelParams
param_priors(model::CustomModel) -> ::ParamPriors
Models may implement:
sliceable(::CustomModel) -> ::Bool
model_posterior_slice(model::CustomModel, data::ExperimentDataMAP, slice::Int) -> (x -> mean, std)
If sliceable(::CustomModel) == true
, then the model should additionally implement:
model_loglike_slice(model::SliceableModel, data::ExperimentData, slice::Int) -> (::ModelParams -> ::Real)
θ_slice(model::SliceableModel, idx::Int) -> Union{Nothing, UnitRange{<:Int}}
See also: LinModel
, NonlinModel
, GaussianProcess
, Semiparametric
The LinModel
and NonlinModel
structures are used to define parametric models. (Some compuatations are simpler/faster with linear model, so the LinModel
might provide better performance in the future. This functionality is not implemented yet, so using the NonlinModel
is equiavalent for now.)
BOSS.Parametric
— TypeAn abstract type for parametric surrogate models.
See also: LinModel
, NonlinModel
BOSS.LinModel
— TypeLinModel(; kwargs...)
A parametric surrogate model linear in its parameters.
This model definition will provide better performance than the more general 'NonlinModel' in the future. This feature is not implemented yet so it is equivalent to using NonlinModel
for now.
The linear model is defined as
ϕs = lift(x)
y = [θs[i]' * ϕs[i] for i in 1:m]
where
x = [x₁, ..., xₙ]
y = [y₁, ..., yₘ]
θs = [θ₁, ..., θₘ], θᵢ = [θᵢ₁, ..., θᵢₚ]
ϕs = [ϕ₁, ..., ϕₘ], ϕᵢ = [ϕᵢ₁, ..., ϕᵢₚ]
and $n, m, p ∈ R$.
Keywords
lift::Function
: Defines thelift
function(::Vector{<:Real}) -> (::Vector{Vector{<:Real}})
according to the definition above.theta_priors::AbstractVector{<:UnivariateDistribution}
: The prior distributions for the parameters[θ₁₁, ..., θ₁ₚ, ..., θₘ₁, ..., θₘₚ]
according to the definition above.noise_std_priors::NoiseStdPriors
: The prior distributions of the noise standard deviations of eachy
dimension.
BOSS.NonlinModel
— TypeNonlinModel(; kwargs...)
A parametric surrogate model.
If your model is linear, you can use LinModel
which will provide better performance in the future. (Not yet implemented.)
Define the model as y = predict(x, θ)
where θ
are the model parameters.
Keywords
predict::Function
: Thepredict
function according to the definition above.theta_priors::AbstractVector{<:UnivariateDistribution}
: The prior distributions for the model parameters.noise_std_priors::NoiseStdPriors
: The prior distributions of the noise standard deviations of eachy
dimension.
The GaussianProcess
structure is used to define a Gaussian process model. See [1] for more information about Gaussian processes.
BOSS.Nonparametric
— TypeNonparametric(; kwargs...)
Alias for GaussianProcess
.
BOSS.GaussianProcess
— TypeGaussianProcess(; kwargs...)
A Gaussian Process surrogate model. Each output dimension is modeled by a separate independent process.
Keywords
mean::Union{Nothing, Function}
: Used as the mean function for the GP. Defaults tonothing
equivalent tox -> zeros(y_dim)
.kernel::Kernel
: The kernel used in the GP. Defaults to theMatern32Kernel()
.length_scale_priors::LengthScalePriors
: The prior distributions for the length scales of the GP. Thelength_scale_priors
should be a vector ofy_dim
x_dim
-variate distributions wherex_dim
andy_dim
are the dimensions of the input and output of the model respectively.amp_priors::AmplitudePriors
: The prior distributions for the amplitude hyperparameters of the GP. Theamp_priors
should be a vector ofy_dim
univariate distributions.noise_std_priors::NoiseStdPriors
: The prior distributions of the noise standard deviations of eachy
dimension.
The Semiparametric
structure is used to define a semiparametric model combining the parametric and nonparametric (Gaussian process) models.
BOSS.Semiparametric
— TypeSemiparametric(; kwargs...)
A semiparametric surrogate model (a combination of a parametric model and Gaussian Process).
The parametric model is used as the mean of the Gaussian Process and all parameters and hyperparameters are estimated simultaneously.
Keywords
parametric::Parametric
: The parametric model used as the GP mean function.nonparametric::Nonparametric{Nothing}
: The outer GP model without mean.
Note that the parametric model must be defined without noise priors, and the nonparametric model must be defined without mean function.
Parameters & Hyperparameters
The BOSS.ModelParams
and BOSS.ParamPriors
type aliases are used throughout the package to pass around model (hyper)parameters and their priors. These types are only important for advanced usage of BOSS.jl. (E.g. implementing custom surrogate models.)
BOSS.ModelParams
— Typeconst ModelParams = Tuple{
<:Theta,
<:LengthScales,
<:Amplitudes,
<:NoiseStd,
}
Represents all model (hyper)parameters.
Example:
params = (nothing, [1.;π;; 1.;π;;], [1., 1.5], [0.1, 1.])
params isa BOSS.ModelParams
θ, λ, α, noise = params
θ isa BOSS.Theta
λ isa BOSS.LengthScales
α isa BOSS.Amplitudes
noise isa BOSS.NoiseStd
See: Theta
, LengthScales
, Amplitudes
, NoiseStd
BOSS.Theta
— Typeconst Theta = Union{Nothing, AbstractVector{<:Real}}
Parameters of the parametric model, or nothing
if the model is nonparametric.
Example: [1., 2., 3.] isa Theta
BOSS.LengthScales
— Typeconst LengthScales = Union{Nothing, <:AbstractMatrix{<:Real}}
Length scales of the GP as a x_dim
×y_dim
matrix, or nothing
if the model is purely parametric.
Example: [1.;5.;; 1.;5.;;] isa LengthScales
BOSS.Amplitudes
— Typeconst Amplitudes = Union{Nothing, <:AbstractVector{<:Real}}
Amplitudes of the GP, or nothing
if the model is purely parametric.
Example: [1., 5.] isa Amplitudes
BOSS.NoiseStd
— Typeconst NoiseStd = AbstractVector{<:Real}
Noise standard deviations of each y
dimension.
Example: [0.1, 1.] isa NoiseStd
BOSS.ParamPriors
— Typeconst ParamPriors = Tuple{
<:ThetaPriors,
<:LengthScalePriors,
<:AmplitudePriors,
<:NoiseStdPriors,
}
Represents all (hyper)parameter priors.
See: ThetaPriors
, LengthScalePriors
, AmplitudePriors
, NoiseStdPriors
BOSS.ThetaPriors
— Typeconst ThetaPriors = Union{Nothing, AbstractVector{<:UnivariateDistribution}}
Prior of Theta
.
BOSS.LengthScalePriors
— Typeconst LengthScalePriors = Union{Nothing, <:AbstractVector{<:MultivariateDistribution}}
Prior of LengthScales
.
BOSS.AmplitudePriors
— Typeconst AmplitudePriors = Union{Nothing, <:AbstractVector{<:UnivariateDistribution}}
Prior of Amplitudes
.
BOSS.NoiseStdPriors
— Typeconst NoiseStdPriors = AbstractVector{<:UnivariateDistribution}
Prior of NoiseStd
.
All (hyper)parameter priors are defined as a part of the surrogate model definition. All surrogate models share the noise_std_priors
field, but other priors may be missing depending on the particular model.
Experiment Data
The data from all past objective function evaluations as well as estimated parameter and/or hyperparameter values of the surrogate model are stored in the ExperimentData
types.
BOSS.ExperimentData
— TypeStores all the data collected during the optimization as well as the parameters and hyperparameters of the model.
See also: ExperimentDataPrior
, ExperimentDataPost
The ExperimentDataPrior
structure is used to pass the initial dataset to the BossProblem
.
BOSS.ExperimentDataPrior
— TypeStores the initial data.
At least one initial datapoint has to be provided (purely for implementation reasons). One can for example use LatinHypercubeSampling.jl to obtain a small intial grid, or provide a single random initial datapoint.
Fields
X::AbstractMatrix{<:Real}
: Contains the objective function inputs as columns.Y::AbstractMatrix{<:Real}
: Contains the objective function outputs as columns.
See also: ExperimentDataPost
The ExperimentDataPost
types contain the estimated model (hyper)parameters in addition to the dataset. The ExperimentDataMAP
structure contains the MAP estimate of the parameters in case a MAP model fitter is used, and the ExperimentDataBI
structure contains samples of the parameters in case a Bayesian inference model fitter is used.
BOSS.ExperimentDataPost
— TypeStores the fitted/samples model parameters in addition to the data matrices X
,Y
.
See also: ExperimentDataPrior
, ExperimentDataMAP
, ExperimentDataBI
BOSS.ExperimentDataMAP
— TypeStores the data matrices X
,Y
as well as the optimized model parameters and hyperparameters.
Fields
X::AbstractMatrix{<:Real}
: Contains the objective function inputs as columns.Y::AbstractMatrix{<:Real}
: Contains the objective function outputs as columns.params::ModelParams
: Contains MAP model (hyper)parameters.consistent::Bool
: True iff the parameters have been fitted using the current dataset (X
,Y
). Is set toconsistent = false
after updating the dataset, and toconsistent = true
after re-fitting the parameters.
See also: ExperimentDataBI
BOSS.ExperimentDataBI
— TypeStores the data matrices X
,Y
as well as the sampled model parameters and hyperparameters.
Fields
X::AbstractMatrix{<:Real}
: Contains the objective function inputs as columns.Y::AbstractMatrix{<:Real}
: Contains the objective function outputs as columns.params::AbstractVector{<:ModelParams}
: Contains samples of the model (hyper)parameters.consistent::Bool
: True iff the parameters have been fitted using the current dataset (X
,Y
). Is set toconsistent = false
after updating the dataset, and toconsistent = true
after re-fitting the parameters.
See also: ExperimentDataMAP
Model Fitter
The ModelFitter
type defines the algorithm used to estimate the model (hyper)parameters.
BOSS.ModelFitter
— TypeSpecifies the library/algorithm used for model parameter estimation. Inherit this type to define a custom model-fitting algorithms.
Example: struct CustomFitter <: ModelFitter{MAP} ... end
or struct CustomFitter <: ModelFitter{BI} ... end
All model fitters should implement: estimate_parameters(model_fitter::CustomFitter, problem::BossProblem; info::Bool)
.
This method should return a tuple (params, val)
. The returned params
should be a ModelParams
(if CustomAlg <: ModelFitter{MAP}
) or a AbstractVector{<:ModelParams}
(if CustomAlg <: ModelFitter{BI}
). The returned val
should be the log likelihood of the parameters (if CustomAlg <: ModelFitter{MAP}
), or a vector of log likelihoods of the individual parameter samples (if CustomAlg <: ModelFitter{BI}
), or nothing
.
See also: OptimizationMAP
, TuringBI
BOSS.ModelFit
— TypeAn abstract type used to differentiate between MAP
(Maximum A Posteriori) and BI
(Bayesian Inference) types.
The OptimizationMAP
model fitter can be used to utilize any optimization algorithm from the Optimization.jl package in order to find the MAP estimate of the (hyper)parameters. (See the example usage.)
BOSS.OptimizationMAP
— TypeOptimizationMAP(; kwargs...)
Finds the MAP estimate of the model parameters and hyperparameters using the Optimization.jl package.
Keywords
algorithm::Any
: Defines the optimization algorithm.multistart::Union{Int, Matrix{Float64}}
: The number of optimization restarts, or a vector of tuples(θ, λ, α)
containing initial (hyper)parameter values for the optimization runs.parallel::Bool
: Ifparallel=true
then the individual restarts are run in parallel.softplus_hyperparams::Bool
: Ifsoftplus_hyperparams=true
then the softplus function is applied to GP hyperparameters (length-scales & amplitudes) and noise deviations to ensure positive values during optimization.softplus_params::Union{Bool, Vector{Bool}}
: Defines to which parameters of the parametric model should the softplus function be applied to ensure positive values. Supplying a boolean instead of a binary vector turns the softplus on/off for all parameters. Defaults tofalse
meaning the softplus is applied to no parameters.
The TuringBI
model fitter can be used to utilize the Turing.jl library in order to sample the (hyper)parameters from the posterior given by the current dataset.
BOSS.TuringBI
— TypeTuringBI(; kwargs...)
Samples the model parameters and hyperparameters using the Turing.jl package.
Keywords
sampler::Any
: The sampling algorithm used to draw the samples.warmup::Int
: The amount of initial unused 'warmup' samples in each chain.samples_in_chain::Int
: The amount of samples used from each chain.chain_count::Int
: The amount of independent chains sampled.leap_size
: Everyleap_size
-th sample is used from each chain. (To avoid correlated samples.)parallel
: Ifparallel=true
then the chains are sampled in parallel.
Sampling Process
In each sampled chain;
- The first
warmup
samples are discarded. - From the following
leap_size * samples_in_chain
samples eachleap_size
-th is kept.
Then the samples from all chains are concatenated and returned.
Total drawn samples: 'chaincount * (warmup + leapsize * samplesinchain)' Total returned samples: 'chaincount * samplesin_chain'
The SamplingMAP
model fitter preforms MAP estimation by sampling the parameters from their priors and maximizing the posterior probability over the samples. This is a trivial model fitter suitable for simple experimentation with BOSS.jl and/or Bayesian optimization. A more sophisticated model fitter such as OptimizationMAP
or TuringBI
should be used to solve real problems.
BOSS.SamplingMAP
— TypeSamplingMAP()
Optimizes the model parameters by sampling them from their prior distributions and selecting the best sample in sense of MAP.
Keywords
samples::Int
: The number of drawn samples.parallel::Bool
: The sampling is performed in parallel ifparallel=true
.
The RandomMAP
model fitter samples random parameter values from their priors. It does NOT optimize for the most probable parameters in any way. This model fitter is provided solely for easy experimentation with BOSS.jl and should not be used to solve problems.
BOSS.RandomMAP
— TypeRandomMAP()
Returns random model parameters sampled from their respective priors.
Can be useful with RandomSelectAM
to avoid unnecessary model parameter estimations.
The SampleOptMAP
model fitter combines the SamplingMAP
and OptimizationMAP
. It first samples many model parameter samples from their priors, and subsequently runs multiple optimization runs initiated at the best samples.
BOSS.SampleOptMAP
— TypeSampleOptMAP(; kwargs...)
SampleOptMAP(::SamplingMAP, ::OptimizationMAP)
Combines SamplingMAP
and OptimizationMAP
to first sample many parameter samples from the prior, and subsequently start multiple optimization runs initialized from the best samples.
Keywords
samples::Int
: The number of drawn samples.algorithm::Any
: Defines the optimization algorithm.multistart::Int
: The number of optimization restarts.parallel::Bool
: Ifparallel=true
, then both the sampling and the optimization are performed in parallel.softplus_hyperparams::Bool
: Ifsoftplus_hyperparams=true
then the softplus function is applied to GP hyperparameters (length-scales & amplitudes) and noise deviations to ensure positive values during optimization.softplus_params::Union{Bool, Vector{Bool}}
: Defines to which parameters of the parametric model should the softplus function be applied to ensure positive values. Supplying a boolean instead of a binary vector turns the softplus on/off for all parameters. Defaults tofalse
meaning the softplus is applied to no parameters.
Acquisition Maximizer
The AcquisitionMaximizer
type is used to define the algorithm used to maximize the acquisition function.
BOSS.AcquisitionMaximizer
— TypeSpecifies the library/algorithm used for acquisition function optimization. Inherit this type to define a custom acquisition maximizer.
Example: struct CustomAlg <: AcquisitionMaximizer ... end
All acquisition maximizers should implement: maximize_acquisition(acq_maximizer::CustomAlg, acq::AcquisitionFunction, problem::BossProblem, options::BossOptions)
.
This method should return a tuple (x, val)
. The returned x
is the point of the input domain which maximizes the given acquisition function acq
(as a vector), or a batch of points (as a column-wise matrix). The returned val
is the acquisition value acq(x)
, or the values acq.(eachcol(x))
for each point of the batch, or nothing
(depending on the acquisition maximizer implementation).
See also: OptimizationAM
The OptimizationAM
can be used to utilize any optimization algorithm from the Optimization.jl package.
BOSS.OptimizationAM
— TypeOptimizationAM(; kwargs...)
Maximizes the acquisition function using the Optimization.jl library.
Can handle constraints on x
if according optimization algorithm is selected.
Keywords
algorithm::Any
: Defines the optimization algorithm.multistart::Union{<:Int, <:AbstractMatrix{<:Real}}
: The number of optimization restarts, or a matrix of optimization intial points as columns.parallel::Bool
: Ifparallel=true
then the individual restarts are run in parallel.autodiff:SciMLBase.AbstractADType:
: The automatic differentiation module passed toOptimization.OptimizationFunction
.kwargs...
: Other kwargs are passed to the optimization algorithm.
The GridAM
maximizes the acquisition function by evaluating all points on a fixed grid of points. This is a trivial acquisition maximizer suitable for simple experimentation with BOSS.jl and/or Bayesian optimization. More sophisticated acquisition maximizers such as OptimizationAM
should be used to solve real problems.
BOSS.GridAM
— TypeGridAM(kwargs...)
Maximizes the acquisition function by checking a fine grid of points from the domain.
Extremely simple optimizer which can be used for simple problems or for debugging. Not suitable for problems with high dimensional domain.
Can be used with constraints on x
.
Keywords
problem::BossProblem
: Provide your defined optimization problem.steps::Vector{Float64}
: Defines the size of the grid gaps in eachx
dimension.parallel::Bool
: Ifparallel=true
, the optimization is parallelized. Defaults totrue
.shuffle::Bool
: Ifshuffle=true
, the grid points are shuffled before each optimization. Defaults totrue
.
The SamplingAM
samples random candidate points from the given x_prior
distribution and selects the sample with maximal acquisition value.
BOSS.SamplingAM
— TypeSamplingAM(; kwargs...)
Optimizes the acquisition function by sampling candidates from the user-provided prior, and returning the sample with the highest acquisition value.
Keywords
x_prior::MultivariateDistribution
: The prior over the input domain used to sample candidates.samples::Int
: The number of samples to be drawn and evaluated.parallel::Bool
: Ifparallel=true
then the sampling is parallelized. Defaults totrue
.
The RandomAM
simply returns a random point. It does NOT perform any optimization. This acquisition maximizer is provided solely for easy experimentation with BOSS.jl and should not be used to solve problems.
BOSS.RandomAM
— TypeRandomAM()
Selects a random interior point instead of maximizing the acquisition function. Can be used for method comparison.
Can handle constraints on x
, but does so by generating random points in the box domain until a point satisfying the constraints is found. Therefore it can take a long time or even get stuck if the constraints are very tight.
The GivenPointAM
always return the same evaluation point predefined by the user. The GivenSequenceAM
returns the predefined sequence of evaluation points and throws an error once it runs out of points. These dummy acquisition maximizers are useful for controlled experiments.
BOSS.GivenPointAM
— TypeGivenPointAM(x::Vector{...})
A dummy acquisition maximizer that always returns predefined point x
.
See Also
BOSS.GivenSequenceAM
— TypeGivenSequenceAM(X::Matrix{...})
GivenSequenceAM(X::Vector{Vector{...}})
A dummy acquisition maximizer that returns the predefined sequence of points in the given order. The maximizer throws an error if it runs out of points in the sequence.
See Also
The SampleOptAM
samples many candidate points from the given x_prior
distribution, and subsequently performs multiple optimization runs initiated from the best samples.
BOSS.SampleOptAM
— TypeSampleOptAM(; kwargs...)
Optimizes the acquisition function by first sampling candidates from the user-provided prior, and then running multiple optimization runs initiated from the samples with the highest acquisition values.
Keywords
x_prior::MultivariateDistribution
: The prior over the input domain used to sample candidates.samples::Int
: The number of samples to be drawn and evaluated.algorithm::Any
: Defines the optimization algorithm.multistart::Int
: The number of optimization restarts.parallel::Bool
: Ifparallel=true
, both the sampling and individual optimization runs are performed in parallel.autodiff:SciMLBase.AbstractADType:
: The automatic differentiation module passed toOptimization.OptimizationFunction
.kwargs...
: Other kwargs are passed to the optimization algorithm.
The SequentialBatchAM
can be used as a wrapper of any of the other acquisition maximizers. It returns a batch of promising points for future evaluations instead of a single point, and thus allows for evaluation of the objective function in batches.
BOSS.SequentialBatchAM
— TypeSequentialBatchAM(::AcquisitionMaximizer, ::Int)
SequentialBatchAM(; am, batch_size)
Provides multiple candidates for batched objective function evaluation.
Selects the candidates sequentially by iterating the following steps:
- Use the 'inner' acquisition maximizer to select a candidate
x
.
- Use the 'inner' acquisition maximizer to select a candidate
- Extend the dataset with a 'speculative' new data point
x
and the posterior predictive mean of the surrogateŷ
.- If
batch_size
candidates have been selected, return them.
- If
Keywords
am::AcquisitionMaximizer
: The inner acquisition maximizer.batch_size::Int
: The number of candidates to be selected.
Acquisition Function
The acquisition function is defined using the AcquisitionFunction
type.
BOSS.AcquisitionFunction
— TypeSpecifies the acquisition function describing the "quality" of a potential next evaluation point. Inherit this type to define a custom acquisition function.
Example: struct CustomAcq <: AcquisitionFunction ... end
All acquisition functions should implement: (acquisition::CustomAcq)(problem::BossProblem, options::BossOptions)
This method should return a function acq(x::AbstractVector{<:Real}) = val::Real
, which is maximized to select the next evaluation function of blackbox function in each iteration.
See also: ExpectedImprovement
The ExpectedImprovement
defines the expected improvement acquisition function. See [1] for more information.
BOSS.ExpectedImprovement
— TypeExpectedImprovement(; kwargs...)
The expected improvement (EI) acquisition function.
Fitness function must be defined as a part of the problem definition in order to use EI. (See Fitness
.)
Measures the quality of a potential evaluation point x
as the expected improvement in best-so-far achieved fitness by evaluating the objective function at y = f(x)
.
In case of constrained problems, the expected improvement is additionally weighted by the probability of feasibility of y
. I.e. the probability that all(cons(y) .> 0.)
.
If the problem is constrained on y
and no feasible point has been observed yet, then the probability of feasibility alone is returned as the acquisition function.
Rather than using the actual evaluations (xᵢ,yᵢ)
from the dataset, the best-so-far achieved fitness is calculated as the maximum fitness among the means ̂yᵢ
of the posterior predictive distribution of the model evaluated at xᵢ
. This is a simple way to handle evaluation noise which may not be suitable for problems with substantial noise. In case of Bayesian Inference, an averaged posterior of the model posterior samples is used for the prediction of ŷᵢ
.
Keywords
ϵ_samples::Int
: Controls how many samples are used to approximate EI. Theϵ_samples
keyword is ignored unlessMAP
model fitter andNonlinFitness
are used! In case ofBI
model fitter, the number of samples is instead set equal to the number of posterior samples. In case ofLinearFitness
, the expected improvement can be calculated analytically.cons_safe::Bool
: If set to true, the acquisition functionacq(x)
is made 'constraint-safe' by checking the bounds and constraints during each evaluation. Setcons_safe
totrue
if the evaluation of the model at exterior points may cause errors or nonsensical values. You may setcons_safe
tofalse
if the evaluation of the model at exterior points can provide useful information to the acquisition maximizer and does not cause errors. Defaults totrue
.
Termination Conditions
The TermCond
type is used to define the termination condition of the BO procedure.
BOSS.TermCond
— TypeSpecifies the termination condition of the whole BOSS algorithm. Inherit this type to define a custom termination condition.
Example: struct CustomCond <: TermCond ... end
All termination conditions should implement: (cond::CustomCond)(problem::BossProblem)
This method should return true to keep the optimization running and return false once the optimization is to be terminated.
See also: IterLimit
The NoLimit
can be used to let the algorithm run indefinitely.
BOSS.NoLimit
— TypeNoLimit()
Never terminates.
The IterLimit
terminates the procedure after a predefined number of iterations.
BOSS.IterLimit
— TypeIterLimit(iter_max::Int)
Terminates the BOSS algorithm after predefined number of iterations.
See also: bo!
Miscellaneous
The BossOptions
structure is used to define miscellaneous hyperparameters of the BOSS.jl package.
BOSS.BossOptions
— TypeBossOptions(; kwargs...)
Stores miscellaneous settings of the BOSS algorithm.
Keywords
info::Bool
: Settinginfo=false
silences the BOSS algorithm.debug::Bool
: Setdebug=true
to print stactraces of caught optimization errors.parallel_evals::Symbol
: Possible values::serial
,:parallel
,:distributed
. Defaults to:parallel
. Determines whether to run multiple objective function evaluations within one batch in serial, parallel, or distributed fashion. (Only has an effect if batching AM is used.)callback::BossCallback
: If provided,callback(::BossProblem; kwargs...)
will be called before the BO procedure starts and after every iteration.
See also: bo!
The BossCallback
type is used to pass callbacks which will be called in every iteration of the BO procedure (and once before the procedure starts).
BOSS.BossCallback
— TypeIf a BossCallback
is provided to BossOptions
, the callback is called once before the BO procedure starts, and after each iteration.
All callbacks should implement:
- (::CustomCallback)(::BossProblem; ::ModelFitter, ::AcquisitionMaximizer, ::AcquisitionFunction, ::TermCond, ::BossOptions, first::Bool, )
The kwarg first
is true only on the first callback before the BO procedure starts.
See PlotCallback
for an example usage of a callback for plotting.
BOSS.NoCallback
— TypeNoCallback()
Does nothing.
The PlotCallback
provides plots the state of the BO procedure in every iteration. It currently only supports one-dimensional input spaces.
BOSS.PlotCallback
— TypePlotOptions(Plots; kwargs...)
If PlotOptions
is passed to BossOptions
as callback
, the state of the optimization problem is plotted in each iteration. Only works with one-dimensional x
domains but supports multi-dimensional y
.
Arguments
Plots::Module
: Evaluateusing Plots
and pass thePlots
module toPlotsOptions
.
Keywords
f_true::Union{Nothing, Function}
: The true objective function to be plotted.points::Int
: The number of points in each plotted function.xaxis::Symbol
: Used to change the x axis scale (:identity
,:log
).yaxis::Symbol
: Used to change the y axis scale (:identity
,:log
).title::String
: The plot title.
References
[1] Bobak Shahriari et al. “Taking the human out of the loop: A review of Bayesian optimization”. In: Proceedings of the IEEE 104.1 (2015), pp. 148–175