Class: Legion::Extensions::Agentic::Affect::Regulation::Helpers::RegulationModel
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Affect::Regulation::Helpers::RegulationModel
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/affect/regulation/helpers/regulation_model.rb
Constant Summary
Constants included from Constants
Constants::DEFAULT_SKILL, Constants::MAX_REGULATION_HISTORY, Constants::REAPPRAISAL_BONUS, Constants::REGULATION_ALPHA, Constants::REGULATION_LABELS, Constants::SKILL_DECAY, Constants::SKILL_GAIN, Constants::STRATEGIES, Constants::STRATEGY_COST, Constants::STRATEGY_EFFECTIVENESS, Constants::SUPPRESSION_PENALTY_THRESHOLD
Instance Attribute Summary collapse
-
#consecutive_suppressions ⇒ Object
readonly
Returns the value of attribute consecutive_suppressions.
-
#regulation_history ⇒ Object
readonly
Returns the value of attribute regulation_history.
-
#skill ⇒ Object
readonly
Returns the value of attribute skill.
Instance Method Summary collapse
-
#decay ⇒ Object
Decay all skills toward DEFAULT_SKILL by SKILL_DECAY each tick.
-
#initialize ⇒ RegulationModel
constructor
A new instance of RegulationModel.
-
#overall_regulation_ability ⇒ Object
Weighted average of all strategy skills.
-
#recommend_strategy(emotion_magnitude:, emotion_valence:, context: :general) ⇒ Object
Recommend the best strategy given current skills and context.
-
#regulate(emotion_magnitude:, emotion_valence:, strategy:) ⇒ Object
Apply a regulation strategy to an emotion.
-
#regulation_label ⇒ Object
Human-readable label for overall regulation ability.
-
#skill_for(strategy) ⇒ Object
Get proficiency for a specific strategy.
- #to_h ⇒ Object
Constructor Details
#initialize ⇒ RegulationModel
Returns a new instance of RegulationModel.
14 15 16 17 18 |
# File 'lib/legion/extensions/agentic/affect/regulation/helpers/regulation_model.rb', line 14 def initialize @skill = STRATEGIES.to_h { |s| [s, DEFAULT_SKILL] } @consecutive_suppressions = 0 @regulation_history = [] end |
Instance Attribute Details
#consecutive_suppressions ⇒ Object (readonly)
Returns the value of attribute consecutive_suppressions.
12 13 14 |
# File 'lib/legion/extensions/agentic/affect/regulation/helpers/regulation_model.rb', line 12 def consecutive_suppressions @consecutive_suppressions end |
#regulation_history ⇒ Object (readonly)
Returns the value of attribute regulation_history.
12 13 14 |
# File 'lib/legion/extensions/agentic/affect/regulation/helpers/regulation_model.rb', line 12 def regulation_history @regulation_history end |
#skill ⇒ Object (readonly)
Returns the value of attribute skill.
12 13 14 |
# File 'lib/legion/extensions/agentic/affect/regulation/helpers/regulation_model.rb', line 12 def skill @skill end |
Instance Method Details
#decay ⇒ Object
Decay all skills toward DEFAULT_SKILL by SKILL_DECAY each tick.
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/legion/extensions/agentic/affect/regulation/helpers/regulation_model.rb', line 70 def decay @skill.each_key do |strategy| current = @skill[strategy] @skill[strategy] = if current > DEFAULT_SKILL [current - SKILL_DECAY, DEFAULT_SKILL].max else [current + (SKILL_DECAY * 0.5), DEFAULT_SKILL].min end end end |
#overall_regulation_ability ⇒ Object
Weighted average of all strategy skills. Effectiveness-weighted so higher-value strategies contribute more.
88 89 90 91 92 |
# File 'lib/legion/extensions/agentic/affect/regulation/helpers/regulation_model.rb', line 88 def overall_regulation_ability total_weight = STRATEGIES.sum { |s| STRATEGY_EFFECTIVENESS[s] } weighted_sum = STRATEGIES.sum { |s| @skill[s] * STRATEGY_EFFECTIVENESS[s] } weighted_sum / total_weight end |
#recommend_strategy(emotion_magnitude:, emotion_valence:, context: :general) ⇒ Object
Recommend the best strategy given current skills and context.
60 61 62 63 64 65 66 67 |
# File 'lib/legion/extensions/agentic/affect/regulation/helpers/regulation_model.rb', line 60 def recommend_strategy(emotion_magnitude:, emotion_valence:, context: :general) scores = STRATEGIES.to_h do |strategy| [strategy, score_strategy(strategy, emotion_magnitude, emotion_valence, context)] end best = scores.max_by { |_, v| v }[0] { recommended: best, scores: scores, context: context } end |
#regulate(emotion_magnitude:, emotion_valence:, strategy:) ⇒ Object
Apply a regulation strategy to an emotion.
Returns a hash with :regulated_magnitude, :cost, :success
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/legion/extensions/agentic/affect/regulation/helpers/regulation_model.rb', line 23 def regulate(emotion_magnitude:, emotion_valence:, strategy:) unless STRATEGIES.include?(strategy) return { regulated_magnitude: emotion_magnitude, cost: 0.0, success: false, reason: :unknown_strategy } end base_effectiveness = STRATEGY_EFFECTIVENESS[strategy] base_cost = STRATEGY_COST[strategy] proficiency = @skill[strategy] # Proficiency scales effectiveness (skill of 1.0 adds 20% to base) effective_reduction = base_effectiveness * (1.0 + (proficiency * 0.2)) effective_reduction = [effective_reduction, 1.0].min # Suppression penalty: repeated suppression degrades its own effectiveness effective_reduction = apply_suppression_penalty(strategy, effective_reduction) regulated = (emotion_magnitude * (1.0 - effective_reduction)).clamp(0.0, 1.0) actual_cost = base_cost * (1.0 - (proficiency * 0.3)) success = regulated < emotion_magnitude update_skill(strategy, success: success) track_suppression(strategy) record_event({ strategy: strategy, emotion_magnitude: emotion_magnitude, regulated_magnitude: regulated, cost: actual_cost, emotion_valence: emotion_valence, success: success }) { regulated_magnitude: regulated, cost: actual_cost, success: success, strategy: strategy, proficiency: proficiency } end |
#regulation_label ⇒ Object
Human-readable label for overall regulation ability.
95 96 97 98 99 100 101 |
# File 'lib/legion/extensions/agentic/affect/regulation/helpers/regulation_model.rb', line 95 def regulation_label ability = overall_regulation_ability REGULATION_LABELS.each do |range, label| return label if range.cover?(ability) end :reactive end |
#skill_for(strategy) ⇒ Object
Get proficiency for a specific strategy.
82 83 84 |
# File 'lib/legion/extensions/agentic/affect/regulation/helpers/regulation_model.rb', line 82 def skill_for(strategy) @skill.fetch(strategy, DEFAULT_SKILL) end |
#to_h ⇒ Object
103 104 105 106 107 108 109 110 111 |
# File 'lib/legion/extensions/agentic/affect/regulation/helpers/regulation_model.rb', line 103 def to_h { skill: @skill.dup, consecutive_suppressions: @consecutive_suppressions, overall_ability: overall_regulation_ability, regulation_label: regulation_label, history_size: @regulation_history.size } end |