pub struct ScalarGradientState<F = f64> { /* private fields */ }Expand description
State for one-dimensional solvers that carry a first derivative
(BrentDerivative): a scalar param, an
optional cached cost, an optional cached gradient f'(x), and
cost/gradient evaluation counters. Param and Float are the same scalar
F.
It is the gradient-carrying sibling of
ScalarState: same scalar single-iterate
shape, but it does impl GradientState (its gradient is the scalar
f'(x)), so first-order termination criteria such as
GradientTolerance work on a
1D solver — the natural “stop when |f'(x)| ≤ tol” test. A scalar gradient
satisfies the criteria’s norm bounds directly (f64::norm_squared() is
f' · f').
best_param tracks the lowest-cost probe, which for a
bracketing search can differ from the final iterate.
The scalar F defaults to f64 so ScalarGradientState call sites resolve
unchanged.
Implementations§
Source§impl<F: Scalar> ScalarGradientState<F>
impl<F: Scalar> ScalarGradientState<F>
Sourcepub fn new(param: F) -> Self
pub fn new(param: F) -> Self
Build a state at the given starting point. The cost and gradient are
filled in by Solver::init.
Trait Implementations§
Source§impl<F> CountsMirror for ScalarGradientState<F>where
ScalarGradientState<F>: State,
impl<F> CountsMirror for ScalarGradientState<F>where
ScalarGradientState<F>: State,
Source§fn mirror(&mut self, delta: &EvalCounts)
fn mirror(&mut self, delta: &EvalCounts)
Solver::init /
Solver::next_iter.Source§impl<F: Scalar> GradientState for ScalarGradientState<F>
impl<F: Scalar> GradientState for ScalarGradientState<F>
Source§fn gradient_evals(&self) -> u64
fn gradient_evals(&self) -> u64
GradientState rather than State so derivative-free states
don’t carry a counter they can never increment. Read moreSource§fn best_gradient_evals(&self) -> u64
fn best_gradient_evals(&self) -> u64
State::best_cost_evals. Useful for
benchmarking first-order solvers (“how many gradient calls until
the solver hit its best?”).Source§impl<P, F> Solver<P, ScalarGradientState<F>> for BrentDerivative<F>
impl<P, F> Solver<P, ScalarGradientState<F>> for BrentDerivative<F>
Source§type Error = <P as CostFunction>::Error
type Error = <P as CostFunction>::Error
type Error. See the trait docs.Source§fn init(
&mut self,
problem: &mut Problem<P>,
state: ScalarGradientState<F>,
) -> Result<ScalarGradientState<F>, Self::Error>
fn init( &mut self, problem: &mut Problem<P>, state: ScalarGradientState<F>, ) -> Result<ScalarGradientState<F>, Self::Error>
Source§fn next_iter(
&mut self,
problem: &mut Problem<P>,
state: ScalarGradientState<F>,
) -> Result<(ScalarGradientState<F>, Option<TerminationReason>), Self::Error>
fn next_iter( &mut self, problem: &mut Problem<P>, state: ScalarGradientState<F>, ) -> Result<(ScalarGradientState<F>, Option<TerminationReason>), Self::Error>
Source§fn terminate(
&self,
_state: &ScalarGradientState<F>,
) -> Option<TerminationReason>
fn terminate( &self, _state: &ScalarGradientState<F>, ) -> Option<TerminationReason>
Source§impl<F: Scalar> State for ScalarGradientState<F>
impl<F: Scalar> State for ScalarGradientState<F>
Source§fn cost(&self) -> F
fn cost(&self) -> F
Reads the cost cached at the current param.
§Panics
Panics if accessed before
Solver::init has populated the
cached cost. By contract,
Executor calls init before any
termination-criterion check, so reads from inside criteria and from
OptimizationResult are
safe.
Source§type Param = F
type Param = F
Vec<f64>,
nalgebra::DVector<f64>).Source§type Float = F
type Float = F
f64 (see
the module docs).Source§fn iter(&self) -> u64
fn iter(&self) -> u64
Solver::next_iter
that bails mid-iteration with Some(reason) does not increment
this counter — see the
executor module for the exact ordering.Source§fn increment_iter(&mut self)
fn increment_iter(&mut self)
iter by one. Called by the executor
after a successful Solver::next_iter.Source§fn cost_evals(&self) -> u64
fn cost_evals(&self) -> u64
iter() whenever a single iteration evaluates the
cost more than once (line searches, Nelder-Mead shrinks, etc.) —
this is what users actually budget against. Read moreSource§fn param(&self) -> &F
fn param(&self) -> &F
Solver::next_iter
calls; safe to read at any iteration including iter 0.Source§fn best_param(&self) -> &F
fn best_param(&self) -> &F
Source§fn best_cost(&self) -> F
fn best_cost(&self) -> F
best_param — the lowest cost ever
observed on this state.Source§fn best_iter(&self) -> u64
fn best_iter(&self) -> u64
0 before the
first update_best call; thereafter, the
value of iter at the moment of the last strict
improvement in best_cost().Source§fn best_cost_evals(&self) -> u64
fn best_cost_evals(&self) -> u64
Source§fn update_best(&mut self)
fn update_best(&mut self)
Source§fn reset_best(&mut self)
fn reset_best(&mut self)
best_cost = +∞, all best counters zero). Read moreAuto Trait Implementations§
impl<F> Freeze for ScalarGradientState<F>where
F: Freeze,
impl<F> RefUnwindSafe for ScalarGradientState<F>where
F: RefUnwindSafe,
impl<F> Send for ScalarGradientState<F>where
F: Send,
impl<F> Sync for ScalarGradientState<F>where
F: Sync,
impl<F> Unpin for ScalarGradientState<F>where
F: Unpin,
impl<F> UnsafeUnpin for ScalarGradientState<F>where
F: UnsafeUnpin,
impl<F> UnwindSafe for ScalarGradientState<F>where
F: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T, U> Imply<T> for U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.