Class: Legion::Extensions::Agentic::Affect::Emotion::Helpers::Momentum

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/affect/emotion/helpers/momentum.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMomentum

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_emaObject (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

#historyObject (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

#stabilityObject (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_emaObject (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_stateObject



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