Trait argmin::core::State

source ·
pub trait State {
    type Param;
    type Float: ArgminFloat;

Show 20 methods fn new() -> Self; fn update(&mut self); fn get_param(&self) -> Option<&Self::Param>; fn get_best_param(&self) -> Option<&Self::Param>; fn get_max_iters(&self) -> u64; fn increment_iter(&mut self); fn get_iter(&self) -> u64; fn get_cost(&self) -> Self::Float; fn get_best_cost(&self) -> Self::Float; fn get_target_cost(&self) -> Self::Float; fn func_counts<O>(&mut self, problem: &Problem<O>); fn get_func_counts(&self) -> &HashMap<String, u64>; fn time(&mut self, time: Option<Duration>) -> &mut Self; fn get_time(&self) -> Option<Duration>; fn get_last_best_iter(&self) -> u64; fn is_best(&self) -> bool; fn terminate_with(self, termination_reason: TerminationReason) -> Self; fn get_termination_status(&self) -> &TerminationStatus; fn get_termination_reason(&self) -> Option<&TerminationReason>; fn terminated(&self) -> bool { ... }
}
Expand description

Minimal interface which struct used for managing state in solvers have to implement.

These methods expose basic information about the state which is needed in Executor and OptimizationResult but can also be useful in observers.

The struct implementing this trait should keep track of

  • the current parameter vector
  • the cost associated with the current parameter vector
  • the current best parameter vector
  • the cost associated with the current best parameter vector
  • the iteration number where the last best parameter vector was found
  • the target cost function value (If this value is reached, the optimization will be stopped). Set this to Self::Float::NEG_INFINITY if not relevant.
  • the current number of iterations
  • how often each function of the problem has been called
  • the time required since the beginning of the optimization until the current point in time
  • the status of optimization execution (TerminationStatus)

Since the state in general changes for each iteration, “current” refers to the current iteration.

State::Param indicates the type of the parameter vector while State::Float indicates the precision of floating point operations. Any type implementing ArgminFloat can be used for this (so far f32 and f64).

Required Associated Types§

Type of parameter vector

Floating point precision (f32 or f64)

Required Methods§

Construct a new state

This method is called after each iteration and checks if the new parameter vector is better than the previous one. If so, it will update the current best parameter vector and current best cost function value.

For methods where the cost function value is unknown, it is advised to assume that every new parameter vector is better than the previous one.

Returns a reference to the current parameter vector

Returns a reference to the current best parameter vector

Returns maximum number of iterations that are to be performed

Increment the number of iterations by one

Returns current number of iterations

Returns current cost function value

Returns best cost function value

Returns target cost

Set all function evaluation counts to the evaluation counts of another operator wrapped in Problem.

Returns current cost function evaluation count

Set time required since the beginning of the optimization until the current iteration

Get time passed since the beginning of the optimization until the current iteration

Returns iteration number where the last best parameter vector was found

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

Sets the termination status to Terminated with the given reason

Returns termination status.

Returns the termination reason if terminated, otherwise None.

Provided Methods§

Return whether the algorithm has terminated or not

Implementors§