pub struct OptObserverVec { /* private fields */ }Expand description
Collection of observers for optimization monitoring.
This struct manages a vector of observers and provides a convenient
notify() method to call all observers at once. Optimizers use this
internally to manage their observers.
§Usage
Typically you don’t create this directly - use the add_observer() method
on optimizers. However, you can use it for custom optimization algorithms:
use apex_solver::observers::{OptObserver, OptObserverVec};
use apex_solver::core::problem::VariableEnum;
use std::collections::HashMap;
struct MyOptimizer {
observers: OptObserverVec,
// ... other fields ...
}
impl MyOptimizer {
fn step(&mut self, values: &HashMap<String, VariableEnum>, iteration: usize) {
// ... optimization logic ...
// Notify all observers
self.observers.notify(values, iteration);
}
}Implementations§
Source§impl OptObserverVec
impl OptObserverVec
Sourcepub fn add(&mut self, observer: impl OptObserver + 'static)
pub fn add(&mut self, observer: impl OptObserver + 'static)
Add an observer to the collection.
The observer will be called at each optimization iteration in the order it was added.
§Arguments
observer- Any type implementingOptObserver
§Examples
use apex_solver::observers::{OptObserver, OptObserverVec};
use apex_solver::core::problem::VariableEnum;
use std::collections::HashMap;
struct MyObserver;
impl OptObserver for MyObserver {
fn on_step(&self, _values: &HashMap<String, VariableEnum>, _iteration: usize) {
// Handle optimization step
}
}
let mut observers = OptObserverVec::new();
observers.add(MyObserver);Sourcepub fn set_iteration_metrics(
&self,
cost: f64,
gradient_norm: f64,
damping: Option<f64>,
step_norm: f64,
step_quality: Option<f64>,
)
pub fn set_iteration_metrics( &self, cost: f64, gradient_norm: f64, damping: Option<f64>, step_norm: f64, step_quality: Option<f64>, )
Set iteration metrics for all observers.
Calls set_iteration_metrics() on each registered observer. This should
be called before notify() to provide optimization metrics.
§Arguments
cost- Current cost function valuegradient_norm- L2 norm of the gradient vectordamping- Damping parameter (may be None)step_norm- L2 norm of the parameter update stepstep_quality- Step quality metric (may be None)
Sourcepub fn set_matrix_data(
&self,
hessian: Option<SparseColMat<usize, f64>>,
gradient: Option<Mat<f64>>,
)
pub fn set_matrix_data( &self, hessian: Option<SparseColMat<usize, f64>>, gradient: Option<Mat<f64>>, )
Set matrix data for all observers.
Calls set_matrix_data() on each registered observer. This should
be called before notify() to provide matrix data for visualization.
§Arguments
hessian- Sparse Hessian matrixgradient- Gradient vector
Sourcepub fn notify(&self, values: &HashMap<String, VariableEnum>, iteration: usize)
pub fn notify(&self, values: &HashMap<String, VariableEnum>, iteration: usize)
Notify all observers with current optimization state.
Calls on_step() on each registered observer in order. If no observers
are registered, this is a no-op with zero overhead.
§Arguments
values- Current variable valuesiteration- Current iteration number
§Examples
use apex_solver::observers::OptObserverVec;
use std::collections::HashMap;
let observers = OptObserverVec::new();
let values = HashMap::new();
// Notify all observers (safe even if empty)
observers.notify(&values, 0);Sourcepub fn notify_complete(
&self,
values: &HashMap<String, VariableEnum>,
iterations: usize,
)
pub fn notify_complete( &self, values: &HashMap<String, VariableEnum>, iterations: usize, )
Notify all observers that optimization is complete.
Calls on_optimization_complete() on each registered observer. This should
be called once at the end of optimization, after all iterations are done.
§Arguments
values- Final optimized variable valuesiterations- Total number of iterations performed
§Examples
use apex_solver::observers::OptObserverVec;
use std::collections::HashMap;
let observers = OptObserverVec::new();
let values = HashMap::new();
// Notify all observers that optimization is complete
observers.notify_complete(&values, 50);Trait Implementations§
Source§impl Default for OptObserverVec
impl Default for OptObserverVec
Source§fn default() -> OptObserverVec
fn default() -> OptObserverVec
Auto Trait Implementations§
impl Freeze for OptObserverVec
impl !RefUnwindSafe for OptObserverVec
impl Send for OptObserverVec
impl !Sync for OptObserverVec
impl Unpin for OptObserverVec
impl !UnwindSafe for OptObserverVec
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
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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
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.