pub struct Calibration { /* private fields */ }Expand description
Process-wide calibration store. Concurrent updates are serialized via
a single RwLock because update events are rare (one per keyhog calibrate invocation or per verifier outcome) and the locked region is
constant-time. We deliberately don’t shard via DashMap - the persisted
artifact is small enough that contention is a non-issue.
Implementations§
Source§impl Calibration
impl Calibration
pub fn empty() -> Self
pub fn load(path: &Path) -> Self
pub fn save(&self, path: &Path) -> Result<()>
Sourcepub fn record_true_positive(&self, detector_id: &str)
pub fn record_true_positive(&self, detector_id: &str)
Record a true positive for detector_id (α += 1).
kimi-confidence audit: bare alpha += 1 would panic in debug
and wrap to 0 in release once a single detector accumulates
2^32 observations. Wrapping to 0 silently mutes a previously
reliable detector (posterior mean drops to 0.0/1.0 = 0). Use
saturating_add so the worst case is a frozen counter at
u32::MAX, which keeps the posterior mean correct.
Sourcepub fn record_false_positive(&self, detector_id: &str)
pub fn record_false_positive(&self, detector_id: &str)
Record a false positive for detector_id (β += 1). Same
saturating_add rationale as [record_true_positive].
Sourcepub fn confidence_multiplier(&self, detector_id: &str) -> f64
pub fn confidence_multiplier(&self, detector_id: &str) -> f64
Return the posterior mean for detector_id, falling back to 0.5
when no observations exist (uniform prior over a never-calibrated
detector). The scanner’s confidence-scoring path consumes this value,
but only when calibration is explicitly opted in (see the module-level
coherence contract) so default / benchmark scans stay deterministic.
Sourcepub fn counters(&self, detector_id: &str) -> BetaCounters
pub fn counters(&self, detector_id: &str) -> BetaCounters
Return the full counters for detector_id (defaults to Beta(1, 1)).
Sourcepub fn entries(&self) -> Vec<(String, BetaCounters)>
pub fn entries(&self) -> Vec<(String, BetaCounters)>
Iterate every recorded (detector_id, counters). Useful for
keyhog calibrate --show.
Trait Implementations§
Source§impl Debug for Calibration
impl Debug for Calibration
Source§impl Default for Calibration
impl Default for Calibration
Source§fn default() -> Calibration
fn default() -> Calibration
Auto Trait Implementations§
impl !Freeze for Calibration
impl !RefUnwindSafe for Calibration
impl Send for Calibration
impl Sync for Calibration
impl Unpin for Calibration
impl UnsafeUnpin for Calibration
impl UnwindSafe for Calibration
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more