Class: Typesafe::ChoiceAnswer
- Defined in:
- lib/typesafe/choice_answer.rb
Overview
Instance Attribute Summary collapse
-
#choice ⇒ String
readonly
The highest-probability option.
-
#confidence ⇒ Numeric
readonly
How certain the model is, between 0 and 1.
-
#probabilities ⇒ Hash
readonly
Every option mapped to its probability.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(choice:, probabilities:, confidence:) ⇒ ChoiceAnswer
constructor
A new instance of ChoiceAnswer.
- #to_h ⇒ Object
- #type ⇒ Object
Methods inherited from Answer
Constructor Details
#initialize(choice:, probabilities:, confidence:) ⇒ ChoiceAnswer
Returns a new instance of ChoiceAnswer.
27 28 29 30 31 32 |
# File 'lib/typesafe/choice_answer.rb', line 27 def initialize(choice:, probabilities:, confidence:) @choice = validate_string(choice, "choice") @probabilities = normalize_probabilities(probabilities) @confidence = validate_probability(confidence, "confidence") freeze end |
Instance Attribute Details
#choice ⇒ String (readonly)
Returns the highest-probability option.
14 15 16 |
# File 'lib/typesafe/choice_answer.rb', line 14 def choice @choice end |
#confidence ⇒ Numeric (readonly)
Returns how certain the model is, between 0 and 1.
20 21 22 |
# File 'lib/typesafe/choice_answer.rb', line 20 def confidence @confidence end |
#probabilities ⇒ Hash (readonly)
Returns every option mapped to its probability.
17 18 19 |
# File 'lib/typesafe/choice_answer.rb', line 17 def probabilities @probabilities end |
Class Method Details
.from_h(hash) ⇒ ChoiceAnswer
37 38 39 40 41 42 43 |
# File 'lib/typesafe/choice_answer.rb', line 37 def self.from_h(hash) new( choice: hash["choice"] || hash[:choice], probabilities: hash["probabilities"] || hash[:probabilities], confidence: hash["confidence"] || hash[:confidence] ) end |
Instance Method Details
#to_h ⇒ Object
49 50 51 |
# File 'lib/typesafe/choice_answer.rb', line 49 def to_h { type: type, choice: choice, probabilities: probabilities, confidence: confidence } end |
#type ⇒ Object
45 46 47 |
# File 'lib/typesafe/choice_answer.rb', line 45 def type "choice" end |