Class: Legion::Extensions::Agentic::Attention::Priming::Helpers::ConceptNode

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/attention/priming/helpers/concept_node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#activationObject

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

#associationsObject (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

#domainObject (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

#nameObject (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_sourceObject

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_namesObject



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_activationObject



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_associationsObject



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

Returns:

  • (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_hObject



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