Trait argmin::core::State

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

Show 20 methods // Required 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>; // Provided method 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§

source

type Param

Type of parameter vector

source

type Float: ArgminFloat

Floating point precision (f32 or f64)

Required Methods§

source

fn new() -> Self

Construct a new state

source

fn update(&mut self)

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.

source

fn get_param(&self) -> Option<&Self::Param>

Returns a reference to the current parameter vector

source

fn get_best_param(&self) -> Option<&Self::Param>

Returns a reference to the current best parameter vector

source

fn get_max_iters(&self) -> u64

Returns maximum number of iterations that are to be performed

source

fn increment_iter(&mut self)

Increment the number of iterations by one

source

fn get_iter(&self) -> u64

Returns current number of iterations

source

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

Returns current cost function value

source

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

Returns best cost function value

source

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

Returns target cost

source

fn func_counts<O>(&mut self, problem: &Problem<O>)

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

source

fn get_func_counts(&self) -> &HashMap<String, u64>

Returns current cost function evaluation count

source

fn time(&mut self, time: Option<Duration>) -> &mut Self

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

source

fn get_time(&self) -> Option<Duration>

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

source

fn get_last_best_iter(&self) -> u64

Returns iteration number where the last best parameter vector was found

source

fn is_best(&self) -> bool

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

source

fn terminate_with(self, termination_reason: TerminationReason) -> Self

Sets the termination status to Terminated with the given reason

source

fn get_termination_status(&self) -> &TerminationStatus

Returns termination status.

source

fn get_termination_reason(&self) -> Option<&TerminationReason>

Returns the termination reason if terminated, otherwise None.

Provided Methods§

source

fn terminated(&self) -> bool

Return whether the algorithm has terminated or not

Object Safety§

This trait is not object safe.

Implementors§

source§

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

§

type Param = P

§

type Float = F

source§

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

§

type Param = P

§

type Float = F

source§

impl<P, G, J, H, R, F> State for IterState<P, G, J, H, R, F>
where P: Clone, F: ArgminFloat,

§

type Param = P

§

type Float = F