Class: Legion::Extensions::Agentic::Attention::FeatureBinding::Helpers::BindingField
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Attention::FeatureBinding::Helpers::BindingField
show all
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/attention/feature_binding/helpers/binding_field.rb
Constant Summary
Constants included
from Constants
Constants::ATTENTION_BOOST, Constants::BINDING_ALPHA, Constants::BINDING_CONFIRMATION_THRESHOLD, Constants::BINDING_DECAY, Constants::BINDING_STATE_LABELS, Constants::BINDING_STRENGTH_FLOOR, Constants::DEFAULT_BINDING_STRENGTH, Constants::FEATURE_DIMENSIONS, Constants::FEATURE_SALIENCE_FLOOR, Constants::ILLUSORY_CONJUNCTION_THRESHOLD, Constants::MAX_BINDINGS, Constants::MAX_BINDING_HISTORY, Constants::MAX_FEATURES, Constants::MAX_OBJECTS, Constants::STRENGTH_LABELS
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of BindingField.
14
15
16
17
18
19
|
# File 'lib/legion/extensions/agentic/attention/feature_binding/helpers/binding_field.rb', line 14
def initialize
@features = {}
@objects = {}
@binding_history = []
@object_counter = 0
end
|
Instance Attribute Details
#binding_history ⇒ Object
Returns the value of attribute binding_history.
12
13
14
|
# File 'lib/legion/extensions/agentic/attention/feature_binding/helpers/binding_field.rb', line 12
def binding_history
@binding_history
end
|
#features ⇒ Object
Returns the value of attribute features.
12
13
14
|
# File 'lib/legion/extensions/agentic/attention/feature_binding/helpers/binding_field.rb', line 12
def features
@features
end
|
#objects ⇒ Object
Returns the value of attribute objects.
12
13
14
|
# File 'lib/legion/extensions/agentic/attention/feature_binding/helpers/binding_field.rb', line 12
def objects
@objects
end
|
Instance Method Details
#attend(object_id:) ⇒ Object
46
47
48
49
50
51
52
53
|
# File 'lib/legion/extensions/agentic/attention/feature_binding/helpers/binding_field.rb', line 46
def attend(object_id:)
obj = @objects[object_id]
return nil unless obj
obj.strengthen
obj.confirm unless obj.confirmed?
obj
end
|
#bind(feature_ids:, attention: false) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/legion/extensions/agentic/attention/feature_binding/helpers/binding_field.rb', line 29
def bind(feature_ids:, attention: false)
ids = Array(feature_ids).select { |fid| @features.key?(fid) }
return nil if ids.size < 2
return nil if @objects.size >= MAX_OBJECTS
@object_counter += 1
obj_id = :"object_#{@object_counter}"
strength = attention ? DEFAULT_BINDING_STRENGTH + ATTENTION_BOOST : DEFAULT_BINDING_STRENGTH
obj = BoundObject.new(id: obj_id, feature_ids: ids, binding_strength: strength)
obj.confirm if attention
@objects[obj_id] = obj
record_binding(obj_id, ids, attention)
obj
end
|
#decay_all ⇒ Object
86
87
88
89
90
91
92
|
# File 'lib/legion/extensions/agentic/attention/feature_binding/helpers/binding_field.rb', line 86
def decay_all
@features.each_value(&:decay)
@features.reject! { |_, f| f.faded? }
@objects.each_value(&:decay)
@objects.reject! { |_, o| o.dissolved? }
end
|
#feature_count ⇒ Object
94
95
96
|
# File 'lib/legion/extensions/agentic/attention/feature_binding/helpers/binding_field.rb', line 94
def feature_count
@features.size
end
|
#features_of(object_id:) ⇒ Object
60
61
62
63
64
65
|
# File 'lib/legion/extensions/agentic/attention/feature_binding/helpers/binding_field.rb', line 60
def features_of(object_id:)
obj = @objects[object_id]
return [] unless obj
obj.feature_ids.filter_map { |fid| @features[fid]&.to_h }
end
|
#illusory_conjunctions ⇒ Object
71
72
73
|
# File 'lib/legion/extensions/agentic/attention/feature_binding/helpers/binding_field.rb', line 71
def illusory_conjunctions
@objects.values.select { |o| o.state == :illusory }.map(&:to_h)
end
|
#object_count ⇒ Object
98
99
100
|
# File 'lib/legion/extensions/agentic/attention/feature_binding/helpers/binding_field.rb', line 98
def object_count
@objects.size
end
|
#objects_with_feature(feature_id:) ⇒ Object
67
68
69
|
# File 'lib/legion/extensions/agentic/attention/feature_binding/helpers/binding_field.rb', line 67
def objects_with_feature(feature_id:)
@objects.values.select { |o| o.includes_feature?(feature_id) }.map(&:to_h)
end
|
#register_feature(id:, dimension:, value:, source: :perception, salience: 0.5) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/legion/extensions/agentic/attention/feature_binding/helpers/binding_field.rb', line 21
def register_feature(id:, dimension:, value:, source: :perception, salience: 0.5)
return @features[id] if @features.key?(id)
return nil unless FEATURE_DIMENSIONS.include?(dimension.to_sym)
return nil if @features.size >= MAX_FEATURES
@features[id] = Feature.new(id: id, dimension: dimension, value: value, source: source, salience: salience)
end
|
#search_by_dimension(dimension:, value: nil) ⇒ Object
80
81
82
83
84
|
# File 'lib/legion/extensions/agentic/attention/feature_binding/helpers/binding_field.rb', line 80
def search_by_dimension(dimension:, value: nil)
matches = @features.values.select { |f| f.dimension == dimension }
matches = matches.select { |f| f.value == value } if value
matches.map(&:to_h)
end
|
#to_h ⇒ Object
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/legion/extensions/agentic/attention/feature_binding/helpers/binding_field.rb', line 102
def to_h
{
features: @features.size,
objects: @objects.size,
confirmed_objects: @objects.values.count(&:confirmed?),
illusory_count: @objects.values.count { |o| o.state == :illusory },
unbound_features: unbound_features.size,
history_size: @binding_history.size
}
end
|
#unbind(object_id:) ⇒ Object
55
56
57
58
|
# File 'lib/legion/extensions/agentic/attention/feature_binding/helpers/binding_field.rb', line 55
def unbind(object_id:)
obj = @objects.delete(object_id)
!obj.nil?
end
|
#unbound_features ⇒ Object
75
76
77
78
|
# File 'lib/legion/extensions/agentic/attention/feature_binding/helpers/binding_field.rb', line 75
def unbound_features
bound_ids = @objects.values.flat_map(&:feature_ids).uniq
@features.values.reject { |f| bound_ids.include?(f.id) }.map(&:to_h)
end
|