Class: Legion::Extensions::Agentic::Social::MoralReasoning::Helpers::MoralFoundation

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/social/moral_reasoning/helpers/moral_foundation.rb

Constant Summary

Constants included from Constants

Constants::DECAY_RATE, Constants::DEFAULT_WEIGHT, Constants::ETHICAL_FRAMEWORKS, Constants::KOHLBERG_LEVELS, Constants::KOHLBERG_STAGES, Constants::MAX_DILEMMAS, Constants::MAX_HISTORY, Constants::MAX_PRINCIPLES, Constants::MORAL_FOUNDATIONS, Constants::REINFORCEMENT_RATE, Constants::SEVERITY_LABELS, Constants::WEIGHT_CEILING, Constants::WEIGHT_FLOOR

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, weight: DEFAULT_WEIGHT, sensitivity: DEFAULT_WEIGHT) ⇒ MoralFoundation

Returns a new instance of MoralFoundation.



14
15
16
17
18
# File 'lib/legion/extensions/agentic/social/moral_reasoning/helpers/moral_foundation.rb', line 14

def initialize(id:, weight: DEFAULT_WEIGHT, sensitivity: DEFAULT_WEIGHT)
  @id          = id
  @weight      = weight.clamp(WEIGHT_FLOOR, WEIGHT_CEILING)
  @sensitivity = sensitivity.clamp(0.0, 1.0)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/legion/extensions/agentic/social/moral_reasoning/helpers/moral_foundation.rb', line 12

def id
  @id
end

#sensitivityObject (readonly)

Returns the value of attribute sensitivity.



12
13
14
# File 'lib/legion/extensions/agentic/social/moral_reasoning/helpers/moral_foundation.rb', line 12

def sensitivity
  @sensitivity
end

#weightObject (readonly)

Returns the value of attribute weight.



12
13
14
# File 'lib/legion/extensions/agentic/social/moral_reasoning/helpers/moral_foundation.rb', line 12

def weight
  @weight
end

Instance Method Details

#decayObject



28
29
30
# File 'lib/legion/extensions/agentic/social/moral_reasoning/helpers/moral_foundation.rb', line 28

def decay
  @weight = (@weight - DECAY_RATE).clamp(WEIGHT_FLOOR, WEIGHT_CEILING)
end

#reinforce(amount: 1.0) ⇒ Object



20
21
22
# File 'lib/legion/extensions/agentic/social/moral_reasoning/helpers/moral_foundation.rb', line 20

def reinforce(amount: 1.0)
  @weight = (@weight + (amount * REINFORCEMENT_RATE)).clamp(WEIGHT_FLOOR, WEIGHT_CEILING)
end

#to_hObject



32
33
34
35
36
37
38
# File 'lib/legion/extensions/agentic/social/moral_reasoning/helpers/moral_foundation.rb', line 32

def to_h
  {
    id:          @id,
    weight:      @weight,
    sensitivity: @sensitivity
  }
end

#weaken(amount: 1.0) ⇒ Object



24
25
26
# File 'lib/legion/extensions/agentic/social/moral_reasoning/helpers/moral_foundation.rb', line 24

def weaken(amount: 1.0)
  @weight = (@weight - (amount * REINFORCEMENT_RATE)).clamp(WEIGHT_FLOOR, WEIGHT_CEILING)
end