Class: Legion::Extensions::Agentic::Attention::Lens::Helpers::LensStack
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Attention::Lens::Helpers::LensStack
show all
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/attention/lens/helpers/lens_stack.rb
Constant Summary
Constants included
from Constants
Constants::CLARITY_BLURRY_THRESHOLD, Constants::CLARITY_LABELS, Constants::CLARITY_SHARP_THRESHOLD, Constants::CLEAN_BOOST_DEFAULT, Constants::DISTORTION_TYPES, Constants::LENS_DEFAULTS, Constants::LENS_TYPES, Constants::MAGNIFICATION_LABELS, Constants::MAX_LENSES, Constants::SMUDGE_RATE_DEFAULT, Constants::STACK_CLARITY_DECAY, Constants::STACK_DISTORTION_BLEND, Constants::STACK_MAGNIFICATION_EXPONENT
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of LensStack.
14
15
16
|
# File 'lib/legion/extensions/agentic/attention/lens/helpers/lens_stack.rb', line 14
def initialize
@lenses = []
end
|
Instance Attribute Details
#lenses ⇒ Object
Returns the value of attribute lenses.
12
13
14
|
# File 'lib/legion/extensions/agentic/attention/lens/helpers/lens_stack.rb', line 12
def lenses
@lenses
end
|
Instance Method Details
#combined_distortion ⇒ Object
46
47
48
49
50
51
52
53
54
|
# File 'lib/legion/extensions/agentic/attention/lens/helpers/lens_stack.rb', line 46
def combined_distortion
return 0.0 if @lenses.empty?
max_dist = @lenses.map(&:distortion).max
mean_dist = @lenses.sum(&:distortion) / @lenses.size
((max_dist * Constants::STACK_DISTORTION_BLEND) +
(mean_dist * (1.0 - Constants::STACK_DISTORTION_BLEND))).clamp(0.0, 1.0).round(10)
end
|
#combined_magnification ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/legion/extensions/agentic/attention/lens/helpers/lens_stack.rb', line 38
def combined_magnification
return 1.0 if @lenses.empty?
base = @lenses.reduce(1.0) { |acc, l| acc * l.magnification }
base**Constants::STACK_MAGNIFICATION_EXPONENT
end
|
#empty? ⇒ Boolean
34
35
36
|
# File 'lib/legion/extensions/agentic/attention/lens/helpers/lens_stack.rb', line 34
def empty?
@lenses.empty?
end
|
#pop_lens ⇒ Object
26
27
28
|
# File 'lib/legion/extensions/agentic/attention/lens/helpers/lens_stack.rb', line 26
def pop_lens
@lenses.pop
end
|
#push_lens(lens) ⇒ Object
18
19
20
21
22
23
24
|
# File 'lib/legion/extensions/agentic/attention/lens/helpers/lens_stack.rb', line 18
def push_lens(lens)
raise ArgumentError, 'expected a Lens instance' unless lens.is_a?(Lens)
raise ArgumentError, "stack is full (max #{Constants::MAX_LENSES})" if @lenses.size >= Constants::MAX_LENSES
@lenses << lens
self
end
|
#size ⇒ Object
30
31
32
|
# File 'lib/legion/extensions/agentic/attention/lens/helpers/lens_stack.rb', line 30
def size
@lenses.size
end
|
#stack_clarity ⇒ Object
56
57
58
59
60
61
62
|
# File 'lib/legion/extensions/agentic/attention/lens/helpers/lens_stack.rb', line 56
def stack_clarity
return 1.0 if @lenses.empty?
base = @lenses.map(&:clarity).min
decay = Constants::STACK_CLARITY_DECAY**(@lenses.size - 1)
(base * decay).clamp(0.0, 1.0).round(10)
end
|
#to_h ⇒ Object
84
85
86
87
88
89
90
91
92
|
# File 'lib/legion/extensions/agentic/attention/lens/helpers/lens_stack.rb', line 84
def to_h
{
lens_count: @lenses.size,
combined_magnification: combined_magnification.round(10),
combined_distortion: combined_distortion.round(10),
stack_clarity: stack_clarity.round(10),
lenses: @lenses.map(&:to_h)
}
end
|
#view_through(content) ⇒ Object
Apply all lenses to a content value (numeric 0.0-1.0) or hash with :value key
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/legion/extensions/agentic/attention/lens/helpers/lens_stack.rb', line 65
def view_through(content)
return content if @lenses.empty?
raw_value = (content)
magnified = apply_magnification(raw_value)
distorted = apply_distortion(magnified)
filtered = apply_clarity(distorted)
{
original: raw_value,
perceived: filtered.round(10),
combined_magnification: combined_magnification.round(10),
combined_distortion: combined_distortion.round(10),
stack_clarity: stack_clarity.round(10),
lens_count: @lenses.size,
focus_active: @lenses.any?(&:focused?)
}
end
|