pub struct CobylaState {Show 20 fields
pub param: Option<Vec<f64>>,
pub prev_param: Option<Vec<f64>>,
pub best_param: Option<Vec<f64>>,
pub prev_best_param: Option<Vec<f64>>,
pub cost: Option<Vec<f64>>,
pub prev_cost: Option<Vec<f64>>,
pub best_cost: Option<Vec<f64>>,
pub prev_best_cost: Option<Vec<f64>>,
pub target_cost: f64,
pub iter: u64,
pub last_best_iter: u64,
pub max_iters: u64,
pub counts: HashMap<String, u64>,
pub time: Option<Duration>,
pub termination_status: TerminationStatus,
pub rhobeg: f64,
pub rhoend: f64,
pub iprint: i32,
pub maxfun: i32,
pub cobyla_context: Option<ManuallyDrop<*mut _cobyla_context>>,
}Expand description
Maintains the state from iteration to iteration of the crate::CobylaSolver.
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 (objective and constraint functions values) 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
- elapsed time
- termination status
- COBYLA specific parameters: rhobeg, rhoend, iprint, maxfun
Fields§
§param: Option<Vec<f64>>Current parameter vector
prev_param: Option<Vec<f64>>Previous parameter vector
best_param: Option<Vec<f64>>Current best parameter vector
prev_best_param: Option<Vec<f64>>Previous best parameter vector
cost: Option<Vec<f64>>Current cost function value
prev_cost: Option<Vec<f64>>Previous cost function value
best_cost: Option<Vec<f64>>Current best cost function value
prev_best_cost: Option<Vec<f64>>Previous best cost function value
target_cost: f64Target cost function value
iter: u64Current iteration
last_best_iter: u64Iteration number of last best cost
max_iters: u64Maximum number of iterations
counts: HashMap<String, u64>Evaluation counts
time: Option<Duration>Time required so far
termination_status: TerminationStatusStatus of optimization execution
rhobeg: f64Rho start value
rhoend: f64Rho end value
iprint: i32Control of traces
maxfun: i32Cost function calls budget
cobyla_context: Option<ManuallyDrop<*mut _cobyla_context>>Implementations§
Source§impl CobylaState
impl CobylaState
Sourcepub fn param(self, param: Vec<f64>) -> Self
pub fn param(self, param: Vec<f64>) -> Self
Set parameter vector. This shifts the stored parameter vector to the previous parameter vector.
§Example
let state = state.param(param);Sourcepub fn target_cost(self, target_cost: f64) -> Self
pub fn target_cost(self, target_cost: f64) -> 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);Sourcepub fn cost(self, cost: Vec<f64>) -> Self
pub fn cost(self, cost: Vec<f64>) -> 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(vec![cost]);Sourcepub fn get_full_cost(&self) -> Option<&Vec<f64>>
pub fn get_full_cost(&self) -> Option<&Vec<f64>>
Returns current cost (ie objective) function and constraint values.
§Example
let cost = state.get_full_cost();Sourcepub fn get_full_best_cost(&self) -> Option<&Vec<f64>>
pub fn get_full_best_cost(&self) -> Option<&Vec<f64>>
Returns current cost (ie objective) function and constraint values.
§Example
let cost = state.get_full_best_cost();Sourcepub fn get_rhoend(&self) -> f64
pub fn get_rhoend(&self) -> f64
Returns the rho end value
Sourcepub fn get_iprint(&self) -> i32
pub fn get_iprint(&self) -> i32
Returns the level of printing
Sourcepub fn get_maxfun(&self) -> i32
pub fn get_maxfun(&self) -> i32
Returns cost function calls budget
Trait Implementations§
Source§impl Clone for CobylaState
impl Clone for CobylaState
Source§fn clone(&self) -> CobylaState
fn clone(&self) -> CobylaState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CobylaState
impl Debug for CobylaState
Source§impl Default for CobylaState
impl Default for CobylaState
Source§fn default() -> CobylaState
fn default() -> CobylaState
Source§impl<O> Solver<O, CobylaState> for CobylaSolver
impl<O> Solver<O, CobylaState> for CobylaSolver
Source§fn init(
&mut self,
problem: &mut Problem<O>,
state: CobylaState,
) -> Result<(CobylaState, Option<KV>), Error>
fn init( &mut self, problem: &mut Problem<O>, state: CobylaState, ) -> Result<(CobylaState, Option<KV>), Error>
Initializes the algorithm.
Executed before any iterations are performed 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.
The default implementation returns the unaltered state and no KV.
Source§fn next_iter(
&mut self,
problem: &mut Problem<O>,
state: CobylaState,
) -> Result<(CobylaState, Option<KV>), Error>
fn next_iter( &mut self, problem: &mut Problem<O>, state: CobylaState, ) -> Result<(CobylaState, Option<KV>), Error>
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.
Source§fn terminate(&mut self, state: &CobylaState) -> TerminationStatus
fn terminate(&mut self, state: &CobylaState) -> TerminationStatus
Used to implement stopping criteria, in particular criteria which are not covered by
(terminate_internal.
This method has access to the internal state and returns an TerminationReason.
Source§fn terminate_internal(&mut self, state: &I) -> TerminationStatus
fn terminate_internal(&mut self, state: &I) -> TerminationStatus
Source§impl State for CobylaState
impl State for CobylaState
Source§fn new() -> Self
fn new() -> Self
Create new CobylaState instance
§Example
use cobyla_argmin::CobylaState;
let state: CobylaState = CobylaState::new();
Source§fn update(&mut self)
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: CobylaState = CobylaState::new();
// Simulating a new parameter vector
state.param = Some(vec![2.0f64]);
state.cost = Some(vec![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.as_ref().unwrap()[0], 5.0);
assert!(state.is_best());Source§fn get_param(&self) -> Option<&Vec<f64>>
fn get_param(&self) -> Option<&Vec<f64>>
Returns a reference to the current parameter vector
§Example
let param = state.get_param(); // Option<&P>Source§fn get_best_param(&self) -> Option<&Vec<f64>>
fn get_best_param(&self) -> Option<&Vec<f64>>
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
fn terminate_with(self, reason: TerminationReason) -> Self
Sets the termination reason
§Example
let state = state.terminate_with(TerminationReason::SolverConverged);Source§fn time(&mut self, time: Option<Duration>) -> &mut Self
fn time(&mut self, time: Option<Duration>) -> &mut Self
Sets the time required so far.
§Example
let state = state.time(Some(web_time::Duration::new(0, 12)));Source§fn get_best_cost(&self) -> Self::Float
fn get_best_cost(&self) -> Self::Float
Source§fn get_target_cost(&self) -> Self::Float
fn get_target_cost(&self) -> Self::Float
Source§fn get_last_best_iter(&self) -> u64
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
fn get_max_iters(&self) -> u64
Source§fn get_termination_status(&self) -> &TerminationStatus
fn get_termination_status(&self) -> &TerminationStatus
Source§fn get_termination_reason(&self) -> Option<&TerminationReason>
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 increment_iter(&mut self)
fn increment_iter(&mut self)
Source§fn func_counts<O>(&mut self, problem: &Problem<O>)
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 is_best(&self) -> bool
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();