Class: Legion::Extensions::Agentic::Learning::PreferenceLearning::Helpers::Option
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Learning::PreferenceLearning::Helpers::Option
- Defined in:
- lib/legion/extensions/agentic/learning/preference_learning/helpers/option.rb
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#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.
-
#losses ⇒ Object
Returns the value of attribute losses.
-
#preference_score ⇒ Object
Returns the value of attribute preference_score.
-
#times_seen ⇒ Object
Returns the value of attribute times_seen.
-
#wins ⇒ Object
Returns the value of attribute wins.
Instance Method Summary collapse
-
#initialize(label:, domain: :general) ⇒ Option
constructor
A new instance of Option.
- #lose! ⇒ Object
- #preference_label ⇒ Object
- #to_h ⇒ Object
- #win! ⇒ Object
- #win_rate ⇒ Object
Constructor Details
#initialize(label:, domain: :general) ⇒ Option
Returns a new instance of Option.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/legion/extensions/agentic/learning/preference_learning/helpers/option.rb', line 15 def initialize(label:, domain: :general) @id = SecureRandom.uuid @label = label @domain = domain @preference_score = Constants::DEFAULT_PREFERENCE @wins = 0 @losses = 0 @times_seen = 0 @created_at = Time.now.utc end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/learning/preference_learning/helpers/option.rb', line 12 def created_at @created_at end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
12 13 14 |
# File 'lib/legion/extensions/agentic/learning/preference_learning/helpers/option.rb', line 12 def domain @domain end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/legion/extensions/agentic/learning/preference_learning/helpers/option.rb', line 12 def id @id end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
12 13 14 |
# File 'lib/legion/extensions/agentic/learning/preference_learning/helpers/option.rb', line 12 def label @label end |
#losses ⇒ Object
Returns the value of attribute losses.
13 14 15 |
# File 'lib/legion/extensions/agentic/learning/preference_learning/helpers/option.rb', line 13 def losses @losses end |
#preference_score ⇒ Object
Returns the value of attribute preference_score.
13 14 15 |
# File 'lib/legion/extensions/agentic/learning/preference_learning/helpers/option.rb', line 13 def preference_score @preference_score end |
#times_seen ⇒ Object
Returns the value of attribute times_seen.
13 14 15 |
# File 'lib/legion/extensions/agentic/learning/preference_learning/helpers/option.rb', line 13 def times_seen @times_seen end |
#wins ⇒ Object
Returns the value of attribute wins.
13 14 15 |
# File 'lib/legion/extensions/agentic/learning/preference_learning/helpers/option.rb', line 13 def wins @wins end |
Instance Method Details
#lose! ⇒ Object
32 33 34 35 36 |
# File 'lib/legion/extensions/agentic/learning/preference_learning/helpers/option.rb', line 32 def lose! @losses += 1 @times_seen += 1 @preference_score = clamp(@preference_score - Constants::LOSS_PENALTY) end |
#preference_label ⇒ Object
45 46 47 48 49 50 |
# File 'lib/legion/extensions/agentic/learning/preference_learning/helpers/option.rb', line 45 def preference_label Constants::PREFERENCE_LABELS.each do |range, label| return label if range.cover?(@preference_score) end :neutral end |
#to_h ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/legion/extensions/agentic/learning/preference_learning/helpers/option.rb', line 52 def to_h { id: @id, label: @label, domain: @domain, preference_score: @preference_score, wins: @wins, losses: @losses, times_seen: @times_seen, win_rate: win_rate, preference_label: preference_label, created_at: @created_at } end |
#win! ⇒ Object
26 27 28 29 30 |
# File 'lib/legion/extensions/agentic/learning/preference_learning/helpers/option.rb', line 26 def win! @wins += 1 @times_seen += 1 @preference_score = clamp(@preference_score + Constants::WIN_BOOST) end |
#win_rate ⇒ Object
38 39 40 41 42 43 |
# File 'lib/legion/extensions/agentic/learning/preference_learning/helpers/option.rb', line 38 def win_rate total = @wins + @losses return 0.0 if total.zero? @wins.to_f / (total + 1) end |