Class: ClassicBandit::Arm
- Inherits:
-
Object
- Object
- ClassicBandit::Arm
- Defined in:
- lib/classic_bandit/arm.rb
Overview
Represents an arm in a multi-armed bandit problem. Each arm maintains its own trial counts and success counts, which are used by various bandit algorithms to make decisions.
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#successes ⇒ Object
Returns the value of attribute successes.
-
#trials ⇒ Object
Returns the value of attribute trials.
Instance Method Summary collapse
-
#initialize(id:, name: nil, trials: 0, successes: 0) ⇒ Arm
constructor
A new instance of Arm.
-
#mean_reward ⇒ Float
Calculate mean reward (success rate) for this arm.
Constructor Details
#initialize(id:, name: nil, trials: 0, successes: 0) ⇒ Arm
Returns a new instance of Arm.
16 17 18 19 20 21 |
# File 'lib/classic_bandit/arm.rb', line 16 def initialize(id:, name: nil, trials: 0, successes: 0) @id = id @name = name || id.to_s @trials = trials @successes = successes end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
13 14 15 |
# File 'lib/classic_bandit/arm.rb', line 13 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/classic_bandit/arm.rb', line 13 def name @name end |
#successes ⇒ Object
Returns the value of attribute successes.
14 15 16 |
# File 'lib/classic_bandit/arm.rb', line 14 def successes @successes end |
#trials ⇒ Object
Returns the value of attribute trials.
14 15 16 |
# File 'lib/classic_bandit/arm.rb', line 14 def trials @trials end |
Instance Method Details
#mean_reward ⇒ Float
Calculate mean reward (success rate) for this arm
25 26 27 28 29 |
# File 'lib/classic_bandit/arm.rb', line 25 def mean_reward return 0.0 if @trials.zero? @successes.to_f / @trials end |