Class: Fabes::Experiment
Instance Attribute Summary collapse
-
#alternatives ⇒ Object
Returns the value of attribute alternatives.
-
#description ⇒ Object
Returns the value of attribute description.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #add_alternative(alternative) ⇒ Object
- #control ⇒ Object
- #find_alternative(id) ⇒ Object
-
#initialize(name, *alternatives) ⇒ Experiment
constructor
A new instance of Experiment.
- #save ⇒ Object
-
#select_alternative! ⇒ Object
TODO: make this an option and add different alternative selection algorithms.
Constructor Details
#initialize(name, *alternatives) ⇒ Experiment
Returns a new instance of Experiment.
5 6 7 8 9 10 11 |
# File 'lib/fabes/experiment.rb', line 5 def initialize(name, *alternatives) @name = name @alternatives = alternatives.map do |alternative| Fabes::Alternative.new alternative end save end |
Instance Attribute Details
#alternatives ⇒ Object
Returns the value of attribute alternatives.
3 4 5 |
# File 'lib/fabes/experiment.rb', line 3 def alternatives @alternatives end |
#description ⇒ Object
Returns the value of attribute description.
3 4 5 |
# File 'lib/fabes/experiment.rb', line 3 def description @description end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/fabes/experiment.rb', line 3 def name @name end |
Class Method Details
.all ⇒ Object
23 24 25 |
# File 'lib/fabes/experiment.rb', line 23 def self.all Fabes.db.all_experiments end |
.find(name) ⇒ Object
19 20 21 |
# File 'lib/fabes/experiment.rb', line 19 def self.find(name) Fabes.db.find_experiment name end |
.find_or_create(name, *alternatives) ⇒ Object
13 14 15 16 17 |
# File 'lib/fabes/experiment.rb', line 13 def self.find_or_create(name, *alternatives) #TODO: What happens if same experiment but different alternatives? #TODO: check the validation of alternatives experiment = find(name) or new(name, *alternatives) end |
Instance Method Details
#add_alternative(alternative) ⇒ Object
44 45 46 |
# File 'lib/fabes/experiment.rb', line 44 def add_alternative(alternative) @alternatives.push alternative end |
#control ⇒ Object
48 49 50 |
# File 'lib/fabes/experiment.rb', line 48 def control @alternatives.first end |
#find_alternative(id) ⇒ Object
36 37 38 |
# File 'lib/fabes/experiment.rb', line 36 def find_alternative(id) @alternatives.select {|alternative| alternative.id == id }.first or control end |
#save ⇒ Object
40 41 42 |
# File 'lib/fabes/experiment.rb', line 40 def save Fabes.db.save_experiment(self) end |
#select_alternative! ⇒ Object
TODO: make this an option and add different alternative selection algorithms
28 29 30 31 32 33 34 |
# File 'lib/fabes/experiment.rb', line 28 def select_alternative! if exploration? random_alternative else #exploitation heaviest_alternative end end |