Class: Legion::Extensions::Agentic::Attention::Priming::Helpers::ConceptNode
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Attention::Priming::Helpers::ConceptNode
- Defined in:
- lib/legion/extensions/agentic/attention/priming/helpers/concept_node.rb
Instance Attribute Summary collapse
-
#activation ⇒ Object
Returns the value of attribute activation.
-
#associations ⇒ Object
readonly
Returns the value of attribute associations.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#prime_source ⇒ Object
Returns the value of attribute prime_source.
Instance Method Summary collapse
- #associate(other_name, strength: Constants::DEFAULT_ASSOCIATION_STRENGTH) ⇒ Object
- #associated_names ⇒ Object
- #association_strength(other_name) ⇒ Object
- #decay_activation ⇒ Object
- #decay_associations ⇒ Object
-
#initialize(name:, domain: :general) ⇒ ConceptNode
constructor
A new instance of ConceptNode.
- #prime(boost: Constants::PRIME_BOOST, source: nil) ⇒ Object
- #primed? ⇒ Boolean
- #strengthen_association(other_name) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(name:, domain: :general) ⇒ ConceptNode
Returns a new instance of ConceptNode.
13 14 15 16 17 18 19 |
# File 'lib/legion/extensions/agentic/attention/priming/helpers/concept_node.rb', line 13 def initialize(name:, domain: :general) @name = name @domain = domain @activation = 0.0 @prime_source = nil @associations = {} end |
Instance Attribute Details
#activation ⇒ Object
Returns the value of attribute activation.
11 12 13 |
# File 'lib/legion/extensions/agentic/attention/priming/helpers/concept_node.rb', line 11 def activation @activation end |
#associations ⇒ Object (readonly)
Returns the value of attribute associations.
10 11 12 |
# File 'lib/legion/extensions/agentic/attention/priming/helpers/concept_node.rb', line 10 def associations @associations end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
10 11 12 |
# File 'lib/legion/extensions/agentic/attention/priming/helpers/concept_node.rb', line 10 def domain @domain end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/legion/extensions/agentic/attention/priming/helpers/concept_node.rb', line 10 def name @name end |
#prime_source ⇒ Object
Returns the value of attribute prime_source.
11 12 13 |
# File 'lib/legion/extensions/agentic/attention/priming/helpers/concept_node.rb', line 11 def prime_source @prime_source end |
Instance Method Details
#associate(other_name, strength: Constants::DEFAULT_ASSOCIATION_STRENGTH) ⇒ Object
25 26 27 28 |
# File 'lib/legion/extensions/agentic/attention/priming/helpers/concept_node.rb', line 25 def associate(other_name, strength: Constants::DEFAULT_ASSOCIATION_STRENGTH) @associations[other_name] = strength.clamp(Constants::ASSOCIATION_FLOOR, Constants::ASSOCIATION_CEILING) trim_associations end |
#associated_names ⇒ Object
62 63 64 |
# File 'lib/legion/extensions/agentic/attention/priming/helpers/concept_node.rb', line 62 def associated_names @associations.keys end |
#association_strength(other_name) ⇒ Object
58 59 60 |
# File 'lib/legion/extensions/agentic/attention/priming/helpers/concept_node.rb', line 58 def association_strength(other_name) @associations[other_name] || 0.0 end |
#decay_activation ⇒ Object
48 49 50 51 |
# File 'lib/legion/extensions/agentic/attention/priming/helpers/concept_node.rb', line 48 def decay_activation @activation = [@activation - Constants::PRIME_DECAY, 0.0].max @prime_source = nil unless primed? end |
#decay_associations ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/legion/extensions/agentic/attention/priming/helpers/concept_node.rb', line 39 def decay_associations @associations.each_key do |key| @associations[key] = [ @associations[key] - Constants::ASSOCIATION_DECAY, Constants::ASSOCIATION_FLOOR ].max end end |
#prime(boost: Constants::PRIME_BOOST, source: nil) ⇒ Object
53 54 55 56 |
# File 'lib/legion/extensions/agentic/attention/priming/helpers/concept_node.rb', line 53 def prime(boost: Constants::PRIME_BOOST, source: nil) @activation = [@activation + boost, 1.0].min @prime_source = source end |
#primed? ⇒ Boolean
21 22 23 |
# File 'lib/legion/extensions/agentic/attention/priming/helpers/concept_node.rb', line 21 def primed? @activation >= Constants::PRIME_THRESHOLD end |
#strengthen_association(other_name) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/legion/extensions/agentic/attention/priming/helpers/concept_node.rb', line 30 def strengthen_association(other_name) return unless @associations.key?(other_name) @associations[other_name] = [ @associations[other_name] + Constants::ASSOCIATION_STRENGTHEN, Constants::ASSOCIATION_CEILING ].min end |
#to_h ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/legion/extensions/agentic/attention/priming/helpers/concept_node.rb', line 66 def to_h { name: @name, domain: @domain, activation: @activation.round(4), primed: primed?, prime_source: @prime_source, associations: @associations.transform_values { |v| v.round(4) } } end |