Class: Legion::Extensions::Agentic::Learning::Plasticity::Helpers::NeuralPathway

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/learning/plasticity/helpers/neural_pathway.rb

Constant Summary

Constants included from Constants

Constants::CRITICAL_PERIOD_MULTIPLIER, Constants::DEFAULT_LEARNING_RATE, Constants::MATURATION_RATE, Constants::MAX_EVENTS, Constants::MAX_PATHWAYS, Constants::PATHWAY_TYPES, Constants::PLASTICITY_LABELS, Constants::PRUNING_THRESHOLD, Constants::STRENGTHENING_RATE, Constants::STRENGTH_LABELS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label:, pathway_type: :synaptic, initial_strength: 0.3) ⇒ NeuralPathway

Returns a new instance of NeuralPathway.



17
18
19
20
21
22
23
24
25
# File 'lib/legion/extensions/agentic/learning/plasticity/helpers/neural_pathway.rb', line 17

def initialize(label:, pathway_type: :synaptic, initial_strength: 0.3)
  @id               = SecureRandom.uuid
  @label            = label
  @pathway_type     = pathway_type.to_sym
  @strength         = initial_strength.to_f.clamp(0.0, 1.0)
  @plasticity       = DEFAULT_LEARNING_RATE
  @activation_count = 0
  @created_at       = Time.now.utc
end

Instance Attribute Details

#activation_countObject (readonly)

Returns the value of attribute activation_count.



14
15
16
# File 'lib/legion/extensions/agentic/learning/plasticity/helpers/neural_pathway.rb', line 14

def activation_count
  @activation_count
end

#created_atObject (readonly)

Returns the value of attribute created_at.



14
15
16
# File 'lib/legion/extensions/agentic/learning/plasticity/helpers/neural_pathway.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/learning/plasticity/helpers/neural_pathway.rb', line 14

def id
  @id
end

#labelObject (readonly)

Returns the value of attribute label.



14
15
16
# File 'lib/legion/extensions/agentic/learning/plasticity/helpers/neural_pathway.rb', line 14

def label
  @label
end

#pathway_typeObject (readonly)

Returns the value of attribute pathway_type.



14
15
16
# File 'lib/legion/extensions/agentic/learning/plasticity/helpers/neural_pathway.rb', line 14

def pathway_type
  @pathway_type
end

#plasticityObject (readonly)

Returns the value of attribute plasticity.



14
15
16
# File 'lib/legion/extensions/agentic/learning/plasticity/helpers/neural_pathway.rb', line 14

def plasticity
  @plasticity
end

#strengthObject (readonly)

Returns the value of attribute strength.



14
15
16
# File 'lib/legion/extensions/agentic/learning/plasticity/helpers/neural_pathway.rb', line 14

def strength
  @strength
end

Instance Method Details

#mature!Object



46
47
48
# File 'lib/legion/extensions/agentic/learning/plasticity/helpers/neural_pathway.rb', line 46

def mature!
  @plasticity = (@plasticity - MATURATION_RATE).clamp(0.1, 1.0).round(10)
end

#plasticity_labelObject



60
61
62
63
# File 'lib/legion/extensions/agentic/learning/plasticity/helpers/neural_pathway.rb', line 60

def plasticity_label
  match = PLASTICITY_LABELS.find { |range, _| range.cover?(@plasticity) }
  match ? match.last : :crystallized
end

#prune_candidate?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/legion/extensions/agentic/learning/plasticity/helpers/neural_pathway.rb', line 42

def prune_candidate?
  @strength < PRUNING_THRESHOLD
end

#rejuvenate!(amount: 0.1) ⇒ Object



50
51
52
53
# File 'lib/legion/extensions/agentic/learning/plasticity/helpers/neural_pathway.rb', line 50

def rejuvenate!(amount: 0.1)
  @plasticity = (@plasticity + amount).clamp(0.1, 1.0).round(10)
  self
end

#strength_labelObject



55
56
57
58
# File 'lib/legion/extensions/agentic/learning/plasticity/helpers/neural_pathway.rb', line 55

def strength_label
  match = STRENGTH_LABELS.find { |range, _| range.cover?(@strength) }
  match ? match.last : :nascent
end

#strengthen!(amount: STRENGTHENING_RATE, critical_period: false) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/legion/extensions/agentic/learning/plasticity/helpers/neural_pathway.rb', line 27

def strengthen!(amount: STRENGTHENING_RATE, critical_period: false)
  multiplier = critical_period ? CRITICAL_PERIOD_MULTIPLIER : 1.0
  effective = (amount * multiplier * @plasticity).round(10)
  @strength = (@strength + effective).clamp(0.0, 1.0).round(10)
  @activation_count += 1
  mature!
  self
end

#to_hObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/legion/extensions/agentic/learning/plasticity/helpers/neural_pathway.rb', line 65

def to_h
  {
    id:               @id,
    label:            @label,
    pathway_type:     @pathway_type,
    strength:         @strength,
    strength_label:   strength_label,
    plasticity:       @plasticity,
    plasticity_label: plasticity_label,
    activation_count: @activation_count,
    prune_candidate:  prune_candidate?,
    created_at:       @created_at
  }
end

#weaken!(amount: STRENGTHENING_RATE) ⇒ Object



36
37
38
39
40
# File 'lib/legion/extensions/agentic/learning/plasticity/helpers/neural_pathway.rb', line 36

def weaken!(amount: STRENGTHENING_RATE)
  effective = (amount * @plasticity).round(10)
  @strength = (@strength - effective).clamp(0.0, 1.0).round(10)
  self
end