pub struct SelectedFirstOrderState<V, F: Scalar = f64> { /* private fields */ }Expand description
Solver-selected constrained progress with a matching objective gradient.
Construction provides an unevaluated seed. replace
checks point and gradient dimensions before publishing a complete current
record, while select_current explicitly chooses
an incumbent. Selection can increase the objective to improve feasibility,
so this state does not implement super::ObjectiveIncumbentState.
The solver supplies a ViolationReport describing the measure, scaling,
and transformation, and defines its eligibility rules.
Current records contain a point, objective, gradient, and violation. Best
records contain the selected point, objective, and violation; their raw
counts and iteration are stamped by the executor at publication. Selection
events follow SelectedState, including preservation when current progress
changes before publication. Derivatives are advertised only for current
evaluated progress. All six evaluation categories retain their raw values.
Fresh initialization calls reset and reevaluates the seed.
Exact continuation retains the solver and state together. With serde,
serialization is available when V and F support it.
§Backends
Vec<F>, nalgebra DVector<F>, ndarray Array1<F>, and faer Col<F>,
for F = f64 (default) or f32. Replacement requires VectorLen;
state capabilities require only V: Clone.
use basin::{RunControl, SelectedFirstOrderState};
let _ = RunControl::<SelectedFirstOrderState<Vec<f64>>>::new().target_objective(0.0);Implementations§
Source§impl<V, F: Scalar> SelectedFirstOrderState<V, F>
impl<V, F: Scalar> SelectedFirstOrderState<V, F>
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Clear records and bookkeeping, retaining the parameter as a fresh seed.
Sourcepub fn current(&self) -> Option<(&V, F, &V, &ViolationReport<F>)>
pub fn current(&self) -> Option<(&V, F, &V, &ViolationReport<F>)>
Matching point, objective, gradient, and violation report, or None for a seed.
Sourcepub fn best(&self) -> Option<(&V, F, &ViolationReport<F>)>
pub fn best(&self) -> Option<(&V, F, &ViolationReport<F>)>
Selected point, objective, and violation report, or None before selection.
Sourcepub fn counts(&self) -> &EvalCounts
pub fn counts(&self) -> &EvalCounts
All six raw evaluation categories at the current publication boundary.
Sourcepub fn best_counts(&self) -> Option<&EvalCounts>
pub fn best_counts(&self) -> Option<&EvalCounts>
Raw counts recorded when the selected incumbent was published.
Source§impl<V: VectorLen, F: Scalar> SelectedFirstOrderState<V, F>
impl<V: VectorLen, F: Scalar> SelectedFirstOrderState<V, F>
Sourcepub fn replace(
&mut self,
param: V,
cost: F,
gradient: V,
violation: ViolationReport<F>,
) -> Result<(), GradientDimensionMismatch>
pub fn replace( &mut self, param: V, cost: F, gradient: V, violation: ViolationReport<F>, ) -> Result<(), GradientDimensionMismatch>
Replace current progress atomically, preserving any pending selection. A dimension mismatch leaves every record and counter unchanged.
Source§impl<V: Clone, F: Scalar> SelectedFirstOrderState<V, F>
impl<V: Clone, F: Scalar> SelectedFirstOrderState<V, F>
Sourcepub fn select_current(&mut self) -> bool
pub fn select_current(&mut self) -> bool
Select the current evaluated record for the next publication boundary.
Returns false for an unevaluated seed. Repeated observation does not
refresh the selected record’s metadata.
Trait Implementations§
Source§impl<V: Clone, F: Scalar> ConstraintViolationState for SelectedFirstOrderState<V, F>
impl<V: Clone, F: Scalar> ConstraintViolationState for SelectedFirstOrderState<V, F>
Source§fn current_violation(&self) -> Option<&ViolationReport<F>>
fn current_violation(&self) -> Option<&ViolationReport<F>>
None.Source§fn incumbent_violation(&self) -> Option<&ViolationReport<F>>
fn incumbent_violation(&self) -> Option<&ViolationReport<F>>
None.Source§impl<V: Clone, F: Scalar> CountsMirror for SelectedFirstOrderState<V, F>
impl<V: Clone, F: Scalar> CountsMirror for SelectedFirstOrderState<V, F>
Source§fn mirror(&mut self, counts: &EvalCounts)
fn mirror(&mut self, counts: &EvalCounts)
Solver::init /
Solver::next_iter.Source§impl<'de, V, F> Deserialize<'de> for SelectedFirstOrderState<V, F>
Available on crate feature serde only.
impl<'de, V, F> Deserialize<'de> for SelectedFirstOrderState<V, F>
serde only.Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<V: Clone, F: Scalar> EvaluatedGradientState for SelectedFirstOrderState<V, F>
impl<V: Clone, F: Scalar> EvaluatedGradientState for SelectedFirstOrderState<V, F>
Source§impl<V: Clone, F: Scalar> EvaluatedState for SelectedFirstOrderState<V, F>
impl<V: Clone, F: Scalar> EvaluatedState for SelectedFirstOrderState<V, F>
Source§fn current_record(&self) -> Option<(&V, F)>
fn current_record(&self) -> Option<(&V, F)>
Source§impl<V: Clone, F: Scalar> GradientState for SelectedFirstOrderState<V, F>
impl<V: Clone, F: Scalar> GradientState for SelectedFirstOrderState<V, F>
Source§fn gradient_evals(&self) -> u64
fn gradient_evals(&self) -> u64
CountsMirror
mapping. In Basin 1.x this can include Jacobian, Hessian, and
Hessian-product evaluations as well as gradient calls. Read moreSource§fn best_gradient_evals(&self) -> u64
fn best_gradient_evals(&self) -> u64
gradient_evals at the publication boundary
that recorded the incumbent, the companion to
State::best_cost_evals. This is not necessarily the count at
the precise evaluation that found the point.Source§impl<V: Clone, F: Scalar> IncumbentState for SelectedFirstOrderState<V, F>
impl<V: Clone, F: Scalar> IncumbentState for SelectedFirstOrderState<V, F>
Source§fn incumbent_record(&self) -> Option<IncumbentRef<'_, V, F>>
fn incumbent_record(&self) -> Option<IncumbentRef<'_, V, F>>
Source§impl<V: Clone, F: Scalar> RawEvaluationState for SelectedFirstOrderState<V, F>
impl<V: Clone, F: Scalar> RawEvaluationState for SelectedFirstOrderState<V, F>
Source§fn raw_counts(&self) -> &EvalCounts
fn raw_counts(&self) -> &EvalCounts
Source§impl<V, F> Serialize for SelectedFirstOrderState<V, F>
Available on crate feature serde only.
impl<V, F> Serialize for SelectedFirstOrderState<V, F>
serde only.Source§impl<P, V, F> Solver<P, SelectedFirstOrderState<V, F>> for Slsqp<F>where
F: Scalar,
P: CostFunction<Param = V, Output = F> + Gradient<Gradient = V>,
P::Constraints: SlsqpSet<P, V, F>,
V: Clone + VectorLen + VectorIndex<F>,
impl<P, V, F> Solver<P, SelectedFirstOrderState<V, F>> for Slsqp<F>where
F: Scalar,
P: CostFunction<Param = V, Output = F> + Gradient<Gradient = V>,
P::Constraints: SlsqpSet<P, V, F>,
V: Clone + VectorLen + VectorIndex<F>,
Source§type Error = ConstraintSolveError<<P as CostFunction>::Error>
type Error = ConstraintSolveError<<P as CostFunction>::Error>
type Error. See the trait docs.Source§fn init(
&mut self,
problem: &mut Problem<P>,
state: SelectedFirstOrderState<V, F>,
) -> Result<SelectedFirstOrderState<V, F>, ConstraintSolveError<P::Error>>
fn init( &mut self, problem: &mut Problem<P>, state: SelectedFirstOrderState<V, F>, ) -> Result<SelectedFirstOrderState<V, F>, ConstraintSolveError<P::Error>>
Source§fn next_iter(
&mut self,
problem: &mut Problem<P>,
state: SelectedFirstOrderState<V, F>,
) -> Result<SolverStep<SelectedFirstOrderState<V, F>>, ConstraintSolveError<P::Error>>
fn next_iter( &mut self, problem: &mut Problem<P>, state: SelectedFirstOrderState<V, F>, ) -> Result<SolverStep<SelectedFirstOrderState<V, F>>, ConstraintSolveError<P::Error>>
Source§fn terminate(
&self,
_state: &SelectedFirstOrderState<V, F>,
) -> Option<Termination<F>>
fn terminate( &self, _state: &SelectedFirstOrderState<V, F>, ) -> Option<Termination<F>>
Source§fn reset_convergence(&mut self)
fn reset_convergence(&mut self)
Source§fn should_check_iterate_change(&self) -> bool
fn should_check_iterate_change(&self) -> bool
Source§fn check_convergence(
&mut self,
_problem: &Problem<P>,
state: &S,
) -> Option<Termination<S::Float>>
fn check_convergence( &mut self, _problem: &Problem<P>, state: &S, ) -> Option<Termination<S::Float>>
Source§impl<V: Clone, F: Scalar> State for SelectedFirstOrderState<V, F>
impl<V: Clone, F: Scalar> State for SelectedFirstOrderState<V, F>
Source§type Param = V
type Param = V
Vec<f64>,
nalgebra::DVector<f64>).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 param(&self) -> &V
fn param(&self) -> &V
Solver::next_iter
calls; available after successful initialization, including iter 0.
Some constructors supply it immediately, while an empty population
such as PopulationProgress::empty must first be initialized.Source§fn cost_evals(&self) -> u64
fn cost_evals(&self) -> u64
CountsMirror mapping.
Every shipped shared state reports only raw cost-function calls.
Custom states define their mapping through CountsMirror.
Diverges from 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 best_param(&self) -> &V
fn best_param(&self) -> &V
Source§fn best_cost(&self) -> F
fn best_cost(&self) -> F
Source§fn best_iter(&self) -> u64
fn best_iter(&self) -> u64
Source§fn best_cost_evals(&self) -> u64
fn best_cost_evals(&self) -> u64
cost_evals at the publication boundary that
recorded the incumbent. This need not be the precise evaluation
that found the point.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 moreimpl<V: PartialEq, F: PartialEq + Scalar> StructuralPartialEq for SelectedFirstOrderState<V, F>
Auto Trait Implementations§
impl<V, F> Freeze for SelectedFirstOrderState<V, F>
impl<V, F> RefUnwindSafe for SelectedFirstOrderState<V, F>
impl<V, F> Send for SelectedFirstOrderState<V, F>
impl<V, F> Sync for SelectedFirstOrderState<V, F>
impl<V, F> Unpin for SelectedFirstOrderState<V, F>
impl<V, F> UnsafeUnpin for SelectedFirstOrderState<V, F>
impl<V, F> UnwindSafe for SelectedFirstOrderState<V, F>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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,
impl<T> Scalar for T
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.