Class: Legion::Extensions::Agentic::Inference::Schema::Helpers::CausalRelation
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Inference::Schema::Helpers::CausalRelation
- Defined in:
- lib/legion/extensions/agentic/inference/schema/helpers/causal_relation.rb
Instance Attribute Summary collapse
-
#cause ⇒ Object
readonly
Returns the value of attribute cause.
-
#confidence ⇒ Object
readonly
Returns the value of attribute confidence.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#effect ⇒ Object
readonly
Returns the value of attribute effect.
-
#evidence_count ⇒ Object
readonly
Returns the value of attribute evidence_count.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#relation_type ⇒ Object
readonly
Returns the value of attribute relation_type.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
Instance Method Summary collapse
- #decay ⇒ Object
- #established? ⇒ Boolean
-
#initialize(cause:, effect:, relation_type:, confidence: 0.5) ⇒ CausalRelation
constructor
A new instance of CausalRelation.
- #prunable? ⇒ Boolean
- #reinforce(amount = Constants::REINFORCEMENT_BONUS) ⇒ Object
- #speculative? ⇒ Boolean
- #to_h ⇒ Object
- #weaken(amount = Constants::CONTRADICTION_PENALTY) ⇒ Object
Constructor Details
#initialize(cause:, effect:, relation_type:, confidence: 0.5) ⇒ CausalRelation
Returns a new instance of CausalRelation.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/legion/extensions/agentic/inference/schema/helpers/causal_relation.rb', line 15 def initialize(cause:, effect:, relation_type:, confidence: 0.5) @id = SecureRandom.uuid @cause = cause @effect = effect @relation_type = relation_type @confidence = confidence.clamp(0.0, 1.0) @evidence_count = 1 @created_at = Time.now.utc @updated_at = Time.now.utc end |
Instance Attribute Details
#cause ⇒ Object (readonly)
Returns the value of attribute cause.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/schema/helpers/causal_relation.rb', line 12 def cause @cause end |
#confidence ⇒ Object (readonly)
Returns the value of attribute confidence.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/schema/helpers/causal_relation.rb', line 12 def confidence @confidence end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/schema/helpers/causal_relation.rb', line 12 def created_at @created_at end |
#effect ⇒ Object (readonly)
Returns the value of attribute effect.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/schema/helpers/causal_relation.rb', line 12 def effect @effect end |
#evidence_count ⇒ Object (readonly)
Returns the value of attribute evidence_count.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/schema/helpers/causal_relation.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/schema/helpers/causal_relation.rb', line 12 def id @id end |
#relation_type ⇒ Object (readonly)
Returns the value of attribute relation_type.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/schema/helpers/causal_relation.rb', line 12 def relation_type @relation_type end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/inference/schema/helpers/causal_relation.rb', line 12 def updated_at @updated_at end |
Instance Method Details
#decay ⇒ Object
37 38 39 |
# File 'lib/legion/extensions/agentic/inference/schema/helpers/causal_relation.rb', line 37 def decay @confidence = [@confidence - Constants::DECAY_RATE, 0.0].max end |
#established? ⇒ Boolean
41 42 43 |
# File 'lib/legion/extensions/agentic/inference/schema/helpers/causal_relation.rb', line 41 def established? @confidence >= Constants::CONFIDENCE_LEVELS[:established] end |
#prunable? ⇒ Boolean
49 50 51 |
# File 'lib/legion/extensions/agentic/inference/schema/helpers/causal_relation.rb', line 49 def prunable? @confidence < Constants::PRUNE_THRESHOLD end |
#reinforce(amount = Constants::REINFORCEMENT_BONUS) ⇒ Object
26 27 28 29 30 |
# File 'lib/legion/extensions/agentic/inference/schema/helpers/causal_relation.rb', line 26 def reinforce(amount = Constants::REINFORCEMENT_BONUS) @confidence = [@confidence + amount, 1.0].min @evidence_count += 1 @updated_at = Time.now.utc end |
#speculative? ⇒ Boolean
45 46 47 |
# File 'lib/legion/extensions/agentic/inference/schema/helpers/causal_relation.rb', line 45 def speculative? @confidence <= Constants::CONFIDENCE_LEVELS[:speculative] end |
#to_h ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/legion/extensions/agentic/inference/schema/helpers/causal_relation.rb', line 53 def to_h { id: @id, cause: @cause, effect: @effect, relation_type: @relation_type, confidence: @confidence.round(4), evidence_count: @evidence_count, established: established? } end |
#weaken(amount = Constants::CONTRADICTION_PENALTY) ⇒ Object
32 33 34 35 |
# File 'lib/legion/extensions/agentic/inference/schema/helpers/causal_relation.rb', line 32 def weaken(amount = Constants::CONTRADICTION_PENALTY) @confidence = [@confidence - amount, 0.0].max @updated_at = Time.now.utc end |