Class: Legion::Extensions::Agentic::Affect::Emotion::Helpers::Momentum
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Affect::Emotion::Helpers::Momentum
- Defined in:
- lib/legion/extensions/agentic/affect/emotion/helpers/momentum.rb
Instance Attribute Summary collapse
-
#arousal_ema ⇒ Object
readonly
Returns the value of attribute arousal_ema.
-
#history ⇒ Object
readonly
Returns the value of attribute history.
-
#stability ⇒ Object
readonly
Returns the value of attribute stability.
-
#valence_ema ⇒ Object
readonly
Returns the value of attribute valence_ema.
Instance Method Summary collapse
- #emotional_state ⇒ Object
-
#initialize ⇒ Momentum
constructor
A new instance of Momentum.
- #update(current_valence, current_arousal) ⇒ Object
Constructor Details
#initialize ⇒ Momentum
Returns a new instance of Momentum.
12 13 14 15 16 17 |
# File 'lib/legion/extensions/agentic/affect/emotion/helpers/momentum.rb', line 12 def initialize @valence_ema = Valence.new_valence @arousal_ema = 0.0 @stability = 1.0 @history = [] end |
Instance Attribute Details
#arousal_ema ⇒ Object (readonly)
Returns the value of attribute arousal_ema.
10 11 12 |
# File 'lib/legion/extensions/agentic/affect/emotion/helpers/momentum.rb', line 10 def arousal_ema @arousal_ema end |
#history ⇒ Object (readonly)
Returns the value of attribute history.
10 11 12 |
# File 'lib/legion/extensions/agentic/affect/emotion/helpers/momentum.rb', line 10 def history @history end |
#stability ⇒ Object (readonly)
Returns the value of attribute stability.
10 11 12 |
# File 'lib/legion/extensions/agentic/affect/emotion/helpers/momentum.rb', line 10 def stability @stability end |
#valence_ema ⇒ Object (readonly)
Returns the value of attribute valence_ema.
10 11 12 |
# File 'lib/legion/extensions/agentic/affect/emotion/helpers/momentum.rb', line 10 def valence_ema @valence_ema end |
Instance Method Details
#emotional_state ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/legion/extensions/agentic/affect/emotion/helpers/momentum.rb', line 38 def emotional_state { valence_ema: @valence_ema, arousal_ema: @arousal_ema, stability: @stability, history_size: @history.size } end |
#update(current_valence, current_arousal) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/legion/extensions/agentic/affect/emotion/helpers/momentum.rb', line 19 def update(current_valence, current_arousal) alpha = Valence::MOMENTUM_ALPHA previous_aggregate = Valence.magnitude(@valence_ema) current_aggregate = Valence.magnitude(current_valence) @valence_ema = Valence::DIMENSIONS.to_h do |dim| [dim, (alpha * current_valence[dim]) + ((1.0 - alpha) * @valence_ema[dim])] end @arousal_ema = (alpha * current_arousal) + ((1.0 - alpha) * @arousal_ema) @stability = Valence.clamp(1.0 - (current_aggregate - previous_aggregate).abs) @history << { valence: current_valence, arousal: current_arousal, timestamp: Time.now.utc } @history.shift while @history.size > 100 { valence_ema: @valence_ema, arousal_ema: @arousal_ema, stability: @stability } end |