pub struct RandomSearch<I> {
pub config: RandomSearchConfig,
pub initializer: I,
}Expand description
Sample-evaluate-keep baseline optimizer.
Each iteration the configured Initializer produces batch_size decisions
which are evaluated and pushed into the population. Cheap, parallelism-free,
and useful as a sanity-check baseline.
§Example
use heuropt::prelude::*;
struct Sphere;
impl Problem for Sphere {
type Decision = Vec<f64>;
fn objectives(&self) -> ObjectiveSpace {
ObjectiveSpace::new(vec![Objective::minimize("f")])
}
fn evaluate(&self, x: &Vec<f64>) -> Evaluation {
Evaluation::new(vec![x.iter().map(|v| v * v).sum::<f64>()])
}
}
let mut opt = RandomSearch::new(
RandomSearchConfig { iterations: 200, batch_size: 10, seed: 42 },
RealBounds::new(vec![(-5.0, 5.0); 3]),
);
let r = opt.run(&Sphere);
assert_eq!(r.evaluations, 200 * 10);
assert!(r.best.is_some());Fields§
§config: RandomSearchConfigAlgorithm configuration.
initializer: IDecision-sampling strategy.
Implementations§
Source§impl<I> RandomSearch<I>
impl<I> RandomSearch<I>
Sourcepub fn new(config: RandomSearchConfig, initializer: I) -> Self
pub fn new(config: RandomSearchConfig, initializer: I) -> Self
Construct a RandomSearch from its config and initializer.
Trait Implementations§
Source§impl<I> AlgorithmInfo for RandomSearch<I>
impl<I> AlgorithmInfo for RandomSearch<I>
Source§fn name(&self) -> &'static str
fn name(&self) -> &'static str
Canonical short algorithm name — e.g.
"NSGA-II",
"DE", "CMA-ES". This is the form that should appear
in tables, plot legends, and exported JSON metadata.Source§impl<I: Clone> Clone for RandomSearch<I>
impl<I: Clone> Clone for RandomSearch<I>
Source§fn clone(&self) -> RandomSearch<I>
fn clone(&self) -> RandomSearch<I>
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 moreSource§impl<I: Debug> Debug for RandomSearch<I>
impl<I: Debug> Debug for RandomSearch<I>
Auto Trait Implementations§
impl<I> Freeze for RandomSearch<I>where
I: Freeze,
impl<I> RefUnwindSafe for RandomSearch<I>where
I: RefUnwindSafe,
impl<I> Send for RandomSearch<I>where
I: Send,
impl<I> Sync for RandomSearch<I>where
I: Sync,
impl<I> Unpin for RandomSearch<I>where
I: Unpin,
impl<I> UnsafeUnpin for RandomSearch<I>where
I: UnsafeUnpin,
impl<I> UnwindSafe for RandomSearch<I>where
I: UnwindSafe,
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