Module: Legion::Extensions::Agentic::Learning::Hebbian::Runners::HebbianAssembly

Includes:
Helpers::Lex
Included in:
Client
Defined in:
lib/legion/extensions/agentic/learning/hebbian/runners/hebbian_assembly.rb

Instance Method Summary collapse

Instance Method Details

#activate_unit(id:, level: 1.0, domain: :general) ⇒ Object



13
14
15
16
17
18
# File 'lib/legion/extensions/agentic/learning/hebbian/runners/hebbian_assembly.rb', line 13

def activate_unit(id:, level: 1.0, domain: :general, **)
  log.debug "[hebbian] activate: id=#{id} level=#{level}"
  network.add_unit(id: id, domain: domain)
  unit = network.activate_unit(id: id, level: level)
  { success: true, unit: unit.to_h, assemblies: network.assembly_count }
end

#assemblies_for(unit_id:) ⇒ Object



66
67
68
69
70
# File 'lib/legion/extensions/agentic/learning/hebbian/runners/hebbian_assembly.rb', line 66

def assemblies_for(unit_id:, **)
  asms = network.assemblies_containing(unit_id: unit_id).map(&:to_h)
  log.debug "[hebbian] assemblies_for: unit=#{unit_id} count=#{asms.size}"
  { success: true, assemblies: asms, count: asms.size }
end

#co_activate_units(ids:, level: 1.0) ⇒ Object



20
21
22
23
24
# File 'lib/legion/extensions/agentic/learning/hebbian/runners/hebbian_assembly.rb', line 20

def co_activate_units(ids:, level: 1.0, **)
  log.debug "[hebbian] co_activate: ids=#{ids}"
  results = network.co_activate(ids: ids, level: level)
  { success: true, units: results, assemblies: network.assembly_count }
end

#hebbian_statsObject



78
79
80
81
# File 'lib/legion/extensions/agentic/learning/hebbian/runners/hebbian_assembly.rb', line 78

def hebbian_stats(**)
  log.debug '[hebbian] stats'
  { success: true, stats: network.to_h }
end

#list_assembliesObject



34
35
36
37
38
# File 'lib/legion/extensions/agentic/learning/hebbian/runners/hebbian_assembly.rb', line 34

def list_assemblies(**)
  assemblies = network.assemblies.values.map(&:to_h)
  log.debug "[hebbian] list_assemblies: #{assemblies.size}"
  { success: true, assemblies: assemblies, count: assemblies.size }
end

#pattern_complete(partial_ids:) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/legion/extensions/agentic/learning/hebbian/runners/hebbian_assembly.rb', line 50

def pattern_complete(partial_ids:, **)
  log.debug "[hebbian] pattern_complete: partial=#{partial_ids}"
  result = network.pattern_complete(partial_ids: partial_ids)
  if result
    { success: true, completion: result }
  else
    { success: false, reason: :no_matching_assembly }
  end
end

#query_assembly(id:) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/legion/extensions/agentic/learning/hebbian/runners/hebbian_assembly.rb', line 40

def query_assembly(id:, **)
  asm = network.query_assembly(id: id.to_sym)
  log.debug "[hebbian] query_assembly: id=#{id} found=#{!asm.nil?}"
  if asm
    { success: true, assembly: asm.to_h }
  else
    { success: false, reason: :not_found }
  end
end

#query_weight(from:, to:) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/legion/extensions/agentic/learning/hebbian/runners/hebbian_assembly.rb', line 26

def query_weight(from:, to:, **)
  w = network.query_weight(from: from, to: to)
  label = Helpers::Constants::WEIGHT_LABELS.each { |range, l| break l if range.cover?(w) }
  label = :nascent unless label.is_a?(Symbol)
  log.debug "[hebbian] weight: #{from}->#{to} = #{w}"
  { success: true, from: from, to: to, weight: w.round(4), label: label }
end

#strongest_units(limit: 10) ⇒ Object



60
61
62
63
64
# File 'lib/legion/extensions/agentic/learning/hebbian/runners/hebbian_assembly.rb', line 60

def strongest_units(limit: 10, **)
  units = network.strongest_units(limit.to_i)
  log.debug "[hebbian] strongest_units: #{units.size}"
  { success: true, units: units }
end

#update_hebbianObject



72
73
74
75
76
# File 'lib/legion/extensions/agentic/learning/hebbian/runners/hebbian_assembly.rb', line 72

def update_hebbian(**)
  log.debug '[hebbian] decay tick'
  network.decay_all
  { success: true, units: network.unit_count, assemblies: network.assembly_count }
end