Class: DecisionAgent::Scoring::Threshold
- Defined in:
- lib/decision_agent/scoring/threshold.rb
Instance Attribute Summary collapse
-
#fallback_decision ⇒ Object
readonly
Returns the value of attribute fallback_decision.
-
#threshold ⇒ Object
readonly
Returns the value of attribute threshold.
Instance Method Summary collapse
-
#initialize(threshold: 0.7, fallback_decision: "no_decision") ⇒ Threshold
constructor
A new instance of Threshold.
- #score(evaluations) ⇒ Object
Constructor Details
#initialize(threshold: 0.7, fallback_decision: "no_decision") ⇒ Threshold
Returns a new instance of Threshold.
8 9 10 11 |
# File 'lib/decision_agent/scoring/threshold.rb', line 8 def initialize(threshold: 0.7, fallback_decision: "no_decision") @threshold = threshold.to_f @fallback_decision = fallback_decision end |
Instance Attribute Details
#fallback_decision ⇒ Object (readonly)
Returns the value of attribute fallback_decision.
6 7 8 |
# File 'lib/decision_agent/scoring/threshold.rb', line 6 def fallback_decision @fallback_decision end |
#threshold ⇒ Object (readonly)
Returns the value of attribute threshold.
6 7 8 |
# File 'lib/decision_agent/scoring/threshold.rb', line 6 def threshold @threshold end |
Instance Method Details
#score(evaluations) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/decision_agent/scoring/threshold.rb', line 13 def score(evaluations) return { decision: @fallback_decision, confidence: 0.0 } if evaluations.empty? grouped = evaluations.group_by(&:decision) weighted_scores = grouped.map do |decision, evals| total_weight = evals.sum(&:weight) avg_weight = total_weight / evals.size [decision, avg_weight] end weighted_scores.sort_by! { |_, weight| -weight } winning_decision, winning_weight = weighted_scores.first if winning_weight >= @threshold { decision: winning_decision, confidence: round_confidence(normalize_confidence(winning_weight)) } else { decision: @fallback_decision, confidence: round_confidence(normalize_confidence(winning_weight * 0.5)) } end end |