Class: FeldtRuby::Optimize::RadiusLimitedPopulationSampler

Inherits:
PopulationSampler show all
Defined in:
lib/feldtruby/optimize/optimizer.rb

Overview

This implements a “trivial geography” similar to Spector and Kline (2006) by first sampling an individual randomly and then selecting additional individuals for the same tournament within a certain deme of limited size for the sub-sequent individuals in the population. The version we implement here is from:

I. Harvey, "The Microbial Genetic Algorithm", in Advances in Artificial Life
Darwin Meets von Neumann, Springer, 2011.

Instance Method Summary collapse

Methods inherited from PopulationSampler

#initialize_all_indices, #sample_indices_without_replacement

Constructor Details

#initialize(optimizer, options = FeldtRuby::Optimize::DefaultOptimizationOptions) ⇒ RadiusLimitedPopulationSampler

Returns a new instance of RadiusLimitedPopulationSampler.



138
139
140
141
# File 'lib/feldtruby/optimize/optimizer.rb', line 138

def initialize(optimizer, options = FeldtRuby::Optimize::DefaultOptimizationOptions)
  super
  @radius = options[:samplerRadius]
end

Instance Method Details

#sample_population_indices_without_replacement(numSamples) ⇒ Object



143
144
145
146
147
148
149
150
# File 'lib/feldtruby/optimize/optimizer.rb', line 143

def sample_population_indices_without_replacement(numSamples)
  i = rand(@population_size)
  indices = (i..(i+@radius)).to_a
  if (i+@radius) >= @population_size
    indices.map! {|i| i % @population_size}
  end
  sample_indices_without_replacement numSamples, indices
end