Class: Legion::Extensions::Agentic::Learning::MetaLearning::Helpers::LearningDomain
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Learning::MetaLearning::Helpers::LearningDomain
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/learning/meta_learning/helpers/learning_domain.rb
Constant Summary
Constants included from Constants
Constants::DEFAULT_LEARNING_RATE, Constants::EFFICIENCY_LABELS, Constants::MAX_DOMAINS, Constants::MAX_EPISODES, Constants::MAX_STRATEGIES, Constants::PROFICIENCY_LABELS, Constants::RATE_BOOST, Constants::RATE_DECAY, Constants::STRATEGY_TYPES, Constants::TRANSFER_BONUS
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#episodes_count ⇒ Object
readonly
Returns the value of attribute episodes_count.
-
#failures ⇒ Object
readonly
Returns the value of attribute failures.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#learning_rate ⇒ Object
readonly
Returns the value of attribute learning_rate.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#preferred_strategy ⇒ Object
Returns the value of attribute preferred_strategy.
-
#proficiency ⇒ Object
readonly
Returns the value of attribute proficiency.
-
#related_domains ⇒ Object
readonly
Returns the value of attribute related_domains.
-
#successes ⇒ Object
readonly
Returns the value of attribute successes.
Instance Method Summary collapse
- #adapt_rate!(delta:) ⇒ Object
- #efficiency ⇒ Object
- #efficiency_label ⇒ Object
-
#initialize(name:, learning_rate: DEFAULT_LEARNING_RATE, related_domains: []) ⇒ LearningDomain
constructor
A new instance of LearningDomain.
- #proficiency_label ⇒ Object
- #record_failure! ⇒ Object
- #record_success! ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(name:, learning_rate: DEFAULT_LEARNING_RATE, related_domains: []) ⇒ LearningDomain
Returns a new instance of LearningDomain.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/legion/extensions/agentic/learning/meta_learning/helpers/learning_domain.rb', line 17 def initialize(name:, learning_rate: DEFAULT_LEARNING_RATE, related_domains: []) @id = SecureRandom.uuid @name = name @proficiency = 0.0 @learning_rate = learning_rate.clamp(0.001, 1.0) @episodes_count = 0 @successes = 0 @failures = 0 @preferred_strategy = nil @related_domains = Array().dup @created_at = Time.now.utc end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
15 16 17 |
# File 'lib/legion/extensions/agentic/learning/meta_learning/helpers/learning_domain.rb', line 15 def created_at @created_at end |
#episodes_count ⇒ Object (readonly)
Returns the value of attribute episodes_count.
15 16 17 |
# File 'lib/legion/extensions/agentic/learning/meta_learning/helpers/learning_domain.rb', line 15 def episodes_count @episodes_count end |
#failures ⇒ Object (readonly)
Returns the value of attribute failures.
15 16 17 |
# File 'lib/legion/extensions/agentic/learning/meta_learning/helpers/learning_domain.rb', line 15 def failures @failures end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
15 16 17 |
# File 'lib/legion/extensions/agentic/learning/meta_learning/helpers/learning_domain.rb', line 15 def id @id end |
#learning_rate ⇒ Object (readonly)
Returns the value of attribute learning_rate.
15 16 17 |
# File 'lib/legion/extensions/agentic/learning/meta_learning/helpers/learning_domain.rb', line 15 def learning_rate @learning_rate end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/legion/extensions/agentic/learning/meta_learning/helpers/learning_domain.rb', line 15 def name @name end |
#preferred_strategy ⇒ Object
Returns the value of attribute preferred_strategy.
14 15 16 |
# File 'lib/legion/extensions/agentic/learning/meta_learning/helpers/learning_domain.rb', line 14 def preferred_strategy @preferred_strategy end |
#proficiency ⇒ Object (readonly)
Returns the value of attribute proficiency.
15 16 17 |
# File 'lib/legion/extensions/agentic/learning/meta_learning/helpers/learning_domain.rb', line 15 def proficiency @proficiency end |
#related_domains ⇒ Object (readonly)
Returns the value of attribute related_domains.
15 16 17 |
# File 'lib/legion/extensions/agentic/learning/meta_learning/helpers/learning_domain.rb', line 15 def @related_domains end |
#successes ⇒ Object (readonly)
Returns the value of attribute successes.
15 16 17 |
# File 'lib/legion/extensions/agentic/learning/meta_learning/helpers/learning_domain.rb', line 15 def successes @successes end |
Instance Method Details
#adapt_rate!(delta:) ⇒ Object
58 59 60 |
# File 'lib/legion/extensions/agentic/learning/meta_learning/helpers/learning_domain.rb', line 58 def adapt_rate!(delta:) @learning_rate = (@learning_rate + delta).clamp(0.001, 1.0).round(10) end |
#efficiency ⇒ Object
43 44 45 46 47 48 |
# File 'lib/legion/extensions/agentic/learning/meta_learning/helpers/learning_domain.rb', line 43 def efficiency total = @successes + @failures return 0.0 if total.zero? (@successes.to_f / total).round(10) end |
#efficiency_label ⇒ Object
50 51 52 |
# File 'lib/legion/extensions/agentic/learning/meta_learning/helpers/learning_domain.rb', line 50 def efficiency_label EFFICIENCY_LABELS.find { |range, _| range.cover?(efficiency) }&.last || :struggling end |
#proficiency_label ⇒ Object
54 55 56 |
# File 'lib/legion/extensions/agentic/learning/meta_learning/helpers/learning_domain.rb', line 54 def proficiency_label PROFICIENCY_LABELS.find { |range, _| range.cover?(@proficiency) }&.last || :beginner end |
#record_failure! ⇒ Object
36 37 38 39 40 41 |
# File 'lib/legion/extensions/agentic/learning/meta_learning/helpers/learning_domain.rb', line 36 def record_failure! @failures += 1 @episodes_count += 1 penalty = (@learning_rate * 0.5).round(10) @proficiency = (@proficiency - penalty).clamp(0.0, 1.0).round(10) end |
#record_success! ⇒ Object
30 31 32 33 34 |
# File 'lib/legion/extensions/agentic/learning/meta_learning/helpers/learning_domain.rb', line 30 def record_success! @successes += 1 @episodes_count += 1 @proficiency = (@proficiency + @learning_rate).clamp(0.0, 1.0).round(10) end |
#to_h ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/legion/extensions/agentic/learning/meta_learning/helpers/learning_domain.rb', line 62 def to_h { id: @id, name: @name, proficiency: @proficiency, proficiency_label: proficiency_label, learning_rate: @learning_rate, episodes_count: @episodes_count, successes: @successes, failures: @failures, efficiency: efficiency, efficiency_label: efficiency_label, preferred_strategy: @preferred_strategy, related_domains: @related_domains, created_at: @created_at } end |