Class: Legion::Extensions::Agentic::Learning::Hebbian::Helpers::Assembly
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Learning::Hebbian::Helpers::Assembly
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/learning/hebbian/helpers/assembly.rb
Constant Summary
Constants included from Constants
Constants::ACTIVATION_THRESHOLD, Constants::ASSEMBLY_MIN_WEIGHT, Constants::ASSEMBLY_STATE_LABELS, Constants::ASSEMBLY_THRESHOLD, Constants::COMPETITION_FACTOR, Constants::CONSOLIDATION_BOOST, Constants::CO_ACTIVATION_WINDOW, Constants::DEFAULT_WEIGHT, Constants::LEARNING_RATE, Constants::MAX_ACTIVATION_HISTORY, Constants::MAX_ASSEMBLIES, Constants::MAX_CONNECTIONS_PER_UNIT, Constants::MAX_UNITS, Constants::MAX_WEIGHT, Constants::WEIGHT_DECAY, Constants::WEIGHT_FLOOR, Constants::WEIGHT_LABELS
Instance Attribute Summary collapse
-
#activation_count ⇒ Object
readonly
Returns the value of attribute activation_count.
-
#coherence ⇒ Object
Returns the value of attribute coherence.
-
#formed_at ⇒ Object
readonly
Returns the value of attribute formed_at.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#last_activated ⇒ Object
readonly
Returns the value of attribute last_activated.
-
#member_ids ⇒ Object
readonly
Returns the value of attribute member_ids.
Instance Method Summary collapse
- #activate ⇒ Object
- #consolidate ⇒ Object
- #decay ⇒ Object
- #dissolving? ⇒ Boolean
- #includes?(unit_id) ⇒ Boolean
-
#initialize(id:, member_ids:) ⇒ Assembly
constructor
A new instance of Assembly.
- #member_count ⇒ Object
- #state ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(id:, member_ids:) ⇒ Assembly
Returns a new instance of Assembly.
15 16 17 18 19 20 21 22 |
# File 'lib/legion/extensions/agentic/learning/hebbian/helpers/assembly.rb', line 15 def initialize(id:, member_ids:) @id = id @member_ids = Array(member_ids).uniq @coherence = 0.5 @formed_at = Time.now.utc @activation_count = 0 @last_activated = nil end |
Instance Attribute Details
#activation_count ⇒ Object (readonly)
Returns the value of attribute activation_count.
12 13 14 |
# File 'lib/legion/extensions/agentic/learning/hebbian/helpers/assembly.rb', line 12 def activation_count @activation_count end |
#coherence ⇒ Object
Returns the value of attribute coherence.
13 14 15 |
# File 'lib/legion/extensions/agentic/learning/hebbian/helpers/assembly.rb', line 13 def coherence @coherence end |
#formed_at ⇒ Object (readonly)
Returns the value of attribute formed_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/learning/hebbian/helpers/assembly.rb', line 12 def formed_at @formed_at end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/legion/extensions/agentic/learning/hebbian/helpers/assembly.rb', line 12 def id @id end |
#last_activated ⇒ Object (readonly)
Returns the value of attribute last_activated.
12 13 14 |
# File 'lib/legion/extensions/agentic/learning/hebbian/helpers/assembly.rb', line 12 def last_activated @last_activated end |
#member_ids ⇒ Object (readonly)
Returns the value of attribute member_ids.
12 13 14 |
# File 'lib/legion/extensions/agentic/learning/hebbian/helpers/assembly.rb', line 12 def member_ids @member_ids end |
Instance Method Details
#activate ⇒ Object
24 25 26 27 |
# File 'lib/legion/extensions/agentic/learning/hebbian/helpers/assembly.rb', line 24 def activate @activation_count += 1 @last_activated = Time.now.utc end |
#consolidate ⇒ Object
29 30 31 |
# File 'lib/legion/extensions/agentic/learning/hebbian/helpers/assembly.rb', line 29 def consolidate @coherence = [@coherence + CONSOLIDATION_BOOST, MAX_WEIGHT].min end |
#decay ⇒ Object
33 34 35 |
# File 'lib/legion/extensions/agentic/learning/hebbian/helpers/assembly.rb', line 33 def decay @coherence = [@coherence - WEIGHT_DECAY, 0.0].max end |
#dissolving? ⇒ Boolean
37 38 39 |
# File 'lib/legion/extensions/agentic/learning/hebbian/helpers/assembly.rb', line 37 def dissolving? @coherence < ASSEMBLY_MIN_WEIGHT end |
#includes?(unit_id) ⇒ Boolean
45 46 47 |
# File 'lib/legion/extensions/agentic/learning/hebbian/helpers/assembly.rb', line 45 def includes?(unit_id) @member_ids.include?(unit_id) end |
#member_count ⇒ Object
41 42 43 |
# File 'lib/legion/extensions/agentic/learning/hebbian/helpers/assembly.rb', line 41 def member_count @member_ids.size end |
#state ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/legion/extensions/agentic/learning/hebbian/helpers/assembly.rb', line 49 def state if @last_activated && (Time.now.utc - @last_activated) < CO_ACTIVATION_WINDOW :active elsif @last_activated && (Time.now.utc - @last_activated) < (CO_ACTIVATION_WINDOW * 3) :primed elsif dissolving? :dissolving elsif @coherence >= ASSEMBLY_MIN_WEIGHT :dormant else :forming end end |
#to_h ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/legion/extensions/agentic/learning/hebbian/helpers/assembly.rb', line 63 def to_h { id: @id, members: @member_ids.dup, member_count: member_count, coherence: @coherence.round(4), state: state, state_label: ASSEMBLY_STATE_LABELS[state], activation_count: @activation_count, formed_at: @formed_at, last_activated: @last_activated } end |