Module: Legion::Extensions::Apollo::Helpers::Confidence
- Extended by:
- Logging::Helper, Settings::Helper
- Defined in:
- lib/legion/extensions/apollo/helpers/confidence.rb
Constant Summary collapse
- INITIAL_CONFIDENCE =
0.5- CORROBORATION_BOOST =
0.3- RETRIEVAL_BOOST =
0.02- POWER_LAW_ALPHA =
0.05- DECAY_THRESHOLD =
0.05- CORROBORATION_SIMILARITY_THRESHOLD =
0.9- WRITE_CONFIDENCE_GATE =
0.6- WRITE_NOVELTY_GATE =
0.3- STALE_DAYS =
90- DECAY_MIN_AGE_HOURS =
168- CONTENT_TYPES =
%i[fact concept procedure association observation].freeze
- STATUSES =
%w[candidate confirmed disputed decayed archived].freeze
- RELATION_TYPES =
%w[is_a has_a part_of causes similar_to contradicts supersedes depends_on].freeze
Class Method Summary collapse
- .apply_corroboration_boost(confidence:, weight: 1.0) ⇒ Object
- .apply_decay(confidence:, age_hours: nil, alpha: power_law_alpha) ⇒ Object
- .apply_retrieval_boost(confidence:) ⇒ Object
- .corroboration_boost ⇒ Object
- .corroboration_similarity_threshold ⇒ Object
- .decay_min_age_hours ⇒ Object
- .decay_threshold ⇒ Object
- .decayed?(confidence:) ⇒ Boolean
- .initial_confidence ⇒ Object
- .meets_write_gate?(confidence:, novelty:) ⇒ Boolean
- .power_law_alpha ⇒ Object
- .retrieval_boost ⇒ Object
- .stale_days ⇒ Object
- .write_confidence_gate ⇒ Object
- .write_novelty_gate ⇒ Object
Class Method Details
.apply_corroboration_boost(confidence:, weight: 1.0) ⇒ Object
57 58 59 |
# File 'lib/legion/extensions/apollo/helpers/confidence.rb', line 57 def apply_corroboration_boost(confidence:, weight: 1.0, **) [confidence + (corroboration_boost * weight), 1.0].min end |
.apply_decay(confidence:, age_hours: nil, alpha: power_law_alpha) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/legion/extensions/apollo/helpers/confidence.rb', line 41 def apply_decay(confidence:, age_hours: nil, alpha: power_law_alpha, **) return confidence if age_hours && age_hours < decay_min_age_hours if age_hours age_days = age_hours / 24.0 [confidence * ((age_days.clamp(1, Float::INFINITY) + 1.0)**(-alpha)) / (age_days.clamp(1, Float::INFINITY)**(-alpha)), 0.0].max else factor = 1.0 / (1.0 + alpha) [confidence * factor, 0.0].max end end |
.apply_retrieval_boost(confidence:) ⇒ Object
53 54 55 |
# File 'lib/legion/extensions/apollo/helpers/confidence.rb', line 53 def apply_retrieval_boost(confidence:, **) [confidence + retrieval_boost, 1.0].min end |
.corroboration_boost ⇒ Object
28 |
# File 'lib/legion/extensions/apollo/helpers/confidence.rb', line 28 def corroboration_boost = settings[:confidence][:corroboration_boost] |
.corroboration_similarity_threshold ⇒ Object
37 38 39 |
# File 'lib/legion/extensions/apollo/helpers/confidence.rb', line 37 def corroboration_similarity_threshold settings[:confidence][:corroboration_similarity] end |
.decay_min_age_hours ⇒ Object
35 |
# File 'lib/legion/extensions/apollo/helpers/confidence.rb', line 35 def decay_min_age_hours = settings[:decay_min_age_hours] |
.decay_threshold ⇒ Object
31 |
# File 'lib/legion/extensions/apollo/helpers/confidence.rb', line 31 def decay_threshold = settings[:decay_threshold] |
.decayed?(confidence:) ⇒ Boolean
61 62 63 |
# File 'lib/legion/extensions/apollo/helpers/confidence.rb', line 61 def decayed?(confidence:, **) confidence < decay_threshold end |
.initial_confidence ⇒ Object
27 |
# File 'lib/legion/extensions/apollo/helpers/confidence.rb', line 27 def initial_confidence = settings[:confidence][:initial] |
.meets_write_gate?(confidence:, novelty:) ⇒ Boolean
65 66 67 |
# File 'lib/legion/extensions/apollo/helpers/confidence.rb', line 65 def meets_write_gate?(confidence:, novelty:, **) confidence > write_confidence_gate && novelty > write_novelty_gate end |
.power_law_alpha ⇒ Object
30 |
# File 'lib/legion/extensions/apollo/helpers/confidence.rb', line 30 def power_law_alpha = settings[:power_law_alpha] |
.retrieval_boost ⇒ Object
29 |
# File 'lib/legion/extensions/apollo/helpers/confidence.rb', line 29 def retrieval_boost = settings[:confidence][:retrieval_boost] |
.stale_days ⇒ Object
34 |
# File 'lib/legion/extensions/apollo/helpers/confidence.rb', line 34 def stale_days = settings[:stale_days] |
.write_confidence_gate ⇒ Object
32 |
# File 'lib/legion/extensions/apollo/helpers/confidence.rb', line 32 def write_confidence_gate = settings[:confidence][:write_gate] |
.write_novelty_gate ⇒ Object
33 |
# File 'lib/legion/extensions/apollo/helpers/confidence.rb', line 33 def write_novelty_gate = settings[:confidence][:novelty_gate] |