Skip to main content

LinearProgramState

Struct LinearProgramState 

Source
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: F

Current cost function value

§prev_cost: F

Previous cost function value

§best_cost: F

Current best cost function value

§prev_best_cost: F

Previous best cost function value

§target_cost: F

Target cost function value

§iter: u64

Current iteration

§last_best_iter: u64

Iteration number of last best cost

§max_iters: u64

Maximum number of iterations

§counts: HashMap<String, u64>

Evaluation counts

§counting_enabled: bool

Update evaluation counts?

§time: Option<Duration>

Time required so far

§termination_status: TerminationStatus

Status of optimization execution

Implementations§

Source§

impl<P, F> LinearProgramState<P, F>

Source

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);
Source

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);
Source

pub fn max_iters(self, iters: u64) -> LinearProgramState<P, F>

Set maximum number of iterations

§Example
let state = state.max_iters(1000);
Source

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);
Source

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>
where P: Clone, F: Clone,

Source§

fn clone(&self) -> LinearProgramState<P, F>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<P, F> Debug for LinearProgramState<P, F>
where P: Debug, F: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

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>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<P, F> Serialize for LinearProgramState<P, F>
where P: Serialize, F: Serialize,

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<P, F> State for LinearProgramState<P, F>
where P: Clone, F: ArgminFloat,

Source§

type Param = P

Type of parameter vector

Source§

type Float = F

Floating point precision

Source§

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)

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>

Returns a reference to the current parameter vector

§Example
let param = state.get_param();  // Option<&P>
Source§

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>

Sets the termination status to Terminated with the given reason

§Example
let state = state.terminate_with(TerminationReason::MaxItersReached);
Source§

fn time(&mut self, time: Option<Duration>) -> &mut LinearProgramState<P, F>

Sets the time required so far.

§Example
let state = state.time(Some(Duration::from_nanos(12)));
Source§

fn get_cost(&self) -> <LinearProgramState<P, F> as State>::Float

Returns current cost function value.

§Example
let cost = state.get_cost();
Source§

fn get_best_cost(&self) -> <LinearProgramState<P, F> as State>::Float

Returns current best cost function value.

§Example
let best_cost = state.get_best_cost();
Source§

fn get_target_cost(&self) -> <LinearProgramState<P, F> as State>::Float

Returns target cost function value.

§Example
let target_cost = state.get_target_cost();
Source§

fn get_iter(&self) -> u64

Returns current number of iterations.

§Example
let iter = state.get_iter();
Source§

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

Returns the maximum number of iterations.

§Example
let max_iters = state.get_max_iters();
Source§

fn get_termination_status(&self) -> &TerminationStatus

Returns the termination status.

§Example
let termination_status = state.get_termination_status();
Source§

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 get_time(&self) -> Option<Duration>

Returns the time elapsed since the start of the optimization.

§Example
let time = state.get_time();
Source§

fn increment_iter(&mut self)

Increments the number of iterations by one

§Example
state.increment_iter();
Source§

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 get_func_counts(&self) -> &HashMap<String, u64>

Returns function evaluation counts

§Example
let counts = state.get_func_counts();
Source§

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

Return whether the algorithm has terminated or not

Auto Trait Implementations§

§

impl<P, F> Freeze for LinearProgramState<P, F>
where F: Freeze, P: Freeze,

§

impl<P, F> RefUnwindSafe for LinearProgramState<P, F>

§

impl<P, F> Send for LinearProgramState<P, F>
where F: Send, P: Send,

§

impl<P, F> Sync for LinearProgramState<P, F>
where F: Sync, P: Sync,

§

impl<P, F> Unpin for LinearProgramState<P, F>
where F: Unpin, P: Unpin,

§

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

Source§

type Aligner = AlignTo1<T>

The AlignTo* type which aligns Self to ALIGNMENT.
Source§

impl<T> AlignerFor<2> for T

Source§

type Aligner = AlignTo2<T>

The AlignTo* type which aligns Self to ALIGNMENT.
Source§

impl<T> AlignerFor<4> for T

Source§

type Aligner = AlignTo4<T>

The AlignTo* type which aligns Self to ALIGNMENT.
Source§

impl<T> AlignerFor<8> for T

Source§

type Aligner = AlignTo8<T>

The AlignTo* type which aligns Self to ALIGNMENT.
Source§

impl<T> AlignerFor<16> for T

Source§

type Aligner = AlignTo16<T>

The AlignTo* type which aligns Self to ALIGNMENT.
Source§

impl<T> AlignerFor<32> for T

Source§

type Aligner = AlignTo32<T>

The AlignTo* type which aligns Self to ALIGNMENT.
Source§

impl<T> AlignerFor<64> for T

Source§

type Aligner = AlignTo64<T>

The AlignTo* type which aligns Self to ALIGNMENT.
Source§

impl<T> AlignerFor<128> for T

Source§

type Aligner = AlignTo128<T>

The AlignTo* type which aligns Self to ALIGNMENT.
Source§

impl<T> AlignerFor<256> for T

Source§

type Aligner = AlignTo256<T>

The AlignTo* type which aligns Self to ALIGNMENT.
Source§

impl<T> AlignerFor<512> for T

Source§

type Aligner = AlignTo512<T>

The AlignTo* type which aligns Self to ALIGNMENT.
Source§

impl<T> AlignerFor<1024> for T

Source§

type Aligner = AlignTo1024<T>

The AlignTo* type which aligns Self to ALIGNMENT.
Source§

impl<T> AlignerFor<2048> for T

Source§

type Aligner = AlignTo2048<T>

The AlignTo* type which aligns Self to ALIGNMENT.
Source§

impl<T> AlignerFor<4096> for T

Source§

type Aligner = AlignTo4096<T>

The AlignTo* type which aligns Self to ALIGNMENT.
Source§

impl<T> AlignerFor<8192> for T

Source§

type Aligner = AlignTo8192<T>

The AlignTo* type which aligns Self to ALIGNMENT.
Source§

impl<T> AlignerFor<16384> for T

Source§

type Aligner = AlignTo16384<T>

The AlignTo* type which aligns Self to ALIGNMENT.
Source§

impl<T> AlignerFor<32768> for T

Source§

type Aligner = AlignTo32768<T>

The AlignTo* type which aligns Self to ALIGNMENT.
Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DistributionExt for T
where T: ?Sized,

Source§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<'a, T> RCowCompatibleRef<'a> for T
where T: Clone + 'a,

Source§

type RefC = &'a T

The (preferably) ffi-safe equivalent of &Self.
Source§

type ROwned = T

The owned version of Self::RefC.
Source§

fn as_c_ref(from: &'a T) -> <T as RCowCompatibleRef<'a>>::RefC

Converts a reference to an FFI-safe type
Source§

fn as_rust_ref(from: <T as RCowCompatibleRef<'a>>::RefC) -> &'a T

Converts an FFI-safe type to a reference
Source§

impl<S> ROExtAcc for S

Source§

fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F

Gets a reference to a field, determined by offset. Read more
Source§

fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F

Gets a muatble reference to a field, determined by offset. Read more
Source§

fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F

Gets a const pointer to a field, the field is determined by offset. Read more
Source§

fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F

Gets a mutable pointer to a field, determined by offset. Read more
Source§

impl<S> ROExtOps<Aligned> for S

Source§

fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F

Replaces a field (determined by offset) with value, returning the previous value of the field. Read more
Source§

fn f_swap<F>(&mut self, offset: FieldOffset<S, F, Aligned>, right: &mut S)

Swaps a field (determined by offset) with the same field in right. Read more
Source§

fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> F
where F: Copy,

Gets a copy of a field (determined by offset). The field is determined by offset. Read more
Source§

impl<S> ROExtOps<Unaligned> for S

Source§

fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F

Replaces a field (determined by offset) with value, returning the previous value of the field. Read more
Source§

fn f_swap<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, right: &mut S)

Swaps a field (determined by offset) with the same field in right. Read more
Source§

fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> F
where F: Copy,

Gets a copy of a field (determined by offset). The field is determined by offset. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SelfOps for T
where T: ?Sized,

Source§

fn eq_id(&self, other: &Self) -> bool

Compares the address of self with the address of other. Read more
Source§

fn piped<F, U>(self, f: F) -> U
where F: FnOnce(Self) -> U, Self: Sized,

Emulates the pipeline operator, allowing method syntax in more places. Read more
Source§

fn piped_ref<'a, F, U>(&'a self, f: F) -> U
where F: FnOnce(&'a Self) -> U,

The same as piped except that the function takes &Self Useful for functions that take &Self instead of Self. Read more
Source§

fn piped_mut<'a, F, U>(&'a mut self, f: F) -> U
where F: FnOnce(&'a mut Self) -> U,

The same as 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
where F: FnOnce(&mut Self), Self: Sized,

Mutates self using a closure taking self by mutable reference, passing it along the method chain. Read more
Source§

fn observe<F>(self, f: F) -> Self
where F: FnOnce(&Self), Self: Sized,

Observes the value of self, passing it along unmodified. Useful in long method chains. Read more
Source§

fn into_<T>(self) -> T
where Self: Into<T>,

Performs a conversion with Into. using the turbofish .into_::<_>() syntax. Read more
Source§

fn as_ref_<T>(&self) -> &T
where Self: AsRef<T>, T: ?Sized,

Performs a reference to reference conversion with AsRef, using the turbofish .as_ref_::<_>() syntax. Read more
Source§

fn as_mut_<T>(&mut self) -> &mut T
where Self: AsMut<T>, T: ?Sized,

Performs a mutable reference to mutable reference conversion with AsMut, using the turbofish .as_mut_::<_>() syntax. Read more
Source§

fn drop_(self)
where Self: Sized,

Drops self using method notation. Alternative to std::mem::drop. Read more
Source§

impl<T> SendAlias for T

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

unsafe fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> SyncAlias for T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<This> TransmuteElement for This
where This: ?Sized,

Source§

unsafe fn transmute_element<T>(self) -> Self::TransmutedPtr
where Self: CanTransmuteElement<T>,

Transmutes the element type of this pointer.. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> TypeIdentity for T
where T: ?Sized,

Source§

type Type = T

This is always Self.
Source§

fn into_type(self) -> Self::Type
where Self: Sized, Self::Type: Sized,

Converts a value back to the original type.
Source§

fn as_type(&self) -> &Self::Type

Converts a reference back to the original type.
Source§

fn as_type_mut(&mut self) -> &mut Self::Type

Converts a mutable reference back to the original type.
Source§

fn into_type_box(self: Box<Self>) -> Box<Self::Type>

Converts a box back to the original type.
Source§

fn into_type_arc(this: Arc<Self>) -> Arc<Self::Type>

Converts an Arc back to the original type. Read more
Source§

fn into_type_rc(this: Rc<Self>) -> Rc<Self::Type>

Converts an Rc back to the original type. Read more
Source§

fn from_type(this: Self::Type) -> Self
where Self: Sized, Self::Type: Sized,

Converts a value back to the original type.
Source§

fn from_type_ref(this: &Self::Type) -> &Self

Converts a reference back to the original type.
Source§

fn from_type_mut(this: &mut Self::Type) -> &mut Self

Converts a mutable reference back to the original type.
Source§

fn from_type_box(this: Box<Self::Type>) -> Box<Self>

Converts a box back to the original type.
Source§

fn from_type_arc(this: Arc<Self::Type>) -> Arc<Self>

Converts an Arc back to the original type.
Source§

fn from_type_rc(this: Rc<Self::Type>) -> Rc<Self>

Converts an Rc back to the original type.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V