Class: Legion::Extensions::Agentic::Attention::Prism::Helpers::SpectralComponent

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/attention/prism/helpers/spectral_component.rb

Constant Summary collapse

ATTENUATION_RATE_DEFAULT =
0.05
AMPLIFY_BOOST_DEFAULT =
0.1
DOMINANT_THRESHOLD =
0.7
FADED_THRESHOLD =
0.1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(band:, wavelength:, intensity:, content:) ⇒ SpectralComponent

Returns a new instance of SpectralComponent.

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
25
26
27
# File 'lib/legion/extensions/agentic/attention/prism/helpers/spectral_component.rb', line 17

def initialize(band:, wavelength:, intensity:, content:)
  raise ArgumentError, "Unknown band: #{band}" unless Constants::SPECTRAL_BANDS.include?(band)

  range = Constants::WAVELENGTH_RANGES.fetch(band)
  raise ArgumentError, "Wavelength #{wavelength} out of range for #{band}" unless range.cover?(wavelength)

  @band       = band
  @wavelength = wavelength
  @intensity  = intensity.clamp(0.0, 1.0)
  @content    = content
end

Instance Attribute Details

#bandObject (readonly)

Returns the value of attribute band.



15
16
17
# File 'lib/legion/extensions/agentic/attention/prism/helpers/spectral_component.rb', line 15

def band
  @band
end

#contentObject (readonly)

Returns the value of attribute content.



15
16
17
# File 'lib/legion/extensions/agentic/attention/prism/helpers/spectral_component.rb', line 15

def content
  @content
end

#wavelengthObject (readonly)

Returns the value of attribute wavelength.



15
16
17
# File 'lib/legion/extensions/agentic/attention/prism/helpers/spectral_component.rb', line 15

def wavelength
  @wavelength
end

Instance Method Details

#amplify!(boost: AMPLIFY_BOOST_DEFAULT) ⇒ Object



38
39
40
41
# File 'lib/legion/extensions/agentic/attention/prism/helpers/spectral_component.rb', line 38

def amplify!(boost: AMPLIFY_BOOST_DEFAULT)
  @intensity = (@intensity + boost.to_f.abs).clamp(0.0, 1.0)
  self
end

#attenuate!(rate: ATTENUATION_RATE_DEFAULT) ⇒ Object



33
34
35
36
# File 'lib/legion/extensions/agentic/attention/prism/helpers/spectral_component.rb', line 33

def attenuate!(rate: ATTENUATION_RATE_DEFAULT)
  @intensity = (@intensity - rate.to_f.abs).clamp(0.0, 1.0)
  self
end

#dominant?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/legion/extensions/agentic/attention/prism/helpers/spectral_component.rb', line 43

def dominant?
  @intensity >= DOMINANT_THRESHOLD
end

#faded?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/legion/extensions/agentic/attention/prism/helpers/spectral_component.rb', line 47

def faded?
  @intensity <= FADED_THRESHOLD
end

#intensityObject



29
30
31
# File 'lib/legion/extensions/agentic/attention/prism/helpers/spectral_component.rb', line 29

def intensity
  @intensity.round(10)
end

#intensity_labelObject



51
52
53
# File 'lib/legion/extensions/agentic/attention/prism/helpers/spectral_component.rb', line 51

def intensity_label
  Constants::INTENSITY_LABELS.find { |entry| entry[:range].cover?(@intensity) }&.fetch(:label, :unknown)
end

#to_hObject



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/legion/extensions/agentic/attention/prism/helpers/spectral_component.rb', line 55

def to_h
  {
    band:            @band,
    wavelength:      @wavelength,
    intensity:       intensity,
    intensity_label: intensity_label,
    content:         @content,
    dominant:        dominant?,
    faded:           faded?
  }
end