Skip to main content

Bobyqa

Struct Bobyqa 

Source
pub struct Bobyqa<Mode = Bounded, F = f64> { /* private fields */ }
Expand description

BOBYQA (Powell 2009): bound-constrained model-based derivative-free trust-region optimization.

Configure the trust-region radii and interpolation-set size, then drive it with an Executor over a BobyqaState on a problem that implements CostFunction + BoxConstraints:

use basin::{BoxConstraints, CostFunction, Executor, Bobyqa, BobyqaState, MaxCostEvals};

struct Booth {
    lower: Vec<f64>,
    upper: Vec<f64>,
}
impl CostFunction for Booth {
    type Param = Vec<f64>;
    type Output = f64;
    type Error = std::convert::Infallible;
    fn cost(&self, x: &Vec<f64>) -> Result<f64, std::convert::Infallible> {
        Ok((x[0] + 2.0 * x[1] - 7.0).powi(2) + (2.0 * x[0] + x[1] - 5.0).powi(2))
    }
}
impl BoxConstraints for Booth {
    fn lower(&self) -> &Vec<f64> { &self.lower }
    fn upper(&self) -> &Vec<f64> { &self.upper }
}

let problem = Booth { lower: vec![-5.0, -5.0], upper: vec![5.0, 5.0] };
let solver = Bobyqa::new().with_rho_beg(0.5).with_rho_end(1e-8);
let state = BobyqaState::new(vec![0.0, 0.0]);
let result = Executor::new(problem, solver, state)
    .terminate_on(MaxCostEvals(500))
    .run()
    .unwrap();
assert!(result.best_param()[0].is_finite());

§Configuration

  • with_rho_beg — initial trust-region radius ρ_beg (default 1.0). Also the initial Δ. The initial sampling needs room b_i ≥ a_i + 2ρ_beg (Powell 2009, eq. 2.1); if ρ_beg is too large for a narrow box it is reduced to min(b_i − a_i)/4 (with ρ_end pulled down to match), mirroring PRIMA rather than rejecting the solve.
  • with_rho_end — final radius ρ_end (default 1e-6); must satisfy ρ_beg > ρ_end > 0.
  • with_npt — interpolation-set size npt, in [2n+1, ½(n+1)(n+2)] (default 2n+1).

§Panics

Executor::run panics (in init) if the start point is empty, if npt is outside [2n+1, ½(n+1)(n+2)] (the n+2 ≤ npt ≤ 2n partial-model regime is not yet implemented), or if after the narrow-box revision ρ_beg > ρ_end > 0 cannot hold (e.g. a degenerate b_i = a_i).

§RESCUE

The full method of RESCUE (Powell 2009, §5 — restoring the interpolation set when rounding damages the update denominator) is implemented and wired, but it fires only on severely ill-conditioned geometry. As Powell and PRIMA both note, it is essentially never invoked on well-behaved problems without heavy noise on the objective; expect it to stay dormant in normal use.

§Backends

Backend-generic over the parameter vector: Vec<f64>, nalgebra, ndarray, and faer all work — the parameter type needs only Clone, VectorLen, and Index/IndexMut element access. The model algebra is internal pure-Rust Vec<f64> scratch, so no linalg-tier op is required. wasm-clean.

§References

M. J. D. Powell, The BOBYQA algorithm for bound constrained optimization without derivatives, DAMTP report 2009/NA06, University of Cambridge. Cross-validated against PRIMA v0.7.2.

Implementations§

Source§

impl<F: Scalar> Bobyqa<Bounded, F>

Source

pub fn new() -> Self

A BOBYQA solver with the default schedule (ρ_beg = 1, ρ_end = 1e-6, npt = 2n+1). Tune with the with_* builders.

Source

pub fn with_rho_beg(self, rho_beg: F) -> Self

Set the initial trust-region radius ρ_beg (also the initial Δ).

Source

pub fn with_rho_end(self, rho_end: F) -> Self

Set the final trust-region radius ρ_end. Must satisfy ρ_beg > ρ_end > 0.

Source

pub fn with_npt(self, npt: usize) -> Self

Set the interpolation-set size npt, in [2n+1, ½(n+1)(n+2)]. Defaults to 2n+1 when unset.

Trait Implementations§

Source§

impl<F: Scalar> Default for Bobyqa<Bounded, F>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<V, F> InitialState<V> for Bobyqa<Bounded, F>
where F: Scalar, V: Clone,

Source§

type State = BobyqaState<V, F>

State shape this solver iterates against.
Source§

fn seed(&self, x: &V) -> Self::State

Build a fresh state seeded at x using the solver’s natural default scale.
Source§

impl<P, V, F> Solver<P, BobyqaState<V, F>> for Bobyqa<Bounded, F>
where F: Scalar, P: CostFunction<Param = V, Output = F> + BoxConstraints, V: Clone + VectorLen + Index<usize, Output = F> + IndexMut<usize, Output = F>,

Source§

type Error = <P as CostFunction>::Error

Hard-abort error type — mirrors the underlying problem’s type Error. See the trait docs.
Source§

fn init( &mut self, problem: &mut Problem<P>, state: BobyqaState<V, F>, ) -> Result<BobyqaState<V, F>, Self::Error>

One-time setup before the iteration loop. Read more
Source§

fn next_iter( &mut self, problem: &mut Problem<P>, state: BobyqaState<V, F>, ) -> Result<(BobyqaState<V, F>, Option<TerminationReason>), Self::Error>

Advance one iteration. Read more
Source§

fn terminate(&self, _state: &S) -> Option<TerminationReason>

Optional pre-iteration solver-specific termination test. Read more

Auto Trait Implementations§

§

impl<Mode, F> Freeze for Bobyqa<Mode, F>
where F: Freeze,

§

impl<Mode, F> RefUnwindSafe for Bobyqa<Mode, F>
where F: RefUnwindSafe,

§

impl<Mode, F> Send for Bobyqa<Mode, F>
where F: Send,

§

impl<Mode, F> Sync for Bobyqa<Mode, F>
where F: Sync,

§

impl<Mode, F> Unpin for Bobyqa<Mode, F>
where F: Unpin,

§

impl<Mode, F> UnsafeUnpin for Bobyqa<Mode, F>
where F: UnsafeUnpin,

§

impl<Mode, F> UnwindSafe for Bobyqa<Mode, F>
where F: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V