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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(features, dimensions, died) ⇒ Measure

Returns a new instance of Measure.



118
119
120
121
122
123
124
# File 'lib/musa-dsl/generative/darwin.rb', line 118

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

  @normalized_dimensions = {}
end

Instance Attribute Details

#dimensionsObject (readonly)

Returns the value of attribute dimensions.



116
117
118
# File 'lib/musa-dsl/generative/darwin.rb', line 116

def dimensions
  @dimensions
end

#featuresObject (readonly)

Returns the value of attribute features.



116
117
118
# File 'lib/musa-dsl/generative/darwin.rb', line 116

def features
  @features
end

#normalized_dimensionsObject (readonly)

Returns the value of attribute normalized_dimensions.



116
117
118
# File 'lib/musa-dsl/generative/darwin.rb', line 116

def normalized_dimensions
  @normalized_dimensions
end

Instance Method Details

#died?Boolean

Returns:

  • (Boolean)


126
127
128
# File 'lib/musa-dsl/generative/darwin.rb', line 126

def died?
  @died
end

#evaluate_weight(weights) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/musa-dsl/generative/darwin.rb', line 130

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



143
144
145
# File 'lib/musa-dsl/generative/darwin.rb', line 143

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