Class: Legion::Extensions::Agentic::Inference::PerceptualInference::Helpers::PerceptualHypothesis
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Inference::PerceptualInference::Helpers::PerceptualHypothesis
- Defined in:
- lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#likelihood ⇒ Object
Returns the value of attribute likelihood.
-
#modality ⇒ Object
readonly
Returns the value of attribute modality.
-
#posterior ⇒ Object
Returns the value of attribute posterior.
-
#prior ⇒ Object
Returns the value of attribute prior.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
- #adapt_prior(outcome:) ⇒ Object
- #compute_posterior(evidence_weight:) ⇒ Object
- #decay ⇒ Object
-
#initialize(content:, modality:, domain: :general, prior: DEFAULT_PRIOR) ⇒ PerceptualHypothesis
constructor
A new instance of PerceptualHypothesis.
- #percept_label ⇒ Object
- #rival_with?(other) ⇒ Boolean
- #select! ⇒ Object
- #selected? ⇒ Boolean
- #suppress! ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(content:, modality:, domain: :general, prior: DEFAULT_PRIOR) ⇒ PerceptualHypothesis
Returns a new instance of PerceptualHypothesis.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis.rb', line 15 def initialize(content:, modality:, domain: :general, prior: DEFAULT_PRIOR) @id = SecureRandom.uuid @content = content @modality = modality @domain = domain @prior = clamp_prior(prior.to_f) @likelihood = 0.5 @posterior = @prior @state = :active @created_at = Time.now.utc end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis.rb', line 12 def content @content end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis.rb', line 12 def created_at @created_at end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis.rb', line 12 def domain @domain end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis.rb', line 12 def id @id end |
#likelihood ⇒ Object
Returns the value of attribute likelihood.
13 14 15 |
# File 'lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis.rb', line 13 def likelihood @likelihood end |
#modality ⇒ Object (readonly)
Returns the value of attribute modality.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis.rb', line 12 def modality @modality end |
#posterior ⇒ Object
Returns the value of attribute posterior.
13 14 15 |
# File 'lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis.rb', line 13 def posterior @posterior end |
#prior ⇒ Object
Returns the value of attribute prior.
13 14 15 |
# File 'lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis.rb', line 13 def prior @prior end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis.rb', line 12 def state @state end |
Instance Method Details
#adapt_prior(outcome:) ⇒ Object
51 52 53 54 |
# File 'lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis.rb', line 51 def adapt_prior(outcome:) delta = outcome == :correct ? ADAPTATION_RATE : -ADAPTATION_RATE @prior = clamp_prior(@prior + delta) end |
#compute_posterior(evidence_weight:) ⇒ Object
27 28 29 30 31 |
# File 'lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis.rb', line 27 def compute_posterior(evidence_weight:) weight = [evidence_weight.to_f, EVIDENCE_STRENGTH_FLOOR].max raw = @prior * ((@likelihood * weight) + ((1.0 - weight) * @prior)) @posterior = clamp_unit(raw) end |
#decay ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis.rb', line 56 def decay if @state == :suppressed @prior = clamp_prior(@prior - (DECAY_RATE * 5)) @state = :decayed if @prior <= PRIOR_FLOOR + 0.001 else @prior = clamp_prior(@prior + ((DEFAULT_PRIOR - @prior) * DECAY_RATE)) end end |
#percept_label ⇒ Object
65 66 67 68 |
# File 'lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis.rb', line 65 def percept_label PERCEPT_LABELS.each { |range, label| return label if range.cover?(@posterior) } :subliminal end |
#rival_with?(other) ⇒ Boolean
45 46 47 48 49 |
# File 'lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis.rb', line 45 def rival_with?(other) return false unless other.is_a?(PerceptualHypothesis) (posterior - other.posterior).abs <= RIVALRY_MARGIN end |
#select! ⇒ Object
33 34 35 |
# File 'lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis.rb', line 33 def select! @state = :selected end |
#selected? ⇒ Boolean
41 42 43 |
# File 'lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis.rb', line 41 def selected? @state == :selected end |
#suppress! ⇒ Object
37 38 39 |
# File 'lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis.rb', line 37 def suppress! @state = :suppressed end |
#to_h ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/legion/extensions/agentic/inference/perceptual_inference/helpers/perceptual_hypothesis.rb', line 70 def to_h { id: @id, content: @content, modality: @modality, domain: @domain, prior: @prior.round(4), likelihood: @likelihood.round(4), posterior: @posterior.round(4), state: @state, label: percept_label, created_at: @created_at } end |