Class: Legion::Extensions::MoralReasoning::Helpers::MoralFoundation
- Inherits:
-
Object
- Object
- Legion::Extensions::MoralReasoning::Helpers::MoralFoundation
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/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
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#sensitivity ⇒ Object
readonly
Returns the value of attribute sensitivity.
-
#weight ⇒ Object
readonly
Returns the value of attribute weight.
Instance Method Summary collapse
- #decay ⇒ Object
-
#initialize(id:, weight: DEFAULT_WEIGHT, sensitivity: DEFAULT_WEIGHT) ⇒ MoralFoundation
constructor
A new instance of MoralFoundation.
- #reinforce(amount: 1.0) ⇒ Object
- #to_h ⇒ Object
- #weaken(amount: 1.0) ⇒ Object
Constructor Details
#initialize(id:, weight: DEFAULT_WEIGHT, sensitivity: DEFAULT_WEIGHT) ⇒ MoralFoundation
Returns a new instance of MoralFoundation.
12 13 14 15 16 |
# File 'lib/legion/extensions/moral_reasoning/helpers/moral_foundation.rb', line 12 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
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/legion/extensions/moral_reasoning/helpers/moral_foundation.rb', line 10 def id @id end |
#sensitivity ⇒ Object (readonly)
Returns the value of attribute sensitivity.
10 11 12 |
# File 'lib/legion/extensions/moral_reasoning/helpers/moral_foundation.rb', line 10 def sensitivity @sensitivity end |
#weight ⇒ Object (readonly)
Returns the value of attribute weight.
10 11 12 |
# File 'lib/legion/extensions/moral_reasoning/helpers/moral_foundation.rb', line 10 def weight @weight end |
Instance Method Details
#decay ⇒ Object
26 27 28 |
# File 'lib/legion/extensions/moral_reasoning/helpers/moral_foundation.rb', line 26 def decay @weight = (@weight - DECAY_RATE).clamp(WEIGHT_FLOOR, WEIGHT_CEILING) end |
#reinforce(amount: 1.0) ⇒ Object
18 19 20 |
# File 'lib/legion/extensions/moral_reasoning/helpers/moral_foundation.rb', line 18 def reinforce(amount: 1.0) @weight = (@weight + (amount * REINFORCEMENT_RATE)).clamp(WEIGHT_FLOOR, WEIGHT_CEILING) end |
#to_h ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/legion/extensions/moral_reasoning/helpers/moral_foundation.rb', line 30 def to_h { id: @id, weight: @weight, sensitivity: @sensitivity } end |
#weaken(amount: 1.0) ⇒ Object
22 23 24 |
# File 'lib/legion/extensions/moral_reasoning/helpers/moral_foundation.rb', line 22 def weaken(amount: 1.0) @weight = (@weight - (amount * REINFORCEMENT_RATE)).clamp(WEIGHT_FLOOR, WEIGHT_CEILING) end |