Class: Legion::Extensions::Agentic::Attention::Salience::Helpers::SalienceMap
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Attention::Salience::Helpers::SalienceMap
- Defined in:
- lib/legion/extensions/agentic/attention/salience/helpers/salience_map.rb
Constant Summary collapse
- MAX_HISTORY =
50- TREND_WINDOW =
5- TREND_DELTA =
0.02
Instance Attribute Summary collapse
-
#baseline ⇒ Object
readonly
Returns the value of attribute baseline.
-
#current_map ⇒ Object
readonly
Returns the value of attribute current_map.
-
#history ⇒ Object
readonly
Returns the value of attribute history.
Instance Method Summary collapse
- #above_baseline? ⇒ Boolean
- #conflict_signals ⇒ Object
- #dominant_source ⇒ Object
-
#initialize ⇒ SalienceMap
constructor
A new instance of SalienceMap.
- #overall_salience ⇒ Object
- #salience_trend ⇒ Object
- #to_h ⇒ Object
- #update(integrated_signals) ⇒ Object
- #urgency_level ⇒ Object
Constructor Details
#initialize ⇒ SalienceMap
Returns a new instance of SalienceMap.
16 17 18 19 20 21 |
# File 'lib/legion/extensions/agentic/attention/salience/helpers/salience_map.rb', line 16 def initialize @current_map = {} @baseline = 0.0 @history = [] @novel_sources = {} end |
Instance Attribute Details
#baseline ⇒ Object (readonly)
Returns the value of attribute baseline.
10 11 12 |
# File 'lib/legion/extensions/agentic/attention/salience/helpers/salience_map.rb', line 10 def baseline @baseline end |
#current_map ⇒ Object (readonly)
Returns the value of attribute current_map.
10 11 12 |
# File 'lib/legion/extensions/agentic/attention/salience/helpers/salience_map.rb', line 10 def current_map @current_map end |
#history ⇒ Object (readonly)
Returns the value of attribute history.
10 11 12 |
# File 'lib/legion/extensions/agentic/attention/salience/helpers/salience_map.rb', line 10 def history @history end |
Instance Method Details
#above_baseline? ⇒ Boolean
57 58 59 |
# File 'lib/legion/extensions/agentic/attention/salience/helpers/salience_map.rb', line 57 def above_baseline? overall_salience > @baseline end |
#conflict_signals ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/legion/extensions/agentic/attention/salience/helpers/salience_map.rb', line 61 def conflict_signals values = @current_map.values return [] if values.size < 2 pairs = [] keys = @current_map.keys keys.each_with_index do |key_a, i| keys[(i + 1)..].each do |key_b| diff = (@current_map[key_a] - @current_map[key_b]).abs pairs << [key_a, key_b] if diff > 0.3 end end pairs end |
#dominant_source ⇒ Object
51 52 53 54 55 |
# File 'lib/legion/extensions/agentic/attention/salience/helpers/salience_map.rb', line 51 def dominant_source return nil if @current_map.empty? @current_map.max_by { |_k, v| v }&.first end |
#overall_salience ⇒ Object
40 41 42 |
# File 'lib/legion/extensions/agentic/attention/salience/helpers/salience_map.rb', line 40 def overall_salience @current_map.values.sum.round(6) end |
#salience_trend ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/legion/extensions/agentic/attention/salience/helpers/salience_map.rb', line 76 def salience_trend return :stable if @history.size < 2 window = @history.last([TREND_WINDOW, @history.size].min).map { |h| h[:overall] } delta = window.last - window.first if delta > TREND_DELTA :rising elsif delta < -TREND_DELTA :falling else :stable end end |
#to_h ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/legion/extensions/agentic/attention/salience/helpers/salience_map.rb', line 90 def to_h { current_map: @current_map, overall: overall_salience, baseline: @baseline, urgency: urgency_level, dominant: dominant_source, above_baseline: above_baseline?, conflicts: conflict_signals, trend: salience_trend, history_size: @history.size } end |
#update(integrated_signals) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/legion/extensions/agentic/attention/salience/helpers/salience_map.rb', line 23 def update(integrated_signals) @current_map = integrated_signals.transform_values { |v| v[:weighted] } apply_novelty_boost(integrated_signals) overall = overall_salience @baseline = (Constants::INTEGRATION_ALPHA * overall) + ((1.0 - Constants::INTEGRATION_ALPHA) * @baseline) snapshot = { timestamp: Time.now.utc.to_f, overall: overall, urgency: urgency_level, dominant: dominant_source, map_snapshot: @current_map.dup } @history << snapshot @history.shift while @history.size > MAX_HISTORY snapshot end |
#urgency_level ⇒ Object
44 45 46 47 48 49 |
# File 'lib/legion/extensions/agentic/attention/salience/helpers/salience_map.rb', line 44 def urgency_level score = overall_salience Constants::URGENCY_LEVELS.find do |level| score >= Constants::URGENCY_THRESHOLDS[level] end || :background end |