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) ⇒ Measure

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 a new instance of Measure.



284
285
286
287
288
289
290
# File 'lib/musa-dsl/generative/darwin.rb', line 284

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

Returns:

  • (Hash{Symbol => Numeric})

    the current value of dimensions



280
281
282
# File 'lib/musa-dsl/generative/darwin.rb', line 280

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

Returns:

  • (Hash{Symbol => Boolean})

    the current value of features



280
281
282
# File 'lib/musa-dsl/generative/darwin.rb', line 280

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

Returns:

  • (Hash{Symbol => Float})

    the current value of normalized_dimensions



280
281
282
# File 'lib/musa-dsl/generative/darwin.rb', line 280

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.

Returns:

  • (Boolean)


296
297
298
# File 'lib/musa-dsl/generative/darwin.rb', line 296

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.

Parameters:

  • weights (Hash{Symbol => Numeric})

    weight assignments

Returns:

  • (Float)

    total fitness score



309
310
311
312
313
314
315
316
317
318
319
320
# File 'lib/musa-dsl/generative/darwin.rb', line 309

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

#inspectObject 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.



322
323
324
# File 'lib/musa-dsl/generative/darwin.rb', line 322

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