use parlov_core::StrategyMetaForStop;
use super::evidence::EvidenceAccumulator;
#[derive(Debug, Clone, PartialEq)]
pub enum StopDecision {
Continue,
EarlyAccept {
posterior: f64,
},
EarlyReject {
posterior: f64,
},
}
const CONFIRM_THRESHOLD: f64 = 1.386_294_361_119_890_6;
const LIKELY_THRESHOLD: f64 = 0.405_465_108_108_164_4;
pub struct StopRule {
confirm_threshold: f64,
likely_threshold: f64,
}
impl StopRule {
#[must_use]
pub fn new() -> Self {
Self {
confirm_threshold: CONFIRM_THRESHOLD,
likely_threshold: LIKELY_THRESHOLD,
}
}
#[must_use]
pub fn evaluate(
&self,
accumulator: &EvidenceAccumulator,
remaining: &[StrategyMetaForStop],
) -> StopDecision {
let log_odds = accumulator.log_odds_current();
let max_neg = accumulator.max_negative_remaining(remaining);
let max_pos = accumulator.max_positive_remaining(remaining);
if log_odds - max_neg >= self.confirm_threshold {
return StopDecision::EarlyAccept {
posterior: accumulator.posterior_probability(),
};
}
if log_odds + max_pos < self.likely_threshold {
return StopDecision::EarlyReject {
posterior: accumulator.posterior_probability(),
};
}
StopDecision::Continue
}
}
impl Default for StopRule {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
#[path = "stop_rule_tests.rs"]
mod tests;