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

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_idObject (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

#componentsObject (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

#contentObject (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

#domainObject (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_bandObject



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

#purityObject



24
25
26
# File 'lib/legion/extensions/agentic/attention/prism/helpers/beam.rb', line 24

def purity
  @purity.round(10)
end

#recomposeObject



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_balanceObject



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_hObject



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