Class: Legion::Extensions::Agentic::Self::Personality::Helpers::TraitModel
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Self::Personality::Helpers::TraitModel
- Defined in:
- lib/legion/extensions/agentic/self/personality/helpers/trait_model.rb
Instance Attribute Summary collapse
-
#history ⇒ Object
readonly
Returns the value of attribute history.
-
#observation_count ⇒ Object
readonly
Returns the value of attribute observation_count.
-
#traits ⇒ Object
readonly
Returns the value of attribute traits.
Instance Method Summary collapse
- #apply_partner_signals(signals) ⇒ Object
- #describe(name) ⇒ Object
- #dominant_trait ⇒ Object
- #formed? ⇒ Boolean
-
#initialize ⇒ TraitModel
constructor
A new instance of TraitModel.
- #profile ⇒ Object
- #stability ⇒ Object
- #to_h ⇒ Object
- #trait(name) ⇒ Object
- #trait_level(name) ⇒ Object
- #trend(name) ⇒ Object
- #update(signals) ⇒ Object
Constructor Details
#initialize ⇒ TraitModel
Returns a new instance of TraitModel.
12 13 14 15 16 17 18 |
# File 'lib/legion/extensions/agentic/self/personality/helpers/trait_model.rb', line 12 def initialize @traits = Constants::TRAITS.to_h do |trait| [trait, Constants::DEFAULT_TRAIT_VALUE] end @observation_count = 0 @history = [] end |
Instance Attribute Details
#history ⇒ Object (readonly)
Returns the value of attribute history.
10 11 12 |
# File 'lib/legion/extensions/agentic/self/personality/helpers/trait_model.rb', line 10 def history @history end |
#observation_count ⇒ Object (readonly)
Returns the value of attribute observation_count.
10 11 12 |
# File 'lib/legion/extensions/agentic/self/personality/helpers/trait_model.rb', line 10 def observation_count @observation_count end |
#traits ⇒ Object (readonly)
Returns the value of attribute traits.
10 11 12 |
# File 'lib/legion/extensions/agentic/self/personality/helpers/trait_model.rb', line 10 def traits @traits end |
Instance Method Details
#apply_partner_signals(signals) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/legion/extensions/agentic/self/personality/helpers/trait_model.rb', line 33 def apply_partner_signals(signals) observations = extract_partner_observations(signals) return if observations.empty? apply_observations(observations) record_snapshot end |
#describe(name) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/legion/extensions/agentic/self/personality/helpers/trait_model.rb', line 62 def describe(name) level = trait_level(name) return nil unless level Constants::TRAIT_DESCRIPTORS.dig(name.to_sym, level) end |
#dominant_trait ⇒ Object
45 46 47 |
# File 'lib/legion/extensions/agentic/self/personality/helpers/trait_model.rb', line 45 def dominant_trait @traits.max_by { |_k, v| (v - 0.5).abs }&.first end |
#formed? ⇒ Boolean
41 42 43 |
# File 'lib/legion/extensions/agentic/self/personality/helpers/trait_model.rb', line 41 def formed? @observation_count >= Constants::FORMATION_THRESHOLD end |
#profile ⇒ Object
69 70 71 |
# File 'lib/legion/extensions/agentic/self/personality/helpers/trait_model.rb', line 69 def profile @traits.transform_values { |v| v.round(3) } end |
#stability ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/legion/extensions/agentic/self/personality/helpers/trait_model.rb', line 73 def stability return 0.0 if @history.size < 5 recent = @history.last(10) variances = Constants::TRAITS.map do |t| values = recent.map { |h| h[:traits][t] } mean = values.sum / values.size.to_f values.sum { |v| (v - mean)**2 } / values.size.to_f end avg_variance = variances.sum / variances.size.to_f (1.0 - (avg_variance * 10)).clamp(0.0, 1.0) end |
#to_h ⇒ Object
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/legion/extensions/agentic/self/personality/helpers/trait_model.rb', line 103 def to_h { traits: profile, observation_count: @observation_count, formed: formed?, stability: stability, dominant_trait: dominant_trait, history_size: @history.size } end |
#trait(name) ⇒ Object
29 30 31 |
# File 'lib/legion/extensions/agentic/self/personality/helpers/trait_model.rb', line 29 def trait(name) @traits[name.to_sym] end |
#trait_level(name) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/legion/extensions/agentic/self/personality/helpers/trait_model.rb', line 49 def trait_level(name) value = @traits[name.to_sym] return nil unless value if value >= Constants::HIGH_THRESHOLD :high elsif value <= Constants::LOW_THRESHOLD :low else :mid end end |
#trend(name) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/legion/extensions/agentic/self/personality/helpers/trait_model.rb', line 86 def trend(name) return :insufficient_data if @history.size < 5 values = @history.last(10).map { |h| h[:traits][name.to_sym] } first_half = values[0...(values.size / 2)] second_half = values[(values.size / 2)..] diff = (second_half.sum / second_half.size.to_f) - (first_half.sum / first_half.size.to_f) if diff > 0.02 :increasing elsif diff < -0.02 :decreasing else :stable end end |
#update(signals) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/legion/extensions/agentic/self/personality/helpers/trait_model.rb', line 20 def update(signals) observations = extract_observations(signals) return if observations.empty? apply_observations(observations) @observation_count += 1 record_snapshot end |