Class: Selection::RankSampling
- Inherits:
-
Object
- Object
- Selection::RankSampling
- Defined in:
- ../lib/rank_sampling.rb
Overview
“Stochastic Universal Sampling” selection using given Ranking instance. Selection operator which uses SUS selection applied on :proportion value of pre-ranked individuals.
Instance Attribute Summary (collapse)
-
- (Object) population
The population to select from.
Instance Method Summary (collapse)
-
- (RankSampling) initialize(ranker)
constructor
Set the instance of the Ranking object which will be used for ranking the population before the selection.
-
- (Object) random=(rnd)
Set the source of randomness for the roulette, using Sampling#random=.
-
- (Object) select(how_much, population = self.population)
Rank the population and then select individuals from it.
-
- (Object) select_one(population = self.population)
Rank the population and then select one individual from it.
Constructor Details
- (RankSampling) initialize(ranker)
Set the instance of the Ranking object which will be used for ranking the population before the selection.
16 17 18 19 20 21 |
# File '../lib/rank_sampling.rb', line 16 def initialize ranker raise "RankSampling: invalid Ranking object" unless ranker.kind_of? Ranking @ranker = ranker @sampling = Sampling.new :proportion @population = nil end |
Instance Attribute Details
- (Object) population
The population to select from.
24 25 26 |
# File '../lib/rank_sampling.rb', line 24 def population @population end |
Instance Method Details
- (Object) random=(rnd)
Set the source of randomness for the roulette, using Sampling#random=
27 28 29 |
# File '../lib/rank_sampling.rb', line 27 def random= rnd @sampling.random = rnd end |
- (Object) select(how_much, population = self.population)
Rank the population and then select individuals from it. The stochastic “slots” are :proportion-al. It can be specified how_much individuals will be selected.
33 34 35 36 37 38 |
# File '../lib/rank_sampling.rb', line 33 def select( how_much, population=self.population ) ranked = @ranker.rank( population ) @population = population @sampling.select( how_much, ranked ).map { |individual| individual.original } end |
- (Object) select_one(population = self.population)
Rank the population and then select one individual from it. The stochastic “slots” are :proportion-al.
42 43 44 |
# File '../lib/rank_sampling.rb', line 42 def select_one population=self.population select( 1, population ).first end |