Class: Legion::Extensions::Agentic::Attention::Prism::Helpers::Beam
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Attention::Prism::Helpers::Beam
- Defined in:
- lib/legion/extensions/agentic/attention/prism/helpers/beam.rb
Constant Summary collapse
- BAND_MIDPOINTS =
Constants::WAVELENGTH_RANGES.transform_values do |range| ((range.min + range.max) / 2.0).round end.freeze
Instance Attribute Summary collapse
-
#beam_id ⇒ Object
readonly
Returns the value of attribute beam_id.
-
#components ⇒ Object
readonly
Returns the value of attribute components.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
Instance Method Summary collapse
- #decompose! ⇒ Object
- #dominant_band ⇒ Object
-
#initialize(beam_id:, domain:, content:) ⇒ Beam
constructor
A new instance of Beam.
- #purity ⇒ Object
- #recompose ⇒ Object
- #spectral_balance ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(beam_id:, domain:, content:) ⇒ Beam
Returns a new instance of Beam.
16 17 18 19 20 21 22 |
# File 'lib/legion/extensions/agentic/attention/prism/helpers/beam.rb', line 16 def initialize(beam_id:, domain:, content:) @beam_id = beam_id @domain = domain @content = content @components = [] @purity = 0.0 end |
Instance Attribute Details
#beam_id ⇒ Object (readonly)
Returns the value of attribute beam_id.
14 15 16 |
# File 'lib/legion/extensions/agentic/attention/prism/helpers/beam.rb', line 14 def beam_id @beam_id end |
#components ⇒ Object (readonly)
Returns the value of attribute components.
14 15 16 |
# File 'lib/legion/extensions/agentic/attention/prism/helpers/beam.rb', line 14 def components @components end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
14 15 16 |
# File 'lib/legion/extensions/agentic/attention/prism/helpers/beam.rb', line 14 def content @content end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
14 15 16 |
# File 'lib/legion/extensions/agentic/attention/prism/helpers/beam.rb', line 14 def domain @domain end |
Instance Method Details
#decompose! ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/legion/extensions/agentic/attention/prism/helpers/beam.rb', line 28 def decompose! @components = [] bands = assign_bands(content) bands.each do |band, band_content| wavelength = BAND_MIDPOINTS.fetch(band) intensity = compute_intensity(band, band_content) @components << SpectralComponent.new( band: band, wavelength: wavelength, intensity: intensity, content: band_content ) end @purity = compute_purity self end |
#dominant_band ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/legion/extensions/agentic/attention/prism/helpers/beam.rb', line 56 def dominant_band return nil if @components.empty? dominant = @components.select(&:dominant?) candidates = dominant.any? ? dominant : @components candidates.max_by(&:intensity)&.band end |
#purity ⇒ Object
24 25 26 |
# File 'lib/legion/extensions/agentic/attention/prism/helpers/beam.rb', line 24 def purity @purity.round(10) end |
#recompose ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/legion/extensions/agentic/attention/prism/helpers/beam.rb', line 47 def recompose return '' if @components.empty? active = @components.reject(&:faded?) sorted = active.sort_by { |c| -c.intensity } parts = sorted.map { |c| "#{c.band}(#{c.intensity.round(3)}): #{summarize(c.content)}" } parts.join(' | ') end |
#spectral_balance ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/legion/extensions/agentic/attention/prism/helpers/beam.rb', line 64 def spectral_balance return {} if @components.empty? total = @components.sum(&:intensity) return {} if total.zero? @components.to_h do |c| [c.band, (c.intensity / total).round(10)] end end |
#to_h ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/legion/extensions/agentic/attention/prism/helpers/beam.rb', line 75 def to_h { beam_id: @beam_id, domain: @domain, content: @content, purity: purity, purity_label: purity_label, dominant_band: dominant_band, spectral_balance: spectral_balance, component_count: @components.size, components: @components.map(&:to_h) } end |