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) -> Self

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) -> Self

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) -> Self

Set maximum number of iterations

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

pub fn cost(self, cost: F) -> Self

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) -> Self

Overrides state of counting function executions (default: false)

let state = state.counting(true);

Trait Implementations§

source§

impl<P: Clone, F: Clone> Clone for LinearProgramState<P, F>

source§

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

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

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

source§

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

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<Self, __D::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::Ok, __S::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,

§

type Param = P

Type of parameter vector

§

type Float = F

Floating point precision

source§

fn new() -> Self

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) -> Self

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 Self

Sets the time required so far.

§Example
let state = state.time(Some(instant::Duration::new(0, 12)));
source§

fn get_cost(&self) -> Self::Float

Returns current cost function value.

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

fn get_best_cost(&self) -> Self::Float

Returns current best cost function value.

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

fn get_target_cost(&self) -> Self::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> 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> UnwindSafe for LinearProgramState<P, F>
where F: UnwindSafe, P: UnwindSafe,

Blanket Implementations§

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

§

type Output = T

Should always be Self
§

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

§

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

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

fn is_in_subset(&self) -> bool

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

fn to_subset_unchecked(&self) -> SS

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

fn from_subset(element: &SS) -> SP

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

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

§

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<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.
§

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

§

fn vzip(self) -> V

source§

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

source§

impl<T> SendAlias for T

source§

impl<T> SyncAlias for T