pub fn epochs(&mut self, n_epochs: u32) -> &mut Self {
        let mut processed_stack = Vec::new();
        let mut active_stack = Vec::new();

        while let Some(unit) = self.units.pop() {
            active_stack.push(LazyUnit::from(unit));
        }

        let seed: &[_] = &[self.seed];
        let mut rng: StdRng = SeedableRng::from_seed(seed);

        for i in 0..(n_epochs + 1) {
            while let Some(mut unit) = active_stack.pop() {
                unit.fitness();
                processed_stack.push(unit);
            }

            // Swap the full processed_stack with the active stack.
            mem::swap(&mut active_stack, &mut processed_stack);

            // We want to sort such that highest fitness units are at the
            // end.
            active_stack.sort_by(|a, b| {
                a.lazy_fitness
                    .unwrap_or(0.0)
                    .partial_cmp(&b.lazy_fitness.unwrap_or(0.0))
                    .unwrap_or(Ordering::Equal)
            });

            // If we have the perfect solution then break early.
            if active_stack.last().unwrap().lazy_fitness.unwrap_or(0.0) == 1.0 {
                break;
            }

            if i != n_epochs {
                rng = self.epoch(&mut active_stack, rng);
            }
        }

        // Reverse the order of units such that the first unit is the
        // strongest candidate.
        while let Some(unit) = active_stack.pop() {
            self.units.push(unit.unit);
        }

        self
    }
/// Runs a number of epochs on a single process.
Runs a number of epochs on a single process.
Runs a number of epochs on a single process .
pub fn epochs(&mut self, n_epochs: u32) -> &mut Self {
        let mut processed_stack = Vec::new();
        let mut active_stack = Vec::new();
        while let Some(unit) = self.units.pop() {
            active_stack.push(LazyUnit::from(unit));
        }
        let seed: &[_] = &[self.seed];
        let mut rng: StdRng = SeedableRng::from_seed(seed);
        for i in 0..(n_epochs + 1) {
            while let Some(mut unit) = active_stack.pop() {
                unit.fitness();
                processed_stack.push(unit);
            }
            // Swap the full processed_stack with the active stack.
            mem::swap(&mut active_stack, &mut processed_stack);
            // We want to sort such that highest fitness units are at the
            // end.
            active_stack.sort_by(|a, b| {
                a.lazy_fitness
                    .unwrap_or(0.0)
                    .partial_cmp(&b.lazy_fitness.unwrap_or(0.0))
                    .unwrap_or(Ordering::Equal)
            });
            // If we have the perfect solution then break early.
            if active_stack.last().unwrap().lazy_fitness.unwrap_or(0.0) == 1.0 {
                break;
            }
            if i != n_epochs {
                rng = self.epoch(&mut active_stack, rng);
            }
        }
        // Reverse the order of units such that the first unit is the
        // strongest candidate.
        while let Some(unit) = active_stack.pop() {
            self.units.push(unit.unit);
        }
        self
    }
pub fn epochs ( & mut self , n_epochs : u32 ) -> & mut Self { let mut processed_stack = Vec :: new ( ) ; let mut active_stack = Vec :: new ( ) ; while let Some ( unit ) = self . units . pop ( ) { active_stack . push ( LazyUnit :: from ( unit ) ) ; } let seed : & [ _ ] = & [ self . seed ] ; let mut rng : StdRng = SeedableRng :: from_seed ( seed ) ; for i in 0 .. ( n_epochs + 1 ) { while let Some ( mut unit ) = active_stack . pop ( ) { unit . fitness ( ) ; processed_stack . push ( unit ) ; } // Swap the full processed_stack with the active stack. mem :: swap ( & mut active_stack , & mut processed_stack ) ; // We want to sort such that highest fitness units are at the // end. active_stack . sort_by ( | a , b | { a . lazy_fitness . unwrap_or ( 0.0 ) . partial_cmp ( & b . lazy_fitness . unwrap_or ( 0.0 ) ) . unwrap_or ( Ordering :: Equal ) } ) ; // If we have the perfect solution then break early. if active_stack . last ( ) . unwrap ( ) . lazy_fitness . unwrap_or ( 0.0 ) == 1.0 { break ; } if i != n_epochs { rng = self . epoch ( & mut active_stack , rng ) ; } } // Reverse the order of units such that the first unit is the // strongest candidate. while let Some ( unit ) = active_stack . pop ( ) { self . units . push ( unit . unit ) ; } self }
Runs a number of epochs on a single process.
Runs a number of epochs on a single process .
&mut self
n_epochs
u32
&mut self
n_epochs
u32