Class: Evoasm::Population::Parameters
- Inherits:
-
FFI::AutoPointer
- Object
- FFI::AutoPointer
- Evoasm::Population::Parameters
- Defined in:
- lib/evoasm/population/parameters.rb
Constant Summary
- DEFAULT_EXAMPLE_WINDOW_SIZE =
128
Instance Attribute Summary collapse
-
#deme_count ⇒ Integer
The number of demes in the population.
-
#deme_size ⇒ Integer
The number of individuals per deme.
-
#distance_metric ⇒ Integer
The metric used for distance calculations.
-
#domains ⇒ Hash{Symbol => Array, Range}
A hash whose values indicate user-defined domains for the parameters given as keys.
-
#example_window_size ⇒ Integer
The size of the example window.
-
#examples ⇒ Hash
Shorthand to set expected kernel input and output.
-
#input ⇒ Kernel::Input
Input examples.
-
#instructions ⇒ Symbol, Instruction
The list of instructions to use.
-
#kernel_size ⇒ Range, Integer
Range of possible kernel sizes.
-
#local_search_iteration_count ⇒ Integer
The number of iterations spent doing local search.
-
#output ⇒ Kernel::Output
Output examples.
-
#parameters ⇒ Array<Symbol>
The list of architecture-dependent instruction parameters to use.
-
#seed ⇒ Array<Integer>
The seed for the random number generator.
-
#tournament_size ⇒ Integer
The tournament size used for selection.
Instance Method Summary collapse
-
#initialize(architecture = Evoasm.architecture) {|self| ... } ⇒ Parameters
constructor
A new instance of Parameters.
-
#validate! ⇒ Object
Validate the parameters.
Constructor Details
#initialize(architecture = Evoasm.architecture) {|self| ... } ⇒ Parameters
Returns a new instance of Parameters
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/evoasm/population/parameters.rb', line 24 def initialize(architecture = Evoasm.architecture, &block) ptr = Libevoasm.pop_params_alloc Libevoasm.pop_params_init ptr case architecture when :x64 @inst_id_enum_type = Libevoasm.enum_type :x64_inst_id @param_id_enum_type = Libevoasm.enum_type :x64_param_id else raise "unknown architecture #{architecture}" end super(ptr) self.seed = PRNG::DEFAULT_SEED self.example_window_size = DEFAULT_EXAMPLE_WINDOW_SIZE if block block[self] end end |
Instance Attribute Details
#deme_count ⇒ Integer
Returns the number of demes in the population
68 69 70 |
# File 'lib/evoasm/population/parameters.rb', line 68 def deme_count Libevoasm.pop_params_get_n_demes self end |
#deme_size ⇒ Integer
Returns the number of individuals per deme
48 49 50 |
# File 'lib/evoasm/population/parameters.rb', line 48 def deme_size Libevoasm.pop_params_get_deme_size self end |
#distance_metric ⇒ Integer
Returns the metric used for distance calculations
78 79 80 |
# File 'lib/evoasm/population/parameters.rb', line 78 def distance_metric Libevoasm.pop_params_get_dist_metric self end |
#domains ⇒ Hash{Symbol => Array, Range}
Returns a hash whose values indicate user-defined domains for the parameters given as keys
113 114 115 116 117 118 119 |
# File 'lib/evoasm/population/parameters.rb', line 113 def domains parameters.map do |parameter_name| domain_ptr = Libevoasm.pop_params_get_domain(self, parameter_name) domain = @domains.find { |domain| domain == domain_ptr } [parameter_name, domain] end.to_h end |
#example_window_size ⇒ Integer
Returns the size of the example window
58 59 60 |
# File 'lib/evoasm/population/parameters.rb', line 58 def example_window_size Libevoasm.pop_params_get_example_win_size self end |
#examples ⇒ Hash
Returns shorthand to set expected kernel input and output
219 220 221 |
# File 'lib/evoasm/population/parameters.rb', line 219 def examples input.zip(output).to_h end |
#input ⇒ Kernel::Input
Returns input examples
17 18 19 |
# File 'lib/evoasm/population/parameters.rb', line 17 def input @input end |
#instructions ⇒ Symbol, Instruction
Returns the list of instructions to use
174 175 176 177 178 |
# File 'lib/evoasm/population/parameters.rb', line 174 def instructions Array.new(Libevoasm.pop_params_get_n_insts self) do |index| @inst_id_enum_type[Libevoasm.pop_params_get_inst(self, index)] end end |
#kernel_size ⇒ Range, Integer
Returns range of possible kernel sizes
195 196 197 198 199 200 |
# File 'lib/evoasm/population/parameters.rb', line 195 def kernel_size min = Libevoasm.pop_params_get_min_kernel_size self max = Libevoasm.pop_params_get_max_kernel_size self return (min..max) end |
#local_search_iteration_count ⇒ Integer
Returns the number of iterations spent doing local search
88 89 90 |
# File 'lib/evoasm/population/parameters.rb', line 88 def local_search_iteration_count Libevoasm.pop_params_get_n_local_search_iters self end |
#output ⇒ Kernel::Output
Returns output examples
20 21 22 |
# File 'lib/evoasm/population/parameters.rb', line 20 def output @output end |
#parameters ⇒ Array<Symbol>
Returns the list of architecture-dependent instruction parameters to use
98 99 100 101 102 |
# File 'lib/evoasm/population/parameters.rb', line 98 def parameters Array.new(Libevoasm.pop_params_get_n_params self) do |index| parameters_enum_type[Libevoasm.pop_params_get_param(self, index)] end end |
#seed ⇒ Array<Integer>
Returns the seed for the random number generator
138 139 140 141 142 |
# File 'lib/evoasm/population/parameters.rb', line 138 def seed Array.new(PRNG::SEED_SIZE) do |index| Libevoasm.pop_params_get_seed(self, index) end end |
#tournament_size ⇒ Integer
Returns the tournament size used for selection
156 157 158 |
# File 'lib/evoasm/population/parameters.rb', line 156 def tournament_size Libevoasm.pop_params_get_tourn_size self end |
Instance Method Details
#validate! ⇒ Object
Validate the parameters
166 167 168 169 170 |
# File 'lib/evoasm/population/parameters.rb', line 166 def validate! unless Libevoasm.pop_params_validate(self) raise Error.last end end |