Class: Legion::Extensions::Agentic::Affect::SomaticMarker::Helpers::SomaticMarker

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker.rb

Constant Summary

Constants included from Constants

Constants::BODY_STATE_DECAY, Constants::DEFAULT_VALENCE, Constants::MARKER_ALPHA, Constants::MARKER_DECAY, Constants::MARKER_STRENGTH_FLOOR, Constants::MAX_BODY_STATES, Constants::MAX_DECISION_HISTORY, Constants::MAX_MARKERS, Constants::MAX_OPTIONS_PER_DECISION, Constants::NEGATIVE_BIAS, Constants::POSITIVE_BIAS, Constants::PUNISHMENT_PENALTY, Constants::REINFORCEMENT_BOOST, Constants::SIGNAL_LABELS, Constants::VALENCE_LABELS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, action:, domain:, valence:, strength: 0.5, source: :experience) ⇒ SomaticMarker

Returns a new instance of SomaticMarker.



14
15
16
17
18
19
20
21
22
# File 'lib/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker.rb', line 14

def initialize(id:, action:, domain:, valence:, strength: 0.5, source: :experience)
  @id         = id
  @action     = action
  @domain     = domain
  @valence    = valence.clamp(-1.0, 1.0)
  @strength   = strength.clamp(0.0, 1.0)
  @source     = source
  @created_at = Time.now.utc
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



12
13
14
# File 'lib/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker.rb', line 12

def action
  @action
end

#created_atObject (readonly)

Returns the value of attribute created_at.



12
13
14
# File 'lib/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker.rb', line 12

def created_at
  @created_at
end

#domainObject (readonly)

Returns the value of attribute domain.



12
13
14
# File 'lib/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker.rb', line 12

def domain
  @domain
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker.rb', line 12

def id
  @id
end

#sourceObject (readonly)

Returns the value of attribute source.



12
13
14
# File 'lib/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker.rb', line 12

def source
  @source
end

#strengthObject (readonly)

Returns the value of attribute strength.



12
13
14
# File 'lib/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker.rb', line 12

def strength
  @strength
end

#valenceObject (readonly)

Returns the value of attribute valence.



12
13
14
# File 'lib/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker.rb', line 12

def valence
  @valence
end

Instance Method Details

#decayObject



40
41
42
# File 'lib/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker.rb', line 40

def decay
  @strength = (@strength - MARKER_DECAY).clamp(0.0, 1.0)
end

#faded?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker.rb', line 44

def faded?
  @strength <= MARKER_STRENGTH_FLOOR
end

#reinforce(outcome_valence:) ⇒ Object



34
35
36
37
38
# File 'lib/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker.rb', line 34

def reinforce(outcome_valence:)
  @valence  = (MARKER_ALPHA * outcome_valence) + ((1.0 - MARKER_ALPHA) * @valence)
  @valence  = @valence.clamp(-1.0, 1.0)
  @strength = (@strength + REINFORCEMENT_BOOST).clamp(0.0, 1.0)
end

#signalObject



24
25
26
27
28
29
30
31
32
# File 'lib/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker.rb', line 24

def signal
  if @valence > POSITIVE_BIAS
    :approach
  elsif @valence < NEGATIVE_BIAS
    :avoid
  else
    :neutral
  end
end

#to_hObject



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker.rb', line 55

def to_h
  {
    id:         @id,
    action:     @action,
    domain:     @domain,
    valence:    @valence,
    strength:   @strength,
    source:     @source,
    signal:     signal,
    label:      valence_label,
    created_at: @created_at
  }
end

#valence_labelObject



48
49
50
51
52
53
# File 'lib/legion/extensions/agentic/affect/somatic_marker/helpers/somatic_marker.rb', line 48

def valence_label
  VALENCE_LABELS.each do |range, label|
    return label if range.cover?(@valence)
  end
  :neutral
end