pub struct IterState<P, G, J, H, F> {
Show 23 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 grad: Option<G>, pub prev_grad: Option<G>, pub hessian: Option<H>, pub prev_hessian: Option<H>, pub inv_hessian: Option<H>, pub prev_inv_hessian: Option<H>, pub jacobian: Option<J>, pub prev_jacobian: Option<J>, pub iter: u64, pub last_best_iter: u64, pub max_iters: u64, pub counts: HashMap<String, u64>, pub time: Option<Duration>, pub termination_reason: TerminationReason,
}
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
  • gradient of current and previous iteration
  • Jacobian of current and previous iteration
  • Hessian of current and previous iteration
  • inverse Hessian 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, annealing,…)
  • elapsed time
  • termination reason (set to TerminationReason::NotTerminated if not terminated yet)

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

grad: Option<G>

Current gradient

prev_grad: Option<G>

Previous gradient

hessian: Option<H>

Current Hessian

prev_hessian: Option<H>

Previous Hessian

inv_hessian: Option<H>

Current inverse Hessian

prev_inv_hessian: Option<H>

Previous inverse Hessian

jacobian: Option<J>

Current Jacobian

prev_jacobian: Option<J>

Previous Jacobian

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

time: Option<Duration>

Time required so far

termination_reason: TerminationReason

Reason of termination

Implementations

Set parameter vector. This shifts the stored parameter vector to the previous parameter vector.

Example
let state = state.param(param);

Set gradient. This shifts the stored gradient to the previous gradient.

Example
let state = state.grad(grad);

Set Hessian. This shifts the stored Hessian to the previous Hessian.

Example
let state = state.hessian(hessian);

Set inverse Hessian. This shifts the stored inverse Hessian to the previous inverse Hessian.

Example
let state = state.inv_hessian(inv_hessian);

Set Jacobian. This shifts the stored Jacobian to the previous Jacobian.

Example
let state = state.jacobian(jacobian);

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

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

Set maximum number of iterations

Example
let state = state.max_iters(1000);

Returns the current cost function value

Example
let cost = state.get_cost();

Returns the previous cost function value

Example
let prev_cost = state.get_prev_cost();

Returns the current best cost function value

Example
let best_cost = state.get_best_cost();

Returns the previous best cost function value

Example
let prev_best_cost = state.get_prev_best_cost();

Returns the target cost function value

Example
let target_cost = state.get_target_cost();

Moves the current parameter vector out and replaces it internally with None

Example
let param = state.take_param();  // Option<P>

Returns a reference to previous parameter vector

Example
let prev_param = state.get_prev_param();  // Option<&P>

Moves the previous parameter vector out and replaces it internally with None

Example
let prev_param = state.take_prev_param();  // Option<P>

Returns a reference to previous best parameter vector

Example
let prev_best_param = state.get_prev_best_param();  // Option<&P>

Moves the best parameter vector out and replaces it internally with None

Example
let best_param = state.take_best_param();  // Option<P>

Moves the previous best parameter vector out and replaces it internally with None

Example
let prev_best_param = state.take_prev_best_param();  // Option<P>

Returns a reference to the gradient

Example
let grad = state.get_grad();  // Option<&G>

Moves the gradient out and replaces it internally with None

Example
let grad = state.take_grad();  // Option<G>

Returns a reference to the previous gradient

Example
let prev_grad = state.get_prev_grad();  // Option<&G>

Moves the gradient out and replaces it internally with None

Example
let prev_grad = state.take_prev_grad();  // Option<G>

Returns a reference to the current Hessian

Example
let hessian = state.get_hessian();  // Option<&H>

Moves the Hessian out and replaces it internally with None

Example
let hessian = state.take_hessian();  // Option<H>

Returns a reference to the previous Hessian

Example
let prev_hessian = state.get_prev_hessian();  // Option<&H>

Moves the previous Hessian out and replaces it internally with None

Example
let prev_hessian = state.take_prev_hessian();  // Option<H>

Returns a reference to the current inverse Hessian

Example
let inv_hessian = state.get_inv_hessian();  // Option<&H>

Moves the inverse Hessian out and replaces it internally with None

Example
let inv_hessian = state.take_inv_hessian();  // Option<H>

Returns a reference to the previous inverse Hessian

Example
let prev_inv_hessian = state.get_prev_inv_hessian();  // Option<&H>

Moves the previous Hessian out and replaces it internally with None

Example
let prev_inv_hessian = state.take_prev_inv_hessian();  // Option<H>

Returns a reference to the current Jacobian

Example
let jacobian = state.get_jacobian();  // Option<&J>

Moves the Jacobian out and replaces it internally with None

Example
let jacobian = state.take_jacobian();  // Option<J>

Returns a reference to the previous Jacobian

Example
let prev_jacobian = state.get_prev_jacobian();  // Option<&J>

Moves the previous Jacobian out and replaces it internally with None

Example
let prev_jacobian = state.take_prev_jacobian();  // Option<J>

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Deserialize this value from the given Serde deserializer. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

Name of the solver. Mainly used in Observers.

Initializes the algorithm. Read more

Computes a single iteration of the algorithm and has access to the optimization problem definition and the internal state of the solver. Returns an updated state and optionally a KV which holds key-value pairs used in Observers. Read more

Checks whether basic termination reasons apply. Read more

Used to implement stopping criteria, in particular criteria which are not covered by (terminate_internal. Read more

Name of the solver. Mainly used in Observers.

Initializes the algorithm. Read more

Computes a single iteration of the algorithm and has access to the optimization problem definition and the internal state of the solver. Returns an updated state and optionally a KV which holds key-value pairs used in Observers. Read more

Checks whether basic termination reasons apply. Read more

Used to implement stopping criteria, in particular criteria which are not covered by (terminate_internal. Read more

Name of the solver. Mainly used in Observers.

Initializes the algorithm. Read more

Computes a single iteration of the algorithm and has access to the optimization problem definition and the internal state of the solver. Returns an updated state and optionally a KV which holds key-value pairs used in Observers. Read more

Used to implement stopping criteria, in particular criteria which are not covered by (terminate_internal. Read more

Checks whether basic termination reasons apply. Read more

Perform one iteration of CG algorithm

Name of the solver. Mainly used in Observers.

Initializes the algorithm. Read more

Checks whether basic termination reasons apply. Read more

Used to implement stopping criteria, in particular criteria which are not covered by (terminate_internal. Read more

Name of the solver. Mainly used in Observers.

Initializes the algorithm. Read more

Computes a single iteration of the algorithm and has access to the optimization problem definition and the internal state of the solver. Returns an updated state and optionally a KV which holds key-value pairs used in Observers. Read more

Used to implement stopping criteria, in particular criteria which are not covered by (terminate_internal. Read more

Checks whether basic termination reasons apply. Read more

Perform one iteration of SA algorithm

Name of the solver. Mainly used in Observers.

Initializes the algorithm. Read more

Used to implement stopping criteria, in particular criteria which are not covered by (terminate_internal. Read more

Checks whether basic termination reasons apply. Read more

Name of the solver. Mainly used in Observers.

Computes a single iteration of the algorithm and has access to the optimization problem definition and the internal state of the solver. Returns an updated state and optionally a KV which holds key-value pairs used in Observers. Read more

Used to implement stopping criteria, in particular criteria which are not covered by (terminate_internal. Read more

Initializes the algorithm. Read more

Checks whether basic termination reasons apply. Read more

Name of the solver. Mainly used in Observers.

Initializes the algorithm. Read more

Computes a single iteration of the algorithm and has access to the optimization problem definition and the internal state of the solver. Returns an updated state and optionally a KV which holds key-value pairs used in Observers. Read more

Checks whether basic termination reasons apply. Read more

Used to implement stopping criteria, in particular criteria which are not covered by (terminate_internal. Read more

Name of the solver. Mainly used in Observers.

Computes a single iteration of the algorithm and has access to the optimization problem definition and the internal state of the solver. Returns an updated state and optionally a KV which holds key-value pairs used in Observers. Read more

Initializes the algorithm. Read more

Checks whether basic termination reasons apply. Read more

Used to implement stopping criteria, in particular criteria which are not covered by (terminate_internal. Read more

Name of the solver. Mainly used in Observers.

Computes a single iteration of the algorithm and has access to the optimization problem definition and the internal state of the solver. Returns an updated state and optionally a KV which holds key-value pairs used in Observers. Read more

Initializes the algorithm. Read more

Checks whether basic termination reasons apply. Read more

Used to implement stopping criteria, in particular criteria which are not covered by (terminate_internal. Read more

Name of the solver. Mainly used in Observers.

Initializes the algorithm. Read more

Computes a single iteration of the algorithm and has access to the optimization problem definition and the internal state of the solver. Returns an updated state and optionally a KV which holds key-value pairs used in Observers. Read more

Used to implement stopping criteria, in particular criteria which are not covered by (terminate_internal. Read more

Checks whether basic termination reasons apply. Read more

Name of the solver. Mainly used in Observers.

Initializes the algorithm. Read more

Computes a single iteration of the algorithm and has access to the optimization problem definition and the internal state of the solver. Returns an updated state and optionally a KV which holds key-value pairs used in Observers. Read more

Used to implement stopping criteria, in particular criteria which are not covered by (terminate_internal. Read more

Checks whether basic termination reasons apply. Read more

Name of the solver. Mainly used in Observers.

Initializes the algorithm. Read more

Computes a single iteration of the algorithm and has access to the optimization problem definition and the internal state of the solver. Returns an updated state and optionally a KV which holds key-value pairs used in Observers. Read more

Checks whether basic termination reasons apply. Read more

Used to implement stopping criteria, in particular criteria which are not covered by (terminate_internal. Read more

Name of the solver. Mainly used in Observers.

Initializes the algorithm. Read more

Computes a single iteration of the algorithm and has access to the optimization problem definition and the internal state of the solver. Returns an updated state and optionally a KV which holds key-value pairs used in Observers. Read more

Used to implement stopping criteria, in particular criteria which are not covered by (terminate_internal. Read more

Checks whether basic termination reasons apply. Read more

Name of the solver. Mainly used in Observers.

Initializes the algorithm. Read more

Computes a single iteration of the algorithm and has access to the optimization problem definition and the internal state of the solver. Returns an updated state and optionally a KV which holds key-value pairs used in Observers. Read more

Used to implement stopping criteria, in particular criteria which are not covered by (terminate_internal. Read more

Checks whether basic termination reasons apply. Read more

Name of the solver. Mainly used in Observers.

Computes a single iteration of the algorithm and has access to the optimization problem definition and the internal state of the solver. Returns an updated state and optionally a KV which holds key-value pairs used in Observers. Read more

Used to implement stopping criteria, in particular criteria which are not covered by (terminate_internal. Read more

Initializes the algorithm. Read more

Checks whether basic termination reasons apply. Read more

Name of the solver. Mainly used in Observers.

Computes a single iteration of the algorithm and has access to the optimization problem definition and the internal state of the solver. Returns an updated state and optionally a KV which holds key-value pairs used in Observers. Read more

Initializes the algorithm. Read more

Checks whether basic termination reasons apply. Read more

Used to implement stopping criteria, in particular criteria which are not covered by (terminate_internal. Read more

Name of the solver. Mainly used in Observers.

Initializes the algorithm. Read more

Computes a single iteration of the algorithm and has access to the optimization problem definition and the internal state of the solver. Returns an updated state and optionally a KV which holds key-value pairs used in Observers. Read more

Used to implement stopping criteria, in particular criteria which are not covered by (terminate_internal. Read more

Checks whether basic termination reasons apply. Read more

Name of the solver. Mainly used in Observers.

Initializes the algorithm. Read more

Computes a single iteration of the algorithm and has access to the optimization problem definition and the internal state of the solver. Returns an updated state and optionally a KV which holds key-value pairs used in Observers. Read more

Used to implement stopping criteria, in particular criteria which are not covered by (terminate_internal. Read more

Checks whether basic termination reasons apply. Read more

Name of the solver. Mainly used in Observers.

Initializes the algorithm. Read more

Computes a single iteration of the algorithm and has access to the optimization problem definition and the internal state of the solver. Returns an updated state and optionally a KV which holds key-value pairs used in Observers. Read more

Used to implement stopping criteria, in particular criteria which are not covered by (terminate_internal. Read more

Checks whether basic termination reasons apply. Read more

Name of the solver. Mainly used in Observers.

Computes a single iteration of the algorithm and has access to the optimization problem definition and the internal state of the solver. Returns an updated state and optionally a KV which holds key-value pairs used in Observers. Read more

Used to implement stopping criteria, in particular criteria which are not covered by (terminate_internal. Read more

Initializes the algorithm. Read more

Checks whether basic termination reasons apply. Read more

Name of the solver. Mainly used in Observers.

Initializes the algorithm. Read more

Computes a single iteration of the algorithm and has access to the optimization problem definition and the internal state of the solver. Returns an updated state and optionally a KV which holds key-value pairs used in Observers. Read more

Used to implement stopping criteria, in particular criteria which are not covered by (terminate_internal. Read more

Checks whether basic termination reasons apply. Read more

Name of the solver. Mainly used in Observers.

Computes a single iteration of the algorithm and has access to the optimization problem definition and the internal state of the solver. Returns an updated state and optionally a KV which holds key-value pairs used in Observers. Read more

Used to implement stopping criteria, in particular criteria which are not covered by (terminate_internal. Read more

Initializes the algorithm. Read more

Checks whether basic termination reasons apply. Read more

Name of the solver. Mainly used in Observers.

Computes a single iteration of the algorithm and has access to the optimization problem definition and the internal state of the solver. Returns an updated state and optionally a KV which holds key-value pairs used in Observers. Read more

Used to implement stopping criteria, in particular criteria which are not covered by (terminate_internal. Read more

Initializes the algorithm. Read more

Checks whether basic termination reasons apply. Read more

Name of the solver. Mainly used in Observers.

Initializes the algorithm. Read more

Computes a single iteration of the algorithm and has access to the optimization problem definition and the internal state of the solver. Returns an updated state and optionally a KV which holds key-value pairs used in Observers. Read more

Used to implement stopping criteria, in particular criteria which are not covered by (terminate_internal. Read more

Checks whether basic termination reasons apply. Read more

Name of the solver. Mainly used in Observers.

Computes a single iteration of the algorithm and has access to the optimization problem definition and the internal state of the solver. Returns an updated state and optionally a KV which holds key-value pairs used in Observers. Read more

Initializes the algorithm. Read more

Checks whether basic termination reasons apply. Read more

Used to implement stopping criteria, in particular criteria which are not covered by (terminate_internal. Read more

Type of parameter vector

Floating point precision

Create a new IterState instance

Example
let state: IterState<Vec<f64>, Vec<f64>, Vec<Vec<f64>>, Vec<Vec<f64>>, f64> = IterState::new();

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: IterState<Vec<f64>, (), (), (), f64> = IterState::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: IterState<Vec<f64>, (), (), (), f64> = IterState::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());

Returns a reference to the current parameter vector

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

Returns a reference to the current best parameter vector

Example
let best_param = state.get_best_param();  // Option<&P>

Sets the termination reason (default: TerminationReason::NotTerminated)

Example
let state = state.termination_reason(TerminationReason::MaxItersReached);

Sets the time required so far.

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

Returns current cost function value.

Example
let cost = state.get_cost();

Returns current best cost function value.

Example
let best_cost = state.get_best_cost();

Returns target cost function value.

Example
let target_cost = state.get_target_cost();

Returns current number of iterations.

Example
let iter = state.get_iter();

Returns iteration number of last best parameter vector.

Example
let last_best_iter = state.get_last_best_iter();

Returns the maximum number of iterations.

Example
let max_iters = state.get_max_iters();

Returns the termination reason.

Example
let termination_reason = state.get_termination_reason();

Returns the time elapsed since the start of the optimization.

Example
let time = state.get_time();

Increments the number of iterations by one

Example
state.increment_iter();

Set all function evaluation counts to the evaluation counts of another Problem.

state.func_counts(&problem);

Returns function evaluation counts

Example
let counts = state.get_func_counts();

Returns whether the current parameter vector is also the best parameter vector found so far.

Example
let is_best = state.is_best();

Return whether the algorithm has terminated or not

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Should always be Self

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

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

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

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

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.