Module: Evolvable::ClassMethods
- Defined in:
- lib/evolvable.rb
Instance Method Summary collapse
-
#after_evolution(population) ⇒ Object
Runs after evolution.
-
#before_evaluation(population) ⇒ Object
Runs before evaluation.
-
#before_evolution(population) ⇒ Object
Runs after evaluation and before evolution.
-
#gene_space ⇒ Object
deprecated
Deprecated.
Will be removed in version 2.0. Use #search_space instead.
- #initialize_evolvable ⇒ Object
-
#new_evolvable(population: nil, genome: Genome.new, generation_index: nil) ⇒ Object
Initializes a new instance.
-
#new_population(keyword_args = {}) ⇒ Object
Initializes a population using configurable defaults that can be configured and optimized.
- #new_search_space ⇒ Object
-
#search_space ⇒ Hash, Array
abstract
This method is responsible for configuring the available gene types of evolvable instances.
- #search_spaces ⇒ Array abstract
Instance Method Details
#after_evolution(population) ⇒ Object
Runs after evolution.
193 |
# File 'lib/evolvable.rb', line 193 def after_evolution(population); end |
#before_evaluation(population) ⇒ Object
Runs before evaluation.
169 |
# File 'lib/evolvable.rb', line 169 def before_evaluation(population); end |
#before_evolution(population) ⇒ Object
Runs after evaluation and before evolution.
187 |
# File 'lib/evolvable.rb', line 187 def before_evolution(population); end |
#gene_space ⇒ Object
Will be removed in version 2.0. Use #search_space instead.
160 161 162 |
# File 'lib/evolvable.rb', line 160 def gene_space {} end |
#initialize_evolvable ⇒ Object
83 84 85 |
# File 'lib/evolvable.rb', line 83 def initialize_evolvable new end |
#new_evolvable(population: nil, genome: Genome.new, generation_index: nil) ⇒ Object
Initializes a new instance. Accepts a population object, an array of gene objects, and the instance's population index. This method is useful for re-initializing instances and populations that have been saved.
It is not recommended that you override this method as it is used by Evolvable internals. If you need to customize how your instances are initialized you can override either of the following two "initialize_instance" methods.
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/evolvable.rb', line 72 def new_evolvable(population: nil, genome: Genome.new, generation_index: nil) evolvable = initialize_evolvable evolvable.population = population evolvable.genome = genome evolvable.generation_index = generation_index evolvable.after_initialize evolvable end |
#new_population(keyword_args = {}) ⇒ Object
Initializes a population using configurable defaults that can be configured and optimized. Accepts the same named parameters as Population#initialize.
57 58 59 60 |
# File 'lib/evolvable.rb', line 57 def new_population(keyword_args = {}) keyword_args[:evolvable_type] = self Population.new(**keyword_args) end |
#new_search_space ⇒ Object
87 88 89 90 91 92 |
# File 'lib/evolvable.rb', line 87 def new_search_space space_config = search_space.empty? ? gene_space : search_space search_space = SearchSpace.build(space_config, self) search_spaces.each { |space| search_space.merge_search_space!(space) } search_space end |
#search_space ⇒ Hash, Array
Define gene config attributes - name, type, count
This method is responsible for configuring the available gene types of evolvable instances. In effect, it provides the blueprint for constructing a hyperdimensional genetic space that's capable of being used and searched by evolvable objects.
Override this method with a search space config for initializing SearchSpace objects. The config can be a hash, array of arrays, or single array when there's only one type of gene.
The below example definitions could conceivably be used to generate evolvable music.
142 143 144 |
# File 'lib/evolvable.rb', line 142 def search_space {} end |
#search_spaces ⇒ Array
Override this method to define multiple search spaces
153 154 155 |
# File 'lib/evolvable.rb', line 153 def search_spaces [] end |