Class: FeldtRuby::Optimize::SearchSpace::SetSampler

Inherits:
Sampler show all
Defined in:
lib/feldtruby/optimize/search_space.rb

Overview

Set samplers sample many candidates in one go, often to create a better “spread” of genotypes within the search space. This is an abstract base class so sub-classes ust override the sample_candidates method.

Direct Known Subclasses

LatinHypercubeSampler

Instance Attribute Summary

Attributes inherited from Sampler

#search_space

Instance Method Summary collapse

Methods inherited from Sampler

#sample_value_for_dimension

Constructor Details

#initialize(chunkSize = 200) ⇒ SetSampler

The chunk size is the number of candidates that are generated in one go and from which the individual candidates are then taken. Default is 200 to get a nice initial spread.



115
116
117
118
# File 'lib/feldtruby/optimize/search_space.rb', line 115

def initialize(chunkSize = 200)
	@chunk_size = chunkSize
	@chunk = []
end

Instance Method Details

#chunk_empty?Boolean

Returns:

  • (Boolean)


134
135
136
# File 'lib/feldtruby/optimize/search_space.rb', line 134

def chunk_empty?
	@chunk.nil? || @chunk.length < 1
end

#pop_candidate_from_chunkObject



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

def pop_candidate_from_chunk
	@chunk.pop
end

#sample_candidateObject



125
126
127
128
# File 'lib/feldtruby/optimize/search_space.rb', line 125

def sample_candidate
	sample_new_chunk() if chunk_empty?
	pop_candidate_from_chunk()
end

#sample_candidates(numCandidates) ⇒ Object

Sample a set of candidates.

Raises:

  • (NotImplementedError)


121
122
123
# File 'lib/feldtruby/optimize/search_space.rb', line 121

def sample_candidates(numCandidates)
	raise NotImplementedError # Subclasses must implement this
end

#sample_new_chunkObject



130
131
132
# File 'lib/feldtruby/optimize/search_space.rb', line 130

def sample_new_chunk
	@chunk = sample_candidates(@chunk_size)
end