Class: Musa::Darwin::Darwin::Measure Private

Inherits:
Object
  • Object
show all
Defined in:
lib/musa-dsl/generative/darwin.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Measurement result for an object.

Contains features, dimensions, and viability status.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(features, dimensions, died) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



323
324
325
326
327
328
329
# File 'lib/musa-dsl/generative/darwin.rb', line 323

def initialize(features, dimensions, died)
  @features = features
  @dimensions = dimensions
  @died = died

  @normalized_dimensions = {}
end

Instance Attribute Details

#dimensionsHash{Symbol => Numeric} (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

raw dimension values



313
314
315
# File 'lib/musa-dsl/generative/darwin.rb', line 313

def dimensions
  @dimensions
end

#featuresHash{Symbol => Boolean} (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

feature flags



313
314
315
# File 'lib/musa-dsl/generative/darwin.rb', line 313

def features
  @features
end

#normalized_dimensionsHash{Symbol => Float} (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

normalized (0-1) dimensions



313
314
315
# File 'lib/musa-dsl/generative/darwin.rb', line 313

def normalized_dimensions
  @normalized_dimensions
end

Instance Method Details

#died?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Checks if object is non-viable.



335
336
337
# File 'lib/musa-dsl/generative/darwin.rb', line 335

def died?
  @died
end

#evaluate_weight(weights) ⇒ Float

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Calculates weighted fitness score.

Sums weighted normalized dimensions and features.



348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/musa-dsl/generative/darwin.rb', line 348

def evaluate_weight(weights)
  total = 0.0

  unless @died
    weights.each do |name, weight|
      total += @normalized_dimensions[name] * weight if @normalized_dimensions.key? name
      total += weight if @features[name]
    end
  end

  total
end

#inspectString Also known as: to_s

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns string representation of measure.



364
365
366
# File 'lib/musa-dsl/generative/darwin.rb', line 364

def inspect
  "Measure features=#{@features.collect { |k, _v| k }} dimensions=#{@normalized_dimensions.collect { |k, v| [k, [@dimensions[k].round(5), v.round(2)]] }.to_h}"
end