Class: Evoasm::Population::Parameters

Inherits:
FFI::AutoPointer
  • Object
show all
Defined in:
lib/evoasm/population/parameters.rb

Constant Summary

DEFAULT_EXAMPLE_WINDOW_SIZE =
128

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(architecture = Evoasm.architecture) {|self| ... } ⇒ Parameters

Returns a new instance of Parameters

Parameters:

  • architecture (Symbol) (defaults to: Evoasm.architecture)

    the machine architecture (currently only :x64 is supported)

Yields:

  • (self)


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_countInteger

Returns the number of demes in the population

Returns:

  • (Integer)

    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_sizeInteger

Returns the number of individuals per deme

Returns:

  • (Integer)

    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_metricInteger

Returns the metric used for distance calculations

Returns:

  • (Integer)

    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

#domainsHash{Symbol => Array, Range}

Returns a hash whose values indicate user-defined domains for the parameters given as keys

Returns:

  • (Hash{Symbol => Array, Range})

    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_sizeInteger

Returns the size of the example window

Returns:

  • (Integer)

    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

#examplesHash

Returns shorthand to set expected kernel input and output

Returns:

  • (Hash)

    shorthand to set expected kernel input and output

See Also:



219
220
221
# File 'lib/evoasm/population/parameters.rb', line 219

def examples
  input.zip(output).to_h
end

#inputKernel::Input

Returns input examples

Returns:



17
18
19
# File 'lib/evoasm/population/parameters.rb', line 17

def input
  @input
end

#instructionsSymbol, Instruction

Returns the list of instructions to use

Returns:

  • (Symbol, Instruction)

    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_sizeRange, Integer

Returns range of possible kernel sizes

Returns:

  • (Range, Integer)

    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_countInteger

Returns the number of iterations spent doing local search

Returns:

  • (Integer)

    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

#outputKernel::Output

Returns output examples

Returns:



20
21
22
# File 'lib/evoasm/population/parameters.rb', line 20

def output
  @output
end

#parametersArray<Symbol>

Returns the list of architecture-dependent instruction parameters to use

Returns:

  • (Array<Symbol>)

    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

#seedArray<Integer>

Returns the seed for the random number generator

Returns:

  • (Array<Integer>)

    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_sizeInteger

Returns the tournament size used for selection

Returns:

  • (Integer)

    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

Raises:

  • (Error)

    if the parameters are invalid



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