Struct cobyla::CobylaSolver

source ·
pub struct CobylaSolver { /* private fields */ }
Expand description

Argmin Solver which implements COBYLA method.

use argmin::core::{CostFunction, Error, Executor};
use argmin::core::observers::{ObserverMode};
use argmin_observer_slog::SlogLogger;
use cobyla::CobylaSolver;

struct ParaboloidProblem;
impl CostFunction for ParaboloidProblem {
    type Param = Vec<f64>;
    type Output = Vec<f64>;

    // Minimize 10*(x0+1)^2 + x1^2 subject to x0 >= 0
    fn cost(&self, x: &Self::Param) -> Result<Self::Output, Error> {
        Ok(vec![10. * (x[0] + 1.).powf(2.) + x[1].powf(2.), x[0]])
    }
}

let pb = ParaboloidProblem;
let solver = CobylaSolver::new(vec![1., 1.]);

let res = Executor::new(pb, solver)
            .configure(|state| state.max_iters(100))
            .add_observer(SlogLogger::term(), ObserverMode::Always)
            .run()
            .unwrap();

// Wait a second (lets the logger flush everything before printing again)
std::thread::sleep(std::time::Duration::from_secs(1));

println!("Result of COBYLA:\n{}", res);

Implementations§

source§

impl CobylaSolver

source

pub fn new(x0: Vec<f64>) -> Self

Trait Implementations§

source§

impl<O> Solver<O, CobylaState> for CobylaSolver
where O: CostFunction<Param = Vec<f64>, Output = Vec<f64>>,

source§

fn init( &mut self, problem: &mut Problem<O>, state: CobylaState ) -> Result<(CobylaState, Option<KV>), Error>

Initializes the algorithm.

Executed before any iterations are performed and has access to the optimization problem definition and the internal state of the solver. Returns an updated state and optionally a KV which holds key-value pairs used in Observers. The default implementation returns the unaltered state and no KV.

source§

fn next_iter( &mut self, problem: &mut Problem<O>, state: CobylaState ) -> Result<(CobylaState, Option<KV>), Error>

Computes a single iteration of the algorithm and has access to the optimization problem definition and the internal state of the solver. Returns an updated state and optionally a KV which holds key-value pairs used in Observers.

source§

fn terminate(&mut self, state: &CobylaState) -> TerminationStatus

Used to implement stopping criteria, in particular criteria which are not covered by (terminate_internal.

This method has access to the internal state and returns an TerminationReason.

source§

const NAME: &'static str = "COBYLA"

Name of the solver. Mainly used in Observers.
source§

fn terminate_internal(&mut self, state: &I) -> TerminationStatus

Checks whether basic termination reasons apply. Read more

Auto Trait Implementations§

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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

source§

impl<T> SendAlias for T

source§

impl<T> SyncAlias for T