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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action:, domain:, valence:, strength: 1.0) ⇒ SomaticMarker

Returns a new instance of SomaticMarker.



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

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

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



10
11
12
# File 'lib/legion/extensions/agentic/affect/interoception/helpers/somatic_marker.rb', line 10

def action
  @action
end

#created_atObject (readonly)

Returns the value of attribute created_at.



10
11
12
# File 'lib/legion/extensions/agentic/affect/interoception/helpers/somatic_marker.rb', line 10

def created_at
  @created_at
end

#domainObject (readonly)

Returns the value of attribute domain.



10
11
12
# File 'lib/legion/extensions/agentic/affect/interoception/helpers/somatic_marker.rb', line 10

def domain
  @domain
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/legion/extensions/agentic/affect/interoception/helpers/somatic_marker.rb', line 10

def id
  @id
end

#strengthObject

Returns the value of attribute strength.



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

def strength
  @strength
end

#valenceObject (readonly)

Returns the value of attribute valence.



10
11
12
# File 'lib/legion/extensions/agentic/affect/interoception/helpers/somatic_marker.rb', line 10

def valence
  @valence
end

Instance Method Details

#bias_for(candidate_action) ⇒ Object



22
23
24
25
26
# File 'lib/legion/extensions/agentic/affect/interoception/helpers/somatic_marker.rb', line 22

def bias_for(candidate_action)
  return 0.0 unless candidate_action == @action

  @valence * @strength * Constants::MARKER_INFLUENCE
end

#decayObject



32
33
34
# File 'lib/legion/extensions/agentic/affect/interoception/helpers/somatic_marker.rb', line 32

def decay
  @strength = [@strength - Constants::MARKER_DECAY, Constants::MARKER_FLOOR].max
end

#faded?Boolean

Returns:

  • (Boolean)


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

def faded?
  @strength <= Constants::MARKER_FLOOR
end

#labelObject



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

def label
  if positive?
    :approach
  elsif negative?
    :avoid
  else
    :neutral
  end
end

#negative?Boolean

Returns:

  • (Boolean)


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

def negative?
  @valence <= Constants::MARKER_NEGATIVE_THRESHOLD
end

#positive?Boolean

Returns:

  • (Boolean)


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

def positive?
  @valence >= Constants::MARKER_POSITIVE_THRESHOLD
end

#reinforce(amount: 0.1) ⇒ Object



28
29
30
# File 'lib/legion/extensions/agentic/affect/interoception/helpers/somatic_marker.rb', line 28

def reinforce(amount: 0.1)
  @strength = [@strength + amount, 1.0].min
end

#to_hObject



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

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