pub struct NSGAII { /* private fields */ }Expand description
NSGA-II (Non-dominated Sorting Genetic Algorithm II) implementation
A state-of-the-art evolutionary algorithm for multi-objective optimization that maintains a diverse set of Pareto-optimal solutions.
§Examples
ⓘ
use sklears_multioutput::optimization::evolutionary_multi_objective::NSGAII;
// Use SciRS2-Core for arrays and random number generation (SciRS2 Policy)
use scirs2_core::ndarray::array;
// Define a multi-objective function (minimize both objectives)
let objectives = |x: &scirs2_autograd::scirs2_core::ndarray::ArrayView1`<f64>`| {
let obj1 = x[0].powi(2) + x[1].powi(2); // Minimize distance from origin
let obj2 = (x[0] - 1.0).powi(2) + (x[1] - 1.0).powi(2); // Minimize distance from (1,1)
array![obj1, obj2]
};
let nsga2 = NSGAII::new()
.population_size(100)
.n_generations(50)
.crossover_probability(0.9)
.mutation_probability(0.1)
.variable_bounds(vec![(-2.0, 2.0), (-2.0, 2.0)])
.random_state(42);
let result = nsga2.optimize(objectives, 2).unwrap();
assert!(result.pareto_front().len() > 0);Implementations§
Source§impl NSGAII
impl NSGAII
Sourcepub fn population_size(self, size: usize) -> Self
pub fn population_size(self, size: usize) -> Self
Set the population size
Sourcepub fn n_generations(self, generations: usize) -> Self
pub fn n_generations(self, generations: usize) -> Self
Set the number of generations
Sourcepub fn crossover_probability(self, prob: Float) -> Self
pub fn crossover_probability(self, prob: Float) -> Self
Set the crossover probability
Sourcepub fn mutation_probability(self, prob: Float) -> Self
pub fn mutation_probability(self, prob: Float) -> Self
Set the mutation probability
Sourcepub fn variable_bounds(self, bounds: Vec<(Float, Float)>) -> Self
pub fn variable_bounds(self, bounds: Vec<(Float, Float)>) -> Self
Set bounds for decision variables
Sourcepub fn random_state(self, seed: u64) -> Self
pub fn random_state(self, seed: u64) -> Self
Set random state for reproducibility
Sourcepub fn crossover_eta(self, eta: Float) -> Self
pub fn crossover_eta(self, eta: Float) -> Self
Set crossover distribution index (higher values = more uniform crossover)
Sourcepub fn mutation_eta(self, eta: Float) -> Self
pub fn mutation_eta(self, eta: Float) -> Self
Set mutation distribution index (higher values = smaller mutations)
Sourcepub fn optimize<F>(
&self,
objective_fn: F,
n_objectives: usize,
) -> SklResult<OptimizationResult>
pub fn optimize<F>( &self, objective_fn: F, n_objectives: usize, ) -> SklResult<OptimizationResult>
Optimize a multi-objective function using NSGA-II
Trait Implementations§
Auto Trait Implementations§
impl Freeze for NSGAII
impl RefUnwindSafe for NSGAII
impl Send for NSGAII
impl Sync for NSGAII
impl Unpin for NSGAII
impl UnwindSafe for NSGAII
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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