Class: Evoasm::Population

Inherits:
FFI::AutoPointer
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(parameters, architecture = Evoasm.architecture) ⇒ Population

Returns a new instance of Population

Parameters:

  • parameters (Population::Parameters)

    the population parameters

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

    architecture, currently only :x64 is supported



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

#architectureObject (readonly)

Returns the value of attribute architecture



9
10
11
# File 'lib/evoasm/population.rb', line 9

def architecture
  @architecture
end

#parametersPopulation::Parameters (readonly)

Returns population parameters

Returns:



8
9
10
# File 'lib/evoasm/population.rb', line 8

def parameters
  @parameters
end

Instance Method Details

#best_kernelKernel

Returns the best kernel found so far

Returns:

  • (Kernel)

    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_lossFloat

Returns the loss of the best kernel found so far

Returns:

  • (Float)

    the loss of the best kernel found so far

See Also:



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

#generationInteger

Returns the current generation

Returns:

  • (Integer)

    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