Class: Legion::Extensions::Agentic::Inference::EnactiveCognition::Helpers::EnactionEngine
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Inference::EnactiveCognition::Helpers::EnactionEngine
- Defined in:
- lib/legion/extensions/agentic/inference/enactive_cognition/helpers/enaction_engine.rb
Instance Attribute Summary collapse
-
#couplings ⇒ Object
readonly
Returns the value of attribute couplings.
Instance Method Summary collapse
- #adapt_coupling(coupling_id:, new_perception:) ⇒ Object
- #by_domain(domain:) ⇒ Object
- #by_type(loop_type:) ⇒ Object
- #count ⇒ Object
- #coupled_loops ⇒ Object
- #create_coupling(action:, perception:, domain:, loop_type: :sensorimotor) ⇒ Object
- #decay_all ⇒ Object
- #execute_action(coupling_id:, actual_perception:) ⇒ Object
- #find_action_for(perception:) ⇒ Object
-
#initialize ⇒ EnactionEngine
constructor
A new instance of EnactionEngine.
- #overall_coupling ⇒ Object
- #prune_decoupled ⇒ Object
- #strongest_couplings(limit: 5) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize ⇒ EnactionEngine
Returns a new instance of EnactionEngine.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/enactive_cognition/helpers/enaction_engine.rb', line 12 def initialize @couplings = {} end |
Instance Attribute Details
#couplings ⇒ Object (readonly)
Returns the value of attribute couplings.
10 11 12 |
# File 'lib/legion/extensions/agentic/inference/enactive_cognition/helpers/enaction_engine.rb', line 10 def couplings @couplings end |
Instance Method Details
#adapt_coupling(coupling_id:, new_perception:) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/legion/extensions/agentic/inference/enactive_cognition/helpers/enaction_engine.rb', line 44 def adapt_coupling(coupling_id:, new_perception:) loop = @couplings[coupling_id] return { success: false, reason: :not_found } unless loop loop.adapt_perception!(new_perception: new_perception) { success: true, coupling_id: coupling_id, new_perception: new_perception } end |
#by_domain(domain:) ⇒ Object
66 67 68 |
# File 'lib/legion/extensions/agentic/inference/enactive_cognition/helpers/enaction_engine.rb', line 66 def by_domain(domain:) @couplings.values.select { |lp| lp.domain.to_s == domain.to_s } end |
#by_type(loop_type:) ⇒ Object
70 71 72 |
# File 'lib/legion/extensions/agentic/inference/enactive_cognition/helpers/enaction_engine.rb', line 70 def by_type(loop_type:) @couplings.values.select { |lp| lp.loop_type == loop_type } end |
#count ⇒ Object
93 94 95 |
# File 'lib/legion/extensions/agentic/inference/enactive_cognition/helpers/enaction_engine.rb', line 93 def count @couplings.size end |
#coupled_loops ⇒ Object
62 63 64 |
# File 'lib/legion/extensions/agentic/inference/enactive_cognition/helpers/enaction_engine.rb', line 62 def coupled_loops @couplings.values.select(&:coupled?) end |
#create_coupling(action:, perception:, domain:, loop_type: :sensorimotor) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/legion/extensions/agentic/inference/enactive_cognition/helpers/enaction_engine.rb', line 16 def create_coupling(action:, perception:, domain:, loop_type: :sensorimotor) prune_to_limit loop = SensorimotorLoop.new( action: action, perception: perception, domain: domain, loop_type: loop_type ) @couplings[loop.id] = loop loop end |
#decay_all ⇒ Object
85 86 87 |
# File 'lib/legion/extensions/agentic/inference/enactive_cognition/helpers/enaction_engine.rb', line 85 def decay_all @couplings.each_value(&:decay!) end |
#execute_action(coupling_id:, actual_perception:) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/legion/extensions/agentic/inference/enactive_cognition/helpers/enaction_engine.rb', line 29 def execute_action(coupling_id:, actual_perception:) loop = @couplings[coupling_id] return { success: false, reason: :not_found } unless loop result = loop.execute!(actual_perception: actual_perception) { success: true, coupling_id: coupling_id, match: result[:match], coupling_strength: result[:coupling_strength], prediction_accuracy: result[:prediction_accuracy], coupling_label: loop.coupling_label } end |
#find_action_for(perception:) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/legion/extensions/agentic/inference/enactive_cognition/helpers/enaction_engine.rb', line 52 def find_action_for(perception:) best = @couplings.values .select(&:coupled?) .select { |lp| lp.perception.to_s == perception.to_s } .max_by(&:coupling_strength) return nil unless best best end |
#overall_coupling ⇒ Object
78 79 80 81 82 83 |
# File 'lib/legion/extensions/agentic/inference/enactive_cognition/helpers/enaction_engine.rb', line 78 def overall_coupling return 0.0 if @couplings.empty? total = @couplings.values.sum(&:coupling_strength) total / @couplings.size end |
#prune_decoupled ⇒ Object
89 90 91 |
# File 'lib/legion/extensions/agentic/inference/enactive_cognition/helpers/enaction_engine.rb', line 89 def prune_decoupled @couplings.delete_if { |_id, lp| lp.coupling_strength < SensorimotorLoop::COUPLING_FLOOR + 0.05 } end |
#strongest_couplings(limit: 5) ⇒ Object
74 75 76 |
# File 'lib/legion/extensions/agentic/inference/enactive_cognition/helpers/enaction_engine.rb', line 74 def strongest_couplings(limit: 5) @couplings.values.sort_by { |lp| -lp.coupling_strength }.first(limit) end |
#to_h ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'lib/legion/extensions/agentic/inference/enactive_cognition/helpers/enaction_engine.rb', line 97 def to_h { coupling_count: @couplings.size, coupled_count: coupled_loops.size, overall_coupling: overall_coupling.round(4), strongest: strongest_couplings(limit: 3).map(&:to_h) } end |