Module: Legion::Extensions::Agentic::Inference::PerceptualInference::Runners::PerceptualInference
- Includes:
- Helpers::Lex
- Included in:
- Client
- Defined in:
- lib/legion/extensions/agentic/inference/perceptual_inference/runners/perceptual_inference.rb
Instance Method Summary collapse
- #adapt_perception(modality:, correct_hypothesis_id:) ⇒ Object
- #check_rivalry(modality:) ⇒ Object
- #current_percept(modality:) ⇒ Object
- #perceptual_ambiguity ⇒ Object
- #perceptual_inference_stats ⇒ Object
- #present_perceptual_evidence(modality:, content:, strength: 0.5) ⇒ Object
- #register_percept_hypothesis(content:, modality:, domain: :general, prior: Helpers::DEFAULT_PRIOR) ⇒ Object
- #select_percept(modality:) ⇒ Object
- #suppress_percept(hypothesis_id:) ⇒ Object
- #update_perceptual_inference ⇒ Object
Instance Method Details
#adapt_perception(modality:, correct_hypothesis_id:) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/legion/extensions/agentic/inference/perceptual_inference/runners/perceptual_inference.rb', line 66 def adapt_perception(modality:, correct_hypothesis_id:, **) field.adapt_priors(modality: modality, correct_hypothesis_id: correct_hypothesis_id) log.info "[perceptual_inference] priors adapted modality=#{modality} correct=#{correct_hypothesis_id[0..7]}" { success: true, modality: modality, correct_hypothesis_id: correct_hypothesis_id } rescue ArgumentError => e { success: false, error: e. } end |
#check_rivalry(modality:) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/legion/extensions/agentic/inference/perceptual_inference/runners/perceptual_inference.rb', line 45 def check_rivalry(modality:, **) rival = field.rivalry?(modality: modality) candidates = field.hypotheses_for(modality) top_two = candidates.select { |h| %i[active selected].include?(h.state) }.max_by(2, &:posterior) log.debug "[perceptual_inference] rivalry check modality=#{modality} rival=#{rival}" { success: true, rivalry: rival, modality: modality, top_hypotheses: top_two.map(&:to_h) } rescue ArgumentError => e { success: false, error: e. } end |
#current_percept(modality:) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/legion/extensions/agentic/inference/perceptual_inference/runners/perceptual_inference.rb', line 55 def current_percept(modality:, **) percept = field.current_percept(modality: modality) if percept { success: true, found: true, modality: modality, percept: percept.to_h } else { success: true, found: false, modality: modality } end rescue ArgumentError => e { success: false, error: e. } end |
#perceptual_ambiguity ⇒ Object
80 81 82 83 84 85 |
# File 'lib/legion/extensions/agentic/inference/perceptual_inference/runners/perceptual_inference.rb', line 80 def perceptual_ambiguity(**) level = field.ambiguity_level label = ambiguity_label(level) log.debug "[perceptual_inference] ambiguity=#{level.round(3)} label=#{label}" { success: true, ambiguity_level: level, label: label } end |
#perceptual_inference_stats ⇒ Object
93 94 95 |
# File 'lib/legion/extensions/agentic/inference/perceptual_inference/runners/perceptual_inference.rb', line 93 def perceptual_inference_stats(**) { success: true, stats: field.to_h } end |
#present_perceptual_evidence(modality:, content:, strength: 0.5) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/legion/extensions/agentic/inference/perceptual_inference/runners/perceptual_inference.rb', line 21 def present_perceptual_evidence(modality:, content:, strength: 0.5, **) count = field.present_evidence(modality: modality, content: content, strength: strength) log.debug "[perceptual_inference] evidence presented modality=#{modality} strength=#{strength} updated=#{count}" { success: true, modality: modality, hypotheses_updated: count, rivalry: field.rivalry?(modality: modality) } rescue ArgumentError => e log.warn "[perceptual_inference] evidence failed: #{e.}" { success: false, error: e. } end |
#register_percept_hypothesis(content:, modality:, domain: :general, prior: Helpers::DEFAULT_PRIOR) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/legion/extensions/agentic/inference/perceptual_inference/runners/perceptual_inference.rb', line 12 def register_percept_hypothesis(content:, modality:, domain: :general, prior: Helpers::DEFAULT_PRIOR, **) hypothesis = field.register_hypothesis(content: content, modality: modality, domain: domain, prior: prior) log.debug "[perceptual_inference] registered hypothesis modality=#{modality} id=#{hypothesis.id[0..7]}" { success: true, hypothesis_id: hypothesis.id, modality: modality, prior: hypothesis.prior } rescue ArgumentError => e log.warn "[perceptual_inference] register failed: #{e.}" { success: false, error: e. } end |
#select_percept(modality:) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/legion/extensions/agentic/inference/perceptual_inference/runners/perceptual_inference.rb', line 30 def select_percept(modality:, **) winner = field.select_percept(modality: modality) if winner log.info "[perceptual_inference] percept selected modality=#{modality} " \ "posterior=#{winner.posterior.round(3)} label=#{winner.percept_label}" { success: true, selected: true, hypothesis: winner.to_h } else rivalry = field.rivalry?(modality: modality) log.debug "[perceptual_inference] no percept selected modality=#{modality} rivalry=#{rivalry}" { success: true, selected: false, rivalry: rivalry } end rescue ArgumentError => e { success: false, error: e. } end |
#suppress_percept(hypothesis_id:) ⇒ Object
74 75 76 77 78 |
# File 'lib/legion/extensions/agentic/inference/perceptual_inference/runners/perceptual_inference.rb', line 74 def suppress_percept(hypothesis_id:, **) suppressed = field.suppress_hypothesis(hypothesis_id: hypothesis_id) log.debug "[perceptual_inference] suppress hypothesis_id=#{hypothesis_id[0..7]} result=#{suppressed}" { success: true, suppressed: suppressed, hypothesis_id: hypothesis_id } end |
#update_perceptual_inference ⇒ Object
87 88 89 90 91 |
# File 'lib/legion/extensions/agentic/inference/perceptual_inference/runners/perceptual_inference.rb', line 87 def update_perceptual_inference(**) field.decay_all log.debug "[perceptual_inference] decay cycle complete remaining=#{field.hypotheses.size}" { success: true, remaining_hypotheses: field.hypotheses.size } end |