Class: Legion::Extensions::Agentic::Attention::LatentInhibition::Helpers::StimulusRecord

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/attention/latent_inhibition/helpers/stimulus_record.rb

Constant Summary

Constants included from Constants

Constants::DISINHIBITION_RATE, Constants::INHIBITION_LABELS, Constants::INHIBITION_RATE, Constants::MAX_STIMULI, Constants::NOVELTY_LABELS, Constants::NOVELTY_THRESHOLD

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label:) ⇒ StimulusRecord

Returns a new instance of StimulusRecord.



16
17
18
19
20
21
22
23
# File 'lib/legion/extensions/agentic/attention/latent_inhibition/helpers/stimulus_record.rb', line 16

def initialize(label:)
  @id              = SecureRandom.uuid
  @label           = label
  @exposure_count  = 0
  @inhibition_score = 0.0
  @last_exposed_at = nil
  @associations    = []
end

Instance Attribute Details

#associationsObject (readonly)

Returns the value of attribute associations.



14
15
16
# File 'lib/legion/extensions/agentic/attention/latent_inhibition/helpers/stimulus_record.rb', line 14

def associations
  @associations
end

#exposure_countObject (readonly)

Returns the value of attribute exposure_count.



14
15
16
# File 'lib/legion/extensions/agentic/attention/latent_inhibition/helpers/stimulus_record.rb', line 14

def exposure_count
  @exposure_count
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/legion/extensions/agentic/attention/latent_inhibition/helpers/stimulus_record.rb', line 14

def id
  @id
end

#inhibition_scoreObject (readonly)

Returns the value of attribute inhibition_score.



14
15
16
# File 'lib/legion/extensions/agentic/attention/latent_inhibition/helpers/stimulus_record.rb', line 14

def inhibition_score
  @inhibition_score
end

#labelObject (readonly)

Returns the value of attribute label.



14
15
16
# File 'lib/legion/extensions/agentic/attention/latent_inhibition/helpers/stimulus_record.rb', line 14

def label
  @label
end

#last_exposed_atObject (readonly)

Returns the value of attribute last_exposed_at.



14
15
16
# File 'lib/legion/extensions/agentic/attention/latent_inhibition/helpers/stimulus_record.rb', line 14

def last_exposed_at
  @last_exposed_at
end

Instance Method Details

#associate!(outcome:) ⇒ Object



32
33
34
35
36
# File 'lib/legion/extensions/agentic/attention/latent_inhibition/helpers/stimulus_record.rb', line 32

def associate!(outcome:)
  effectiveness = (1.0 - @inhibition_score).clamp(0.0, 1.0).round(10)
  @associations << { outcome: outcome, effectiveness: effectiveness, recorded_at: Time.now.utc }
  effectiveness
end

#disinhibit!(intensity:) ⇒ Object



38
39
40
41
42
# File 'lib/legion/extensions/agentic/attention/latent_inhibition/helpers/stimulus_record.rb', line 38

def disinhibit!(intensity:)
  reduction = (Constants::DISINHIBITION_RATE * intensity.clamp(0.0, 1.0)).round(10)
  @inhibition_score = (@inhibition_score - reduction).clamp(0.0, 1.0).round(10)
  self
end

#expose!Object



25
26
27
28
29
30
# File 'lib/legion/extensions/agentic/attention/latent_inhibition/helpers/stimulus_record.rb', line 25

def expose!
  @exposure_count  += 1
  @last_exposed_at  = Time.now.utc
  @inhibition_score = (@inhibition_score + Constants::INHIBITION_RATE).clamp(0.0, 1.0).round(10)
  self
end

#inhibition_labelObject



48
49
50
# File 'lib/legion/extensions/agentic/attention/latent_inhibition/helpers/stimulus_record.rb', line 48

def inhibition_label
  Constants::INHIBITION_LABELS.find { |range, _| range.cover?(@inhibition_score) }&.last || :saturated
end

#novel?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/legion/extensions/agentic/attention/latent_inhibition/helpers/stimulus_record.rb', line 44

def novel?
  @exposure_count < Constants::NOVELTY_THRESHOLD
end

#to_hObject



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/legion/extensions/agentic/attention/latent_inhibition/helpers/stimulus_record.rb', line 52

def to_h
  {
    id:               @id,
    label:            @label,
    exposure_count:   @exposure_count,
    inhibition_score: @inhibition_score,
    inhibition_label: inhibition_label,
    novel:            novel?,
    last_exposed_at:  @last_exposed_at,
    associations:     @associations.dup
  }
end