Class: Legion::Extensions::Agentic::Self::Fingerprint::Helpers::CognitiveTrait
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Self::Fingerprint::Helpers::CognitiveTrait
- Defined in:
- lib/legion/extensions/agentic/self/fingerprint/helpers/cognitive_trait.rb
Instance Attribute Summary collapse
-
#baseline ⇒ Object
readonly
Returns the value of attribute baseline.
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#last_updated ⇒ Object
readonly
Returns the value of attribute last_updated.
-
#sample_count ⇒ Object
readonly
Returns the value of attribute sample_count.
-
#variance ⇒ Object
readonly
Returns the value of attribute variance.
Instance Method Summary collapse
- #deviation_from(value) ⇒ Object
-
#initialize(category:) ⇒ CognitiveTrait
constructor
A new instance of CognitiveTrait.
- #record_sample!(value) ⇒ Object
- #stable? ⇒ Boolean
- #strength_label ⇒ Object
- #to_h ⇒ Object
- #volatile? ⇒ Boolean
Constructor Details
#initialize(category:) ⇒ CognitiveTrait
Returns a new instance of CognitiveTrait.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/legion/extensions/agentic/self/fingerprint/helpers/cognitive_trait.rb', line 14 def initialize(category:) raise ArgumentError, "unknown category: #{category}" unless Constants::TRAIT_CATEGORIES.include?(category) @id = SecureRandom.uuid @category = category @baseline = 0.5 @variance = 0.0 @sample_count = 0 @last_updated = Time.now.utc end |
Instance Attribute Details
#baseline ⇒ Object (readonly)
Returns the value of attribute baseline.
12 13 14 |
# File 'lib/legion/extensions/agentic/self/fingerprint/helpers/cognitive_trait.rb', line 12 def baseline @baseline end |
#category ⇒ Object (readonly)
Returns the value of attribute category.
12 13 14 |
# File 'lib/legion/extensions/agentic/self/fingerprint/helpers/cognitive_trait.rb', line 12 def category @category end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/legion/extensions/agentic/self/fingerprint/helpers/cognitive_trait.rb', line 12 def id @id end |
#last_updated ⇒ Object (readonly)
Returns the value of attribute last_updated.
12 13 14 |
# File 'lib/legion/extensions/agentic/self/fingerprint/helpers/cognitive_trait.rb', line 12 def last_updated @last_updated end |
#sample_count ⇒ Object (readonly)
Returns the value of attribute sample_count.
12 13 14 |
# File 'lib/legion/extensions/agentic/self/fingerprint/helpers/cognitive_trait.rb', line 12 def sample_count @sample_count end |
#variance ⇒ Object (readonly)
Returns the value of attribute variance.
12 13 14 |
# File 'lib/legion/extensions/agentic/self/fingerprint/helpers/cognitive_trait.rb', line 12 def variance @variance end |
Instance Method Details
#deviation_from(value) ⇒ Object
38 39 40 |
# File 'lib/legion/extensions/agentic/self/fingerprint/helpers/cognitive_trait.rb', line 38 def deviation_from(value) (value.clamp(0.0, 1.0) - @baseline).abs.round(10) end |
#record_sample!(value) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/legion/extensions/agentic/self/fingerprint/helpers/cognitive_trait.rb', line 25 def record_sample!(value) clamped = value.clamp(0.0, 1.0) old_baseline = @baseline @baseline = ((Constants::EMA_ALPHA * clamped) + ((1.0 - Constants::EMA_ALPHA) * old_baseline)).round(10) deviation = (clamped - @baseline).abs @variance = ((Constants::EMA_ALPHA * deviation) + ((1.0 - Constants::EMA_ALPHA) * @variance)).round(10) @sample_count = [@sample_count + 1, Constants::MAX_SAMPLES].min @last_updated = Time.now.utc self end |
#stable? ⇒ Boolean
42 43 44 |
# File 'lib/legion/extensions/agentic/self/fingerprint/helpers/cognitive_trait.rb', line 42 def stable? @variance <= 0.1 end |
#strength_label ⇒ Object
50 51 52 |
# File 'lib/legion/extensions/agentic/self/fingerprint/helpers/cognitive_trait.rb', line 50 def strength_label Constants.trait_strength_label_for(@baseline) end |
#to_h ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/legion/extensions/agentic/self/fingerprint/helpers/cognitive_trait.rb', line 54 def to_h { id: @id, category: @category, baseline: @baseline, variance: @variance, sample_count: @sample_count, stable: stable?, volatile: volatile?, strength: strength_label, last_updated: @last_updated } end |
#volatile? ⇒ Boolean
46 47 48 |
# File 'lib/legion/extensions/agentic/self/fingerprint/helpers/cognitive_trait.rb', line 46 def volatile? @variance >= 0.3 end |