fn survive(&mut self) -> &mut Self
	{
		if (self.learn_params.1 + self.learn_params.2) as usize >= self.items.len()
		{ //already done
			return self;
		}
		
		let mut rng = rand::thread_rng();
		
		if self.learn_params.4 == Strat::Deterministic
		{ //deterministic selection
			let mut bad = self.items.split_off(self.learn_params.1 as usize); //best items kept
			
			//randomly select bad items
			for _ in 0..self.learn_params.2
			{
				if bad.is_empty() { return self; }
				let i:usize = rng.gen::<usize>() % bad.len();
				self.items.push(bad.swap_remove(i));
			}
		}
		else if self.learn_params.4 == Strat::Stochastic
		{ //stochastic selection
			let mut set = Vec::new(); //index set to keep items
			let size = (self.learn_params.1 + self.learn_params.2) as usize;
			
			//randomly select distinct items non-uniformly
			for _ in 0..size
			{
				let mut contained = true;
				let mut index:usize = 0;
				while contained
				{
					index = (rng.gen::<f64>().powf(3.0) * self.items.len() as f64) as usize;
					contained = set.contains(&index);
				}
				set.push(index);
			}
			//efficiently keep only items indexed in the set
			set.sort_unstable();
			for i in 0..size
			{
				self.items.swap(i, set[i]);
			}
			self.items.truncate(size);
		}
		else
		{ //mixed selection
			let mut bad = self.items.split_off(self.learn_params.1 as usize); //best items kept
			
			let mut set = Vec::new(); //index set to keep items
			let size = self.learn_params.2 as usize;
			
			//randomly select distinct items non-uniformly
			for _ in 0..size
			{
				let mut contained = true;
				let mut index:usize = 0;
				while contained
				{
					index = (rng.gen::<f64>().powf(3.0) * bad.len() as f64) as usize;
					contained = set.contains(&index);
				}
				set.push(index);
			}
			//efficiently keep only items indexed in the set
			set.sort_unstable();
			for i in 0..size
			{
				bad.swap(i, set[i]);
			}
			bad.truncate(size);
			self.items.append(&mut bad);
		}
		
		self
	}
/// Eliminates population, so that the best "survival" items and random "bad_survival" items survive
Eliminates population, so that the best "survival" items and random "bad_survival" items survive
Eliminates population so that the best " survival " items and random " bad_survival " items survive
fn survive(&mut self) -> &mut Self
	{
		if (self.learn_params.1 + self.learn_params.2) as usize >= self.items.len()
		{ //already done
			return self;
		}
		let mut rng = rand::thread_rng();
		if self.learn_params.4 == Strat::Deterministic
		{ //deterministic selection
			let mut bad = self.items.split_off(self.learn_params.1 as usize); //best items kept
			//randomly select bad items
			for _ in 0..self.learn_params.2
			{
				if bad.is_empty() { return self; }
				let i:usize = rng.gen::<usize>() % bad.len();
				self.items.push(bad.swap_remove(i));
			}
		}
		else if self.learn_params.4 == Strat::Stochastic
		{ //stochastic selection
			let mut set = Vec::new(); //index set to keep items
			let size = (self.learn_params.1 + self.learn_params.2) as usize;
			//randomly select distinct items non-uniformly
			for _ in 0..size
			{
				let mut contained = true;
				let mut index:usize = 0;
				while contained
				{
					index = (rng.gen::<f64>().powf(3.0) * self.items.len() as f64) as usize;
					contained = set.contains(&index);
				}
				set.push(index);
			}
			//efficiently keep only items indexed in the set
			set.sort_unstable();
			for i in 0..size
			{
				self.items.swap(i, set[i]);
			}
			self.items.truncate(size);
		}
		else
		{ //mixed selection
			let mut bad = self.items.split_off(self.learn_params.1 as usize); //best items kept
			let mut set = Vec::new(); //index set to keep items
			let size = self.learn_params.2 as usize;
			//randomly select distinct items non-uniformly
			for _ in 0..size
			{
				let mut contained = true;
				let mut index:usize = 0;
				while contained
				{
					index = (rng.gen::<f64>().powf(3.0) * bad.len() as f64) as usize;
					contained = set.contains(&index);
				}
				set.push(index);
			}
			//efficiently keep only items indexed in the set
			set.sort_unstable();
			for i in 0..size
			{
				bad.swap(i, set[i]);
			}
			bad.truncate(size);
			self.items.append(&mut bad);
		}
		self
	}
fn survive ( & mut self ) -> & mut Self { if ( self . learn_params . 1 + self . learn_params . 2 ) as usize >= self . items . len ( ) { //already done return self ; } let mut rng = rand :: thread_rng ( ) ; if self . learn_params . 4 == Strat :: Deterministic { //deterministic selection let mut bad = self . items . split_off ( self . learn_params . 1 as usize ) ; //best items kept //randomly select bad items for _ in 0 .. self . learn_params . 2 { if bad . is_empty ( ) { return self ; } let i : usize = rng . gen :: < usize > ( ) % bad . len ( ) ; self . items . push ( bad . swap_remove ( i ) ) ; } } else if self . learn_params . 4 == Strat :: Stochastic { //stochastic selection let mut set = Vec :: new ( ) ; //index set to keep items let size = ( self . learn_params . 1 + self . learn_params . 2 ) as usize ; //randomly select distinct items non-uniformly for _ in 0 .. size { let mut contained = true ; let mut index : usize = 0 ; while contained { index = ( rng . gen :: < f64 > ( ) . powf ( 3.0 ) * self . items . len ( ) as f64 ) as usize ; contained = set . contains ( & index ) ; } set . push ( index ) ; } //efficiently keep only items indexed in the set set . sort_unstable ( ) ; for i in 0 .. size { self . items . swap ( i , set [ i ] ) ; } self . items . truncate ( size ) ; } else { //mixed selection let mut bad = self . items . split_off ( self . learn_params . 1 as usize ) ; //best items kept let mut set = Vec :: new ( ) ; //index set to keep items let size = self . learn_params . 2 as usize ; //randomly select distinct items non-uniformly for _ in 0 .. size { let mut contained = true ; let mut index : usize = 0 ; while contained { index = ( rng . gen :: < f64 > ( ) . powf ( 3.0 ) * bad . len ( ) as f64 ) as usize ; contained = set . contains ( & index ) ; } set . push ( index ) ; } //efficiently keep only items indexed in the set set . sort_unstable ( ) ; for i in 0 .. size { bad . swap ( i , set [ i ] ) ; } bad . truncate ( size ) ; self . items . append ( & mut bad ) ; } self }
Eliminates population, so that the best "survival" items and random "bad_survival" items survive
Eliminates population so that the best " survival " items and random " bad_survival " items survive
&mut self
&mut self