Class: Legion::Extensions::Agentic::Inference::HypothesisTesting::Helpers::Hypothesis
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Inference::HypothesisTesting::Helpers::Hypothesis
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis.rb
Constant Summary
Constants included from Constants
Constants::CONFIDENCE_LABELS, Constants::CONFIRMATION_THRESHOLD, Constants::DISCONFIRMATION_THRESHOLD, Constants::EVIDENCE_WEIGHT, Constants::MAX_HYPOTHESES, Constants::PRIOR_DEFAULT, Constants::STATUS_LABELS
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#evidence_count ⇒ Object
readonly
Returns the value of attribute evidence_count.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#posterior ⇒ Object
readonly
Returns the value of attribute posterior.
-
#prior ⇒ Object
readonly
Returns the value of attribute prior.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #confidence_label ⇒ Object
- #confirm! ⇒ Object
- #disconfirm! ⇒ Object
-
#initialize(description:, domain: 'general', prior: Constants::PRIOR_DEFAULT) ⇒ Hypothesis
constructor
A new instance of Hypothesis.
- #to_h ⇒ Object
- #update_posterior!(evidence_strength:, supporting: true) ⇒ Object
Constructor Details
#initialize(description:, domain: 'general', prior: Constants::PRIOR_DEFAULT) ⇒ Hypothesis
Returns a new instance of Hypothesis.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis.rb', line 17 def initialize(description:, domain: 'general', prior: Constants::PRIOR_DEFAULT) @id = SecureRandom.uuid @description = description @domain = domain @prior = prior.clamp(0.0, 1.0) @posterior = @prior @evidence_count = 0 @status = :proposed @created_at = Time.now.utc end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
14 15 16 |
# File 'lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis.rb', line 14 def created_at @created_at end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
14 15 16 |
# File 'lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis.rb', line 14 def description @description end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
14 15 16 |
# File 'lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis.rb', line 14 def domain @domain end |
#evidence_count ⇒ Object (readonly)
Returns the value of attribute evidence_count.
14 15 16 |
# File 'lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis.rb', line 14 def evidence_count @evidence_count end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
14 15 16 |
# File 'lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis.rb', line 14 def id @id end |
#posterior ⇒ Object (readonly)
Returns the value of attribute posterior.
14 15 16 |
# File 'lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis.rb', line 14 def posterior @posterior end |
#prior ⇒ Object (readonly)
Returns the value of attribute prior.
14 15 16 |
# File 'lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis.rb', line 14 def prior @prior end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
14 15 16 |
# File 'lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis.rb', line 14 def status @status end |
Instance Method Details
#confidence_label ⇒ Object
57 58 59 60 61 62 |
# File 'lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis.rb', line 57 def confidence_label Constants::CONFIDENCE_LABELS.each do |range, label| return label if range.cover?(@posterior) end 'agnostic' end |
#confirm! ⇒ Object
45 46 47 48 49 |
# File 'lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis.rb', line 45 def confirm! @status = :confirmed @posterior = [@posterior, Constants::CONFIRMATION_THRESHOLD].max.round(10) self end |
#disconfirm! ⇒ Object
51 52 53 54 55 |
# File 'lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis.rb', line 51 def disconfirm! @status = :disconfirmed @posterior = [@posterior, Constants::DISCONFIRMATION_THRESHOLD].min.round(10) self end |
#to_h ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis.rb', line 64 def to_h { id: @id, description: @description, domain: @domain, prior: @prior, posterior: @posterior, evidence_count: @evidence_count, status: @status, confidence_label: confidence_label, created_at: @created_at } end |
#update_posterior!(evidence_strength:, supporting: true) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/legion/extensions/agentic/inference/hypothesis_testing/helpers/hypothesis.rb', line 28 def update_posterior!(evidence_strength:, supporting: true) return self if @status == :confirmed || @status == :disconfirmed @status = :testing weight = Constants::EVIDENCE_WEIGHT * evidence_strength.clamp(0.0, 1.0) @posterior = if supporting @posterior + (weight * (1.0 - @posterior)) else @posterior - (weight * @posterior) end @posterior = @posterior.clamp(0.0, 1.0).round(10) @evidence_count += 1 self end |