Class: Legion::Extensions::Agentic::Integration::PhenomenalBinding::Helpers::BindingUnit

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_unit.rb

Constant Summary

Constants included from Constants

Constants::BINDING_BOOST, Constants::BINDING_DECAY, Constants::BINDING_TYPES, Constants::COHERENCE_LABELS, Constants::COHERENCE_THRESHOLD, Constants::DEFAULT_SALIENCE, Constants::MAX_BINDINGS, Constants::MAX_STREAMS, Constants::STREAM_TYPES

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream_ids:, binding_type:, coherence:, attention_weight: 0.5) ⇒ BindingUnit

Returns a new instance of BindingUnit.



16
17
18
19
20
21
22
23
# File 'lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_unit.rb', line 16

def initialize(stream_ids:, binding_type:, coherence:, attention_weight: 0.5)
  @id              = ::SecureRandom.uuid
  @stream_ids      = stream_ids.dup
  @binding_type    = binding_type
  @coherence       = coherence.clamp(0.0, 1.0)
  @attention_weight = attention_weight.clamp(0.0, 1.0)
  @created_at = Time.now.utc
end

Instance Attribute Details

#attention_weightObject (readonly)

Returns the value of attribute attention_weight.



14
15
16
# File 'lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_unit.rb', line 14

def attention_weight
  @attention_weight
end

#binding_typeObject (readonly)

Returns the value of attribute binding_type.



14
15
16
# File 'lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_unit.rb', line 14

def binding_type
  @binding_type
end

#coherenceObject (readonly)

Returns the value of attribute coherence.



14
15
16
# File 'lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_unit.rb', line 14

def coherence
  @coherence
end

#created_atObject (readonly)

Returns the value of attribute created_at.



14
15
16
# File 'lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_unit.rb', line 14

def created_at
  @created_at
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_unit.rb', line 14

def id
  @id
end

#stream_idsObject (readonly)

Returns the value of attribute stream_ids.



14
15
16
# File 'lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_unit.rb', line 14

def stream_ids
  @stream_ids
end

Instance Method Details

#add_stream(stream_id:) ⇒ Object



25
26
27
# File 'lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_unit.rb', line 25

def add_stream(stream_id:)
  @stream_ids << stream_id unless @stream_ids.include?(stream_id)
end

#coherence_labelObject



45
46
47
# File 'lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_unit.rb', line 45

def coherence_label
  COHERENCE_LABELS.find { |range, _| range.cover?(@coherence) }&.last || :unbound
end

#coherent?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_unit.rb', line 41

def coherent?
  @coherence >= COHERENCE_THRESHOLD
end

#decay!Object



37
38
39
# File 'lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_unit.rb', line 37

def decay!
  @coherence = (@coherence - BINDING_DECAY).clamp(0.0, 1.0)
end

#reinforce!Object



33
34
35
# File 'lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_unit.rb', line 33

def reinforce!
  @coherence = (@coherence + BINDING_BOOST).clamp(0.0, 1.0)
end

#remove_stream(stream_id:) ⇒ Object



29
30
31
# File 'lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_unit.rb', line 29

def remove_stream(stream_id:)
  @stream_ids.delete(stream_id)
end

#stream_countObject



49
50
51
# File 'lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_unit.rb', line 49

def stream_count
  @stream_ids.size
end

#to_hObject



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_unit.rb', line 53

def to_h
  {
    id:               @id,
    stream_ids:       @stream_ids.dup,
    binding_type:     @binding_type,
    coherence:        @coherence.round(10),
    attention_weight: @attention_weight.round(10),
    coherent:         coherent?,
    coherence_label:  coherence_label,
    stream_count:     stream_count,
    created_at:       @created_at
  }
end