pub struct LinearProgramState<P, F> {Show 16 fields
pub param: Option<P>,
pub prev_param: Option<P>,
pub best_param: Option<P>,
pub prev_best_param: Option<P>,
pub cost: F,
pub prev_cost: F,
pub best_cost: F,
pub prev_best_cost: F,
pub target_cost: F,
pub iter: u64,
pub last_best_iter: u64,
pub max_iters: u64,
pub counts: HashMap<String, u64>,
pub counting_enabled: bool,
pub time: Option<Duration>,
pub termination_status: TerminationStatus,
}Expand description
Maintains the state from iteration to iteration of a solver
This struct is passed from one iteration of an algorithm to the next.
Keeps track of
- parameter vector of current and previous iteration
- best parameter vector of current and previous iteration
- cost function value of current and previous iteration
- current and previous best cost function value
- target cost function value
- current iteration number
- iteration number where the last best parameter vector was found
- maximum number of iterations that will be executed
- problem function evaluation counts (cost function, gradient, jacobian, hessian,
- elapsed time
- termination status
Fields§
§param: Option<P>Current parameter vector
prev_param: Option<P>Previous parameter vector
best_param: Option<P>Current best parameter vector
prev_best_param: Option<P>Previous best parameter vector
cost: FCurrent cost function value
prev_cost: FPrevious cost function value
best_cost: FCurrent best cost function value
prev_best_cost: FPrevious best cost function value
target_cost: FTarget cost function value
iter: u64Current iteration
last_best_iter: u64Iteration number of last best cost
max_iters: u64Maximum number of iterations
counts: HashMap<String, u64>Evaluation counts
counting_enabled: boolUpdate evaluation counts?
time: Option<Duration>Time required so far
termination_status: TerminationStatusStatus of optimization execution
Implementations§
Source§impl<P, F> LinearProgramState<P, F>
impl<P, F> LinearProgramState<P, F>
Sourcepub fn param(self, param: P) -> LinearProgramState<P, F>
pub fn param(self, param: P) -> LinearProgramState<P, F>
Set parameter vector. This shifts the stored parameter vector to the previous parameter vector.
§Example
let state = state.param(param);Sourcepub fn target_cost(self, target_cost: F) -> LinearProgramState<P, F>
pub fn target_cost(self, target_cost: F) -> LinearProgramState<P, F>
Set target cost.
When this cost is reached, the algorithm will stop. The default is
Self::Float::NEG_INFINITY.
§Example
let state = state.target_cost(0.0);Sourcepub fn max_iters(self, iters: u64) -> LinearProgramState<P, F>
pub fn max_iters(self, iters: u64) -> LinearProgramState<P, F>
Sourcepub fn cost(self, cost: F) -> LinearProgramState<P, F>
pub fn cost(self, cost: F) -> LinearProgramState<P, F>
Set the current cost function value. This shifts the stored cost function value to the previous cost function value.
§Example
let state = state.cost(cost);Sourcepub fn counting(self, mode: bool) -> LinearProgramState<P, F>
pub fn counting(self, mode: bool) -> LinearProgramState<P, F>
Overrides state of counting function executions (default: false)
let state = state.counting(true);Trait Implementations§
Source§impl<P, F> Clone for LinearProgramState<P, F>
impl<P, F> Clone for LinearProgramState<P, F>
Source§fn clone(&self) -> LinearProgramState<P, F>
fn clone(&self) -> LinearProgramState<P, F>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<P, F> Debug for LinearProgramState<P, F>
impl<P, F> Debug for LinearProgramState<P, F>
Source§impl<'de, P, F> Deserialize<'de> for LinearProgramState<P, F>where
P: Deserialize<'de>,
F: Deserialize<'de>,
impl<'de, P, F> Deserialize<'de> for LinearProgramState<P, F>where
P: Deserialize<'de>,
F: Deserialize<'de>,
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<LinearProgramState<P, F>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<LinearProgramState<P, F>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl<P, F> Serialize for LinearProgramState<P, F>
impl<P, F> Serialize for LinearProgramState<P, F>
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Source§impl<P, F> State for LinearProgramState<P, F>where
P: Clone,
F: ArgminFloat,
impl<P, F> State for LinearProgramState<P, F>where
P: Clone,
F: ArgminFloat,
Source§fn new() -> LinearProgramState<P, F>
fn new() -> LinearProgramState<P, F>
Create new LinearProgramState instance
§Example
use argmin::core::{LinearProgramState, State};
let state: LinearProgramState<Vec<f64>, f64> = LinearProgramState::new();
Source§fn update(&mut self)
fn update(&mut self)
Checks if the current parameter vector is better than the previous best parameter value. If a new best parameter vector was found, the state is updated accordingly.
§Example
let mut state: LinearProgramState<Vec<f64>, f64> = LinearProgramState::new();
// Simulating a new, better parameter vector
state.best_param = Some(vec![1.0f64]);
state.best_cost = 10.0;
state.param = Some(vec![2.0f64]);
state.cost = 5.0;
// Calling update
state.update();
// Check if update was successful
assert_eq!(state.best_param.as_ref().unwrap()[0], 2.0f64);
assert_eq!(state.best_cost.to_ne_bytes(), state.best_cost.to_ne_bytes());
assert!(state.is_best());For algorithms which do not compute the cost function, every new parameter vector will be the new best:
let mut state: LinearProgramState<Vec<f64>, f64> = LinearProgramState::new();
// Simulating a new, better parameter vector
state.best_param = Some(vec![1.0f64]);
state.param = Some(vec![2.0f64]);
// Calling update
state.update();
// Check if update was successful
assert_eq!(state.best_param.as_ref().unwrap()[0], 2.0f64);
assert_eq!(state.best_cost.to_ne_bytes(), state.best_cost.to_ne_bytes());
assert!(state.is_best());Source§fn get_param(&self) -> Option<&P>
fn get_param(&self) -> Option<&P>
Returns a reference to the current parameter vector
§Example
let param = state.get_param(); // Option<&P>Source§fn get_best_param(&self) -> Option<&P>
fn get_best_param(&self) -> Option<&P>
Returns a reference to the current best parameter vector
§Example
let best_param = state.get_best_param(); // Option<&P>Source§fn terminate_with(self, reason: TerminationReason) -> LinearProgramState<P, F>
fn terminate_with(self, reason: TerminationReason) -> LinearProgramState<P, F>
Sets the termination status to Terminated with the given reason
§Example
let state = state.terminate_with(TerminationReason::MaxItersReached);Source§fn get_best_cost(&self) -> <LinearProgramState<P, F> as State>::Float
fn get_best_cost(&self) -> <LinearProgramState<P, F> as State>::Float
Source§fn get_target_cost(&self) -> <LinearProgramState<P, F> as State>::Float
fn get_target_cost(&self) -> <LinearProgramState<P, F> as State>::Float
Source§fn get_last_best_iter(&self) -> u64
fn get_last_best_iter(&self) -> u64
Returns iteration number of last best parameter vector.
§Example
let last_best_iter = state.get_last_best_iter();Source§fn get_max_iters(&self) -> u64
fn get_max_iters(&self) -> u64
Source§fn get_termination_status(&self) -> &TerminationStatus
fn get_termination_status(&self) -> &TerminationStatus
Source§fn get_termination_reason(&self) -> Option<&TerminationReason>
fn get_termination_reason(&self) -> Option<&TerminationReason>
Returns the termination reason if terminated, otherwise None.
§Example
let termination_reason = state.get_termination_reason();Source§fn increment_iter(&mut self)
fn increment_iter(&mut self)
Source§fn func_counts<O>(&mut self, problem: &Problem<O>)
fn func_counts<O>(&mut self, problem: &Problem<O>)
Set all function evaluation counts to the evaluation counts of another Problem.
state.func_counts(&problem);Source§fn is_best(&self) -> bool
fn is_best(&self) -> bool
Returns whether the current parameter vector is also the best parameter vector found so far.
§Example
let is_best = state.is_best();Source§fn terminated(&self) -> bool
fn terminated(&self) -> bool
Auto Trait Implementations§
impl<P, F> Freeze for LinearProgramState<P, F>
impl<P, F> RefUnwindSafe for LinearProgramState<P, F>where
F: RefUnwindSafe,
P: RefUnwindSafe,
impl<P, F> Send for LinearProgramState<P, F>
impl<P, F> Sync for LinearProgramState<P, F>
impl<P, F> Unpin for LinearProgramState<P, F>
impl<P, F> UnsafeUnpin for LinearProgramState<P, F>where
F: UnsafeUnpin,
P: UnsafeUnpin,
impl<P, F> UnwindSafe for LinearProgramState<P, F>where
F: UnwindSafe,
P: UnwindSafe,
Blanket Implementations§
Source§impl<T> AlignerFor<1> for T
impl<T> AlignerFor<1> for T
Source§impl<T> AlignerFor<2> for T
impl<T> AlignerFor<2> for T
Source§impl<T> AlignerFor<4> for T
impl<T> AlignerFor<4> for T
Source§impl<T> AlignerFor<8> for T
impl<T> AlignerFor<8> for T
Source§impl<T> AlignerFor<16> for T
impl<T> AlignerFor<16> for T
Source§impl<T> AlignerFor<32> for T
impl<T> AlignerFor<32> for T
Source§impl<T> AlignerFor<64> for T
impl<T> AlignerFor<64> for T
Source§impl<T> AlignerFor<128> for T
impl<T> AlignerFor<128> for T
Source§type Aligner = AlignTo128<T>
type Aligner = AlignTo128<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<256> for T
impl<T> AlignerFor<256> for T
Source§type Aligner = AlignTo256<T>
type Aligner = AlignTo256<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<512> for T
impl<T> AlignerFor<512> for T
Source§type Aligner = AlignTo512<T>
type Aligner = AlignTo512<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<1024> for T
impl<T> AlignerFor<1024> for T
Source§type Aligner = AlignTo1024<T>
type Aligner = AlignTo1024<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<2048> for T
impl<T> AlignerFor<2048> for T
Source§type Aligner = AlignTo2048<T>
type Aligner = AlignTo2048<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<4096> for T
impl<T> AlignerFor<4096> for T
Source§type Aligner = AlignTo4096<T>
type Aligner = AlignTo4096<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<8192> for T
impl<T> AlignerFor<8192> for T
Source§type Aligner = AlignTo8192<T>
type Aligner = AlignTo8192<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<16384> for T
impl<T> AlignerFor<16384> for T
Source§type Aligner = AlignTo16384<T>
type Aligner = AlignTo16384<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<32768> for T
impl<T> AlignerFor<32768> for T
Source§type Aligner = AlignTo32768<T>
type Aligner = AlignTo32768<T>
AlignTo* type which aligns Self to ALIGNMENT.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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
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
Source§impl<'a, T> RCowCompatibleRef<'a> for Twhere
T: Clone + 'a,
impl<'a, T> RCowCompatibleRef<'a> for Twhere
T: Clone + 'a,
Source§fn as_c_ref(from: &'a T) -> <T as RCowCompatibleRef<'a>>::RefC
fn as_c_ref(from: &'a T) -> <T as RCowCompatibleRef<'a>>::RefC
Source§fn as_rust_ref(from: <T as RCowCompatibleRef<'a>>::RefC) -> &'a T
fn as_rust_ref(from: <T as RCowCompatibleRef<'a>>::RefC) -> &'a T
Source§impl<S> ROExtAcc for S
impl<S> ROExtAcc for S
Source§fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
offset. Read moreSource§fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
offset. Read moreSource§fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
offset. Read moreSource§fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
offset. Read moreSource§impl<S> ROExtOps<Aligned> for S
impl<S> ROExtOps<Aligned> for S
Source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
offset) with value,
returning the previous value of the field. Read moreSource§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
Source§impl<S> ROExtOps<Unaligned> for S
impl<S> ROExtOps<Unaligned> for S
Source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
offset) with value,
returning the previous value of the field. Read moreSource§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
Source§impl<T> SelfOps for Twhere
T: ?Sized,
impl<T> SelfOps for Twhere
T: ?Sized,
Source§fn piped<F, U>(self, f: F) -> U
fn piped<F, U>(self, f: F) -> U
Source§fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
piped except that the function takes &Self
Useful for functions that take &Self instead of Self. Read moreSource§fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
piped, except that the function takes &mut Self.
Useful for functions that take &mut Self instead of Self.Source§fn mutated<F>(self, f: F) -> Self
fn mutated<F>(self, f: F) -> Self
Source§fn observe<F>(self, f: F) -> Self
fn observe<F>(self, f: F) -> Self
Source§fn as_ref_<T>(&self) -> &T
fn as_ref_<T>(&self) -> &T
AsRef,
using the turbofish .as_ref_::<_>() syntax. Read moreimpl<T> SendAlias 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.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§unsafe fn to_subset_unchecked(&self) -> SS
unsafe 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.