pub struct SimulatedAnnealing;Expand description
Simulated-annealing local search.
A unit struct: all configuration lives in SimulatedAnnealingParams, so
one instance can refine many genomes. See the module docs for the
acceptance rule and the best-so-far tracking that upholds the
LocalSearch contract.
§Example
use burn::backend::Flex;
use rand::{rngs::StdRng, SeedableRng};
use rlevo_evolution::fitness::FitnessFn;
use rlevo_core::bounds::Bounds;
use rlevo_evolution::local_search::{LocalSearch, SimulatedAnnealing, SimulatedAnnealingParams};
// Maximize the negated 2-D sphere; the optimum is the origin with fitness 0.
struct NegSphere;
impl FitnessFn<Vec<f32>> for NegSphere {
fn evaluate_one(&mut self, x: &Vec<f32>) -> f32 {
-x.iter().map(|v| v * v).sum::<f32>()
}
}
let searcher = SimulatedAnnealing;
let params = SimulatedAnnealingParams::default_for(Bounds::new(-5.12, 5.12));
let mut fitness = NegSphere;
let mut rng = StdRng::seed_from_u64(7);
let start = vec![2.5_f32, -1.5];
let start_fit: f32 = -start.iter().map(|v| v * v).sum::<f32>();
let (refined, refined_fit) =
LocalSearch::<Flex>::refine(&searcher, ¶ms, start, &mut fitness, &mut rng);
assert_eq!(refined.len(), 2); // dimensionality preserved
assert!(refined_fit >= start_fit); // monotone non-worseningTrait Implementations§
Source§impl Clone for SimulatedAnnealing
impl Clone for SimulatedAnnealing
Source§fn clone(&self) -> SimulatedAnnealing
fn clone(&self) -> SimulatedAnnealing
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for SimulatedAnnealing
Source§impl Debug for SimulatedAnnealing
impl Debug for SimulatedAnnealing
Source§impl Default for SimulatedAnnealing
impl Default for SimulatedAnnealing
Source§fn default() -> SimulatedAnnealing
fn default() -> SimulatedAnnealing
Returns the “default value” for a type. Read more
Source§impl<B: Backend> LocalSearch<B> for SimulatedAnnealing
impl<B: Backend> LocalSearch<B> for SimulatedAnnealing
Source§fn refine(
&self,
params: &SimulatedAnnealingParams,
genome: Vec<f32>,
fitness_fn: &mut dyn FitnessFn<Vec<f32>>,
rng: &mut dyn Rng,
) -> (Vec<f32>, f32)
fn refine( &self, params: &SimulatedAnnealingParams, genome: Vec<f32>, fitness_fn: &mut dyn FitnessFn<Vec<f32>>, rng: &mut dyn Rng, ) -> (Vec<f32>, f32)
§Panics
Panics if params.max_iters == 0; see refine_impl.
Source§fn refine_with_known_fitness(
&self,
params: &SimulatedAnnealingParams,
genome: Vec<f32>,
known_fitness: f32,
fitness_fn: &mut dyn FitnessFn<Vec<f32>>,
rng: &mut dyn Rng,
) -> (Vec<f32>, f32)
fn refine_with_known_fitness( &self, params: &SimulatedAnnealingParams, genome: Vec<f32>, known_fitness: f32, fitness_fn: &mut dyn FitnessFn<Vec<f32>>, rng: &mut dyn Rng, ) -> (Vec<f32>, f32)
Seeds the walker and best-so-far tracker with known_fitness (sanitizing
NaN to -inf) instead of re-scoring the input, saving one eval.
§Panics
Panics if params.max_iters == 0; see refine_impl.
Source§type Params = SimulatedAnnealingParams
type Params = SimulatedAnnealingParams
Static configuration for a refinement run (bounds, budget, step
sizes, …). Cloned by a memetic wrapper once per generation.
Auto Trait Implementations§
impl Freeze for SimulatedAnnealing
impl RefUnwindSafe for SimulatedAnnealing
impl Send for SimulatedAnnealing
impl Sync for SimulatedAnnealing
impl Unpin for SimulatedAnnealing
impl UnsafeUnpin for SimulatedAnnealing
impl UnwindSafe for SimulatedAnnealing
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<C> CloneExpand for Cwhere
C: Clone,
impl<C> CloneExpand for Cwhere
C: Clone,
fn __expand_clone_method(&self, _scope: &mut Scope) -> C
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more