use argmin::prelude::*;
use argmin::solver::goldensectionsearch::GoldenSectionSearch;
struct TestFunc {}
impl ArgminOp for TestFunc {
type Param = f32;
type Output = f32;
type Float = f32;
type Hessian = ();
type Jacobian = ();
fn apply(&self, x: &Self::Param) -> Result<Self::Output, Error> {
Ok((x + 3.0) * (x - 1.0).powi(2))
}
}
fn main() {
let cost = TestFunc {};
let init_param = -0.5;
let solver = GoldenSectionSearch::new(-2.5, 3.0).tolerance(0.0001);
let res = Executor::new(cost, solver, init_param)
.add_observer(ArgminSlogLogger::term(), ObserverMode::Always)
.max_iters(100)
.run()
.unwrap();
println!("Result of golden section search:\n{}", res);
}