Class: Evoasm::Population
- Inherits:
-
FFI::AutoPointer
- Object
- FFI::AutoPointer
- Evoasm::Population
- Defined in:
- lib/evoasm/population.rb,
lib/evoasm/population/plotter.rb,
lib/evoasm/population/reporter.rb,
lib/evoasm/population/parameters.rb,
lib/evoasm/population/seed_builder.rb
Defined Under Namespace
Classes: Parameters, Plotter, Reporter, SeedBuilder
Instance Attribute Summary collapse
-
#architecture ⇒ Object
readonly
Returns the value of attribute architecture.
-
#parameters ⇒ Population::Parameters
readonly
Population parameters.
Instance Method Summary collapse
-
#best_kernel ⇒ Kernel
The best kernel found so far.
-
#best_loss ⇒ Float
The loss of the best kernel found so far.
-
#evaluate(minor_generations = 5) ⇒ void
Evaluates all kernels and kernels in the population.
-
#generation ⇒ Integer
The current generation.
-
#initialize(parameters, architecture = Evoasm.architecture) ⇒ Population
constructor
A new instance of Population.
-
#seed(&block) ⇒ void
Seeds the population with random individuals.
Constructor Details
#initialize(parameters, architecture = Evoasm.architecture) ⇒ Population
Returns a new instance of Population
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/evoasm/population.rb', line 19 def initialize(parameters, architecture = Evoasm.architecture) @parameters = parameters @architecture = architecture ptr = Libevoasm.pop_alloc unless Libevoasm.pop_init ptr, @architecture, @parameters raise Error.last end super(ptr) end |
Instance Attribute Details
#architecture ⇒ Object (readonly)
Returns the value of attribute architecture
9 10 11 |
# File 'lib/evoasm/population.rb', line 9 def architecture @architecture end |
#parameters ⇒ Population::Parameters (readonly)
Returns population parameters
8 9 10 |
# File 'lib/evoasm/population.rb', line 8 def parameters @parameters end |
Instance Method Details
#best_kernel ⇒ Kernel
Returns the best kernel found so far
63 64 65 66 67 68 69 70 |
# File 'lib/evoasm/population.rb', line 63 def best_kernel kernel = Libevoasm.kernel_alloc unless Libevoasm.pop_load_best_kernel self, kernel raise Error.last end Kernel.wrap kernel end |
#best_loss ⇒ Float
Returns the loss of the best kernel found so far
58 59 60 |
# File 'lib/evoasm/population.rb', line 58 def best_loss Libevoasm.pop_get_best_loss self end |
#evaluate(minor_generations = 5) ⇒ void
This method returns an undefined value.
Evaluates all kernels and kernels in the population
33 34 35 36 37 |
# File 'lib/evoasm/population.rb', line 33 def evaluate(minor_generations = 5) unless Libevoasm.pop_eval self, minor_generations raise Error.last end end |
#generation ⇒ Integer
Returns the current generation
40 41 42 |
# File 'lib/evoasm/population.rb', line 40 def generation Libevoasm.pop_get_gen_counter self end |
#seed(&block) ⇒ void
This method returns an undefined value.
Seeds the population with random individuals
46 47 48 49 50 51 52 53 54 |
# File 'lib/evoasm/population.rb', line 46 def seed(&block) if block seed_builder = SeedBuilder.new self, self.parameters.instructions, &block seed_builder.seed_population! else Libevoasm.pop_seed self, FFI::Pointer::NULL end end |