Class: Legion::Extensions::Agentic::Homeostasis::TemporalDiscounting::Helpers::Reward
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Homeostasis::TemporalDiscounting::Helpers::Reward
- Defined in:
- lib/legion/extensions/agentic/homeostasis/temporal_discounting/helpers/reward.rb
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#delay ⇒ Object
readonly
Returns the value of attribute delay.
-
#discount_rate ⇒ Object
readonly
Returns the value of attribute discount_rate.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
Instance Method Summary collapse
- #adjust_delay!(new_delay:) ⇒ Object
- #adjust_discount_rate!(new_rate:) ⇒ Object
- #impulsivity_label ⇒ Object
-
#initialize(label:, amount:, delay:, domain: :general, discount_rate: DEFAULT_DISCOUNT_RATE) ⇒ Reward
constructor
A new instance of Reward.
- #subjective_value ⇒ Object
- #to_h ⇒ Object
- #value_label ⇒ Object
- #value_ratio ⇒ Object
- #worth_waiting?(threshold: 0.3) ⇒ Boolean
Constructor Details
#initialize(label:, amount:, delay:, domain: :general, discount_rate: DEFAULT_DISCOUNT_RATE) ⇒ Reward
Returns a new instance of Reward.
14 15 16 17 18 19 20 21 22 |
# File 'lib/legion/extensions/agentic/homeostasis/temporal_discounting/helpers/reward.rb', line 14 def initialize(label:, amount:, delay:, domain: :general, discount_rate: DEFAULT_DISCOUNT_RATE) @id = SecureRandom.uuid @label = label @amount = amount.clamp(0.0, 1.0) @delay = delay.to_f @domain = domain @discount_rate = discount_rate.clamp(MIN_DISCOUNT_RATE, MAX_DISCOUNT_RATE) @created_at = Time.now.utc end |
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/temporal_discounting/helpers/reward.rb', line 12 def amount @amount end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/temporal_discounting/helpers/reward.rb', line 12 def created_at @created_at end |
#delay ⇒ Object (readonly)
Returns the value of attribute delay.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/temporal_discounting/helpers/reward.rb', line 12 def delay @delay end |
#discount_rate ⇒ Object (readonly)
Returns the value of attribute discount_rate.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/temporal_discounting/helpers/reward.rb', line 12 def discount_rate @discount_rate end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/temporal_discounting/helpers/reward.rb', line 12 def domain @domain end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/temporal_discounting/helpers/reward.rb', line 12 def id @id end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
12 13 14 |
# File 'lib/legion/extensions/agentic/homeostasis/temporal_discounting/helpers/reward.rb', line 12 def label @label end |
Instance Method Details
#adjust_delay!(new_delay:) ⇒ Object
54 55 56 |
# File 'lib/legion/extensions/agentic/homeostasis/temporal_discounting/helpers/reward.rb', line 54 def adjust_delay!(new_delay:) @delay = new_delay.to_f end |
#adjust_discount_rate!(new_rate:) ⇒ Object
58 59 60 |
# File 'lib/legion/extensions/agentic/homeostasis/temporal_discounting/helpers/reward.rb', line 58 def adjust_discount_rate!(new_rate:) @discount_rate = new_rate.clamp(MIN_DISCOUNT_RATE, MAX_DISCOUNT_RATE) end |
#impulsivity_label ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/legion/extensions/agentic/homeostasis/temporal_discounting/helpers/reward.rb', line 42 def impulsivity_label k = @discount_rate IMPULSIVITY_LABELS.each do |range, label| return label if range.cover?(k) end :extreme end |
#subjective_value ⇒ Object
24 25 26 |
# File 'lib/legion/extensions/agentic/homeostasis/temporal_discounting/helpers/reward.rb', line 24 def subjective_value (@amount / (1.0 + (@discount_rate * @delay))).round(10) end |
#to_h ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/legion/extensions/agentic/homeostasis/temporal_discounting/helpers/reward.rb', line 62 def to_h { id: @id, label: @label, amount: @amount, delay: @delay, domain: @domain, discount_rate: @discount_rate, subjective_value: subjective_value, value_ratio: value_ratio, value_label: value_label, impulsivity_label: impulsivity_label, worth_waiting: worth_waiting?, created_at: @created_at } end |
#value_label ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/legion/extensions/agentic/homeostasis/temporal_discounting/helpers/reward.rb', line 34 def value_label ratio = value_ratio VALUE_LABELS.each do |range, label| return label if range.cover?(ratio) end :negligible end |
#value_ratio ⇒ Object
28 29 30 31 32 |
# File 'lib/legion/extensions/agentic/homeostasis/temporal_discounting/helpers/reward.rb', line 28 def value_ratio return 0.0 if @amount.zero? (subjective_value / @amount).round(10) end |
#worth_waiting?(threshold: 0.3) ⇒ Boolean
50 51 52 |
# File 'lib/legion/extensions/agentic/homeostasis/temporal_discounting/helpers/reward.rb', line 50 def worth_waiting?(threshold: 0.3) subjective_value >= threshold end |