Class: Legion::Extensions::Agentic::Inference::RealityTesting::Helpers::Belief
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Inference::RealityTesting::Helpers::Belief
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/inference/reality_testing/helpers/belief.rb
Constant Summary
Constants included from Constants
Constants::CONFIDENCE_BOOST, Constants::CONFIDENCE_DECAY, Constants::CONFIDENCE_LABELS, Constants::CONFIDENCE_PENALTY, Constants::DEFAULT_CONFIDENCE, Constants::EVIDENCE_TYPES, Constants::MAX_BELIEFS, Constants::MAX_EVIDENCE, Constants::VALIDITY_LABELS
Instance Attribute Summary collapse
-
#claim ⇒ Object
readonly
Returns the value of attribute claim.
-
#confidence ⇒ Object
readonly
Returns the value of attribute confidence.
-
#confirming_count ⇒ Object
readonly
Returns the value of attribute confirming_count.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#disconfirming_count ⇒ Object
readonly
Returns the value of attribute disconfirming_count.
-
#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.
-
#last_tested_at ⇒ Object
readonly
Returns the value of attribute last_tested_at.
Instance Method Summary collapse
- #confidence_label ⇒ Object
- #decay! ⇒ Object
-
#initialize(id:, claim:, domain: :general, confidence: Constants::DEFAULT_CONFIDENCE) ⇒ Belief
constructor
A new instance of Belief.
- #needs_testing? ⇒ Boolean
- #test_with_evidence!(evidence_type:, weight: 0.1) ⇒ Object
- #to_h ⇒ Object
- #validity ⇒ Object
- #validity_label ⇒ Object
Constructor Details
#initialize(id:, claim:, domain: :general, confidence: Constants::DEFAULT_CONFIDENCE) ⇒ Belief
Returns a new instance of Belief.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/legion/extensions/agentic/inference/reality_testing/helpers/belief.rb', line 15 def initialize(id:, claim:, domain: :general, confidence: Constants::DEFAULT_CONFIDENCE) @id = id @claim = claim @domain = domain @confidence = confidence.clamp(0.0, 1.0) @evidence_count = 0 @confirming_count = 0 @disconfirming_count = 0 @created_at = Time.now.utc @last_tested_at = nil end |
Instance Attribute Details
#claim ⇒ Object (readonly)
Returns the value of attribute claim.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/reality_testing/helpers/belief.rb', line 12 def claim @claim end |
#confidence ⇒ Object (readonly)
Returns the value of attribute confidence.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/reality_testing/helpers/belief.rb', line 12 def confidence @confidence end |
#confirming_count ⇒ Object (readonly)
Returns the value of attribute confirming_count.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/reality_testing/helpers/belief.rb', line 12 def confirming_count @confirming_count end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/reality_testing/helpers/belief.rb', line 12 def created_at @created_at end |
#disconfirming_count ⇒ Object (readonly)
Returns the value of attribute disconfirming_count.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/reality_testing/helpers/belief.rb', line 12 def disconfirming_count @disconfirming_count end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/reality_testing/helpers/belief.rb', line 12 def domain @domain end |
#evidence_count ⇒ Object (readonly)
Returns the value of attribute evidence_count.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/reality_testing/helpers/belief.rb', line 12 def evidence_count @evidence_count end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/reality_testing/helpers/belief.rb', line 12 def id @id end |
#last_tested_at ⇒ Object (readonly)
Returns the value of attribute last_tested_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/reality_testing/helpers/belief.rb', line 12 def last_tested_at @last_tested_at end |
Instance Method Details
#confidence_label ⇒ Object
50 51 52 |
# File 'lib/legion/extensions/agentic/inference/reality_testing/helpers/belief.rb', line 50 def confidence_label Constants::CONFIDENCE_LABELS.find { |entry| entry[:range].cover?(@confidence) }&.fetch(:label) || :rejected end |
#decay! ⇒ Object
70 71 72 73 |
# File 'lib/legion/extensions/agentic/inference/reality_testing/helpers/belief.rb', line 70 def decay! @confidence = (@confidence - Constants::CONFIDENCE_DECAY).clamp(0.0, 1.0) self end |
#needs_testing? ⇒ Boolean
66 67 68 |
# File 'lib/legion/extensions/agentic/inference/reality_testing/helpers/belief.rb', line 66 def needs_testing? @confidence.between?(0.3, 0.7) end |
#test_with_evidence!(evidence_type:, weight: 0.1) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/legion/extensions/agentic/inference/reality_testing/helpers/belief.rb', line 27 def test_with_evidence!(evidence_type:, weight: 0.1) raise ArgumentError, "unknown evidence_type: #{evidence_type}" unless Constants::EVIDENCE_TYPES.include?(evidence_type) @evidence_count += 1 @last_tested_at = Time.now.utc case evidence_type when :confirming @confirming_count += 1 @confidence = (@confidence + (Constants::CONFIDENCE_BOOST * weight * 10)).clamp(0.0, 1.0) when :disconfirming @disconfirming_count += 1 @confidence = (@confidence - (Constants::CONFIDENCE_PENALTY * weight * 10)).clamp(0.0, 1.0) when :neutral # no confidence change when :ambiguous delta = @confidence - 0.5 @confidence = (@confidence - (delta * 0.1)).clamp(0.0, 1.0) end self end |
#to_h ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/legion/extensions/agentic/inference/reality_testing/helpers/belief.rb', line 75 def to_h { id: @id, claim: @claim, domain: @domain, confidence: @confidence, confidence_label: confidence_label, evidence_count: @evidence_count, confirming_count: @confirming_count, disconfirming_count: @disconfirming_count, validity: validity.round(3), validity_label: validity_label, needs_testing: needs_testing?, created_at: @created_at, last_tested_at: @last_tested_at } end |
#validity ⇒ Object
54 55 56 57 58 59 |
# File 'lib/legion/extensions/agentic/inference/reality_testing/helpers/belief.rb', line 54 def validity total = @confirming_count + @disconfirming_count return 0.5 if total.zero? @confirming_count.to_f / total end |
#validity_label ⇒ Object
61 62 63 64 |
# File 'lib/legion/extensions/agentic/inference/reality_testing/helpers/belief.rb', line 61 def validity_label v = validity Constants::VALIDITY_LABELS.find { |entry| entry[:range].cover?(v) }&.fetch(:label) || :refuted end |