Class: Legion::Extensions::Agentic::Executive::Load::Helpers::LoadModel
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Executive::Load::Helpers::LoadModel
show all
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/executive/load/helpers/load_model.rb
Constant Summary
Constants included
from Constants
Constants::DEFAULT_CAPACITY, Constants::DEFAULT_EXTRANEOUS, Constants::DEFAULT_GERMANE, Constants::DEFAULT_INTRINSIC, Constants::EXTRANEOUS_ALPHA, Constants::GERMANE_ALPHA, Constants::INTRINSIC_ALPHA, Constants::LOAD_DECAY, Constants::LOAD_LABELS, Constants::MAX_LOAD_HISTORY, Constants::OPTIMAL_GERMANE_RATIO, Constants::OVERLOAD_THRESHOLD, Constants::UNDERLOAD_THRESHOLD
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(capacity: DEFAULT_CAPACITY) ⇒ LoadModel
Returns a new instance of LoadModel.
Instance Attribute Details
#capacity ⇒ Object
Returns the value of attribute capacity.
12
13
14
|
# File 'lib/legion/extensions/agentic/executive/load/helpers/load_model.rb', line 12
def capacity
@capacity
end
|
Returns the value of attribute extraneous.
12
13
14
|
# File 'lib/legion/extensions/agentic/executive/load/helpers/load_model.rb', line 12
def
@extraneous
end
|
#germane ⇒ Object
Returns the value of attribute germane.
12
13
14
|
# File 'lib/legion/extensions/agentic/executive/load/helpers/load_model.rb', line 12
def germane
@germane
end
|
#intrinsic ⇒ Object
Returns the value of attribute intrinsic.
12
13
14
|
# File 'lib/legion/extensions/agentic/executive/load/helpers/load_model.rb', line 12
def intrinsic
@intrinsic
end
|
#load_history ⇒ Object
Returns the value of attribute load_history.
12
13
14
|
# File 'lib/legion/extensions/agentic/executive/load/helpers/load_model.rb', line 12
def load_history
@load_history
end
|
Instance Method Details
39
40
41
42
43
|
# File 'lib/legion/extensions/agentic/executive/load/helpers/load_model.rb', line 39
def (amount:, source: :unknown)
@extraneous = ema_update(@extraneous, amount.to_f.clamp(0.0, 1.0), EXTRANEOUS_ALPHA)
record_snapshot(event: :extraneous_added, source: source)
self
end
|
#add_germane(amount:, source: :unknown) ⇒ Object
45
46
47
48
49
|
# File 'lib/legion/extensions/agentic/executive/load/helpers/load_model.rb', line 45
def add_germane(amount:, source: :unknown)
@germane = ema_update(@germane, amount.to_f.clamp(0.0, 1.0), GERMANE_ALPHA)
record_snapshot(event: :germane_added, source: source)
self
end
|
#add_intrinsic(amount:, source: :unknown) ⇒ Object
33
34
35
36
37
|
# File 'lib/legion/extensions/agentic/executive/load/helpers/load_model.rb', line 33
def add_intrinsic(amount:, source: :unknown)
@intrinsic = ema_update(@intrinsic, amount.to_f.clamp(0.0, 1.0), INTRINSIC_ALPHA)
record_snapshot(event: :intrinsic_added, source: source)
self
end
|
#adjust_capacity(new_capacity:) ⇒ Object
65
66
67
68
69
|
# File 'lib/legion/extensions/agentic/executive/load/helpers/load_model.rb', line 65
def adjust_capacity(new_capacity:)
@capacity = new_capacity.to_f.clamp(0.1, 2.0)
record_snapshot(event: :capacity_adjusted, source: :external)
self
end
|
#decay ⇒ Object
57
58
59
60
61
62
63
|
# File 'lib/legion/extensions/agentic/executive/load/helpers/load_model.rb', line 57
def decay
@intrinsic = decay_toward(@intrinsic, DEFAULT_INTRINSIC)
@extraneous = decay_toward(@extraneous, DEFAULT_EXTRANEOUS)
@germane = decay_toward(@germane, DEFAULT_GERMANE)
record_snapshot(event: :decay, source: :tick)
self
end
|
#germane_ratio ⇒ Object
79
80
81
82
83
|
# File 'lib/legion/extensions/agentic/executive/load/helpers/load_model.rb', line 79
def germane_ratio
return 0.0 if total_load <= 0.0
(@germane / total_load).clamp(0.0, 1.0)
end
|
#load_label ⇒ Object
85
86
87
88
89
90
|
# File 'lib/legion/extensions/agentic/executive/load/helpers/load_model.rb', line 85
def load_label
LOAD_LABELS.each do |range, label|
return label if range.cover?(load_ratio)
end
:idle
end
|
#load_ratio ⇒ Object
27
28
29
30
31
|
# File 'lib/legion/extensions/agentic/executive/load/helpers/load_model.rb', line 27
def load_ratio
return 0.0 if @capacity <= 0.0
(total_load / @capacity).clamp(0.0, 1.0)
end
|
#overloaded? ⇒ Boolean
71
72
73
|
# File 'lib/legion/extensions/agentic/executive/load/helpers/load_model.rb', line 71
def overloaded?
load_ratio >= OVERLOAD_THRESHOLD
end
|
#recommendation ⇒ Object
92
93
94
95
96
97
98
|
# File 'lib/legion/extensions/agentic/executive/load/helpers/load_model.rb', line 92
def recommendation
return :simplify if overloaded?
return :increase_challenge if underloaded?
return :reduce_overhead if @extraneous > (@intrinsic + @germane)
:continue
end
|
51
52
53
54
55
|
# File 'lib/legion/extensions/agentic/executive/load/helpers/load_model.rb', line 51
def (amount:)
@extraneous = (@extraneous - amount.to_f.clamp(0.0, 1.0)).clamp(0.0, 1.0)
record_snapshot(event: :extraneous_reduced, source: :explicit)
self
end
|
#to_h ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/legion/extensions/agentic/executive/load/helpers/load_model.rb', line 100
def to_h
{
intrinsic: @intrinsic.round(4),
extraneous: @extraneous.round(4),
germane: @germane.round(4),
total_load: total_load.round(4),
capacity: @capacity.round(4),
load_ratio: load_ratio.round(4),
germane_ratio: germane_ratio.round(4),
load_label: load_label,
overloaded: overloaded?,
underloaded: underloaded?,
recommendation: recommendation,
history_size: @load_history.size
}
end
|
#total_load ⇒ Object
22
23
24
25
|
# File 'lib/legion/extensions/agentic/executive/load/helpers/load_model.rb', line 22
def total_load
raw = @intrinsic + @extraneous + @germane
raw.clamp(0.0, @capacity)
end
|
#underloaded? ⇒ Boolean
75
76
77
|
# File 'lib/legion/extensions/agentic/executive/load/helpers/load_model.rb', line 75
def underloaded?
load_ratio <= UNDERLOAD_THRESHOLD
end
|