pub struct MetricStats {
pub mean: f64,
pub std_dev: f64,
pub ci_half_width: f64,
pub ci_lower: f64,
pub ci_upper: f64,
pub min: f64,
pub max: f64,
pub n: usize,
}Expand description
Statistical metrics with variance and confidence intervals.
This is the canonical type for evaluation metrics that need to track statistical properties across multiple runs or samples.
§Features
- Mean, standard deviation, and min/max range
- 95% confidence interval (both ± and lower/upper bounds)
- Sample count for determining statistical significance
- Formatting helpers for display
§Examples
use anno_core::types::MetricStats;
let stats = MetricStats::from_samples(&[0.85, 0.87, 0.82, 0.88, 0.84]);
println!("F1: {}", stats.format_ci()); // "85.2% ± 2.1%"
println!("Range: {}", stats.format_range()); // "85.2% (82.0%-88.0%)"Fields§
§mean: f64Mean value of the metric
std_dev: f64Standard deviation (sample, Bessel-corrected)
ci_half_width: f6495% confidence interval half-width (±)
ci_lower: f6495% CI lower bound
ci_upper: f6495% CI upper bound
min: f64Minimum observed value
max: f64Maximum observed value
n: usizeNumber of samples
Implementations§
Source§impl MetricStats
impl MetricStats
Sourcepub fn from_samples(samples: &[f64]) -> MetricStats
pub fn from_samples(samples: &[f64]) -> MetricStats
Create from a slice of sample values.
Uses sample standard deviation (Bessel’s correction) and t-distribution approximation for 95% CI.
§Examples
use anno_core::types::MetricStats;
let stats = MetricStats::from_samples(&[0.80, 0.82, 0.85, 0.83, 0.80]);
assert!((stats.mean - 0.82).abs() < 0.01);
assert_eq!(stats.n, 5);Sourcepub fn from_single(value: f64) -> MetricStats
pub fn from_single(value: f64) -> MetricStats
Create from a single value (no variance).
Sourcepub fn format_range(&self) -> String
pub fn format_range(&self) -> String
Format as “mean (min-max)” string (percentages).
Sourcepub fn format_ci_bounds(&self) -> String
pub fn format_ci_bounds(&self) -> String
Format as “mean [ci_lower, ci_upper]” string (percentages).
Sourcepub fn coefficient_of_variation(&self) -> f64
pub fn coefficient_of_variation(&self) -> f64
Get coefficient of variation (CV = std_dev / mean).
Lower CV indicates more stable/consistent results.
- CV < 0.05: Excellent stability
- CV < 0.10: Good stability
- CV < 0.20: Moderate stability
- CV >= 0.20: High variance, investigate
Sourcepub fn is_stable(&self, cv_threshold: f64) -> bool
pub fn is_stable(&self, cv_threshold: f64) -> bool
Check if results are statistically stable.
Returns true if coefficient of variation is below threshold.
Sourcepub fn ci_95_tuple(&self) -> (f64, f64)
pub fn ci_95_tuple(&self) -> (f64, f64)
Get 95% CI as a tuple (lower, upper).
For compatibility with code expecting tuple representation.
Sourcepub fn merge(&self, other: &MetricStats) -> MetricStats
pub fn merge(&self, other: &MetricStats) -> MetricStats
Merge with another MetricStats (combine samples).
Uses Welford’s online algorithm for numerically stable combination.
Trait Implementations§
Source§impl Clone for MetricStats
impl Clone for MetricStats
Source§fn clone(&self) -> MetricStats
fn clone(&self) -> MetricStats
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MetricStats
impl Debug for MetricStats
Source§impl Default for MetricStats
impl Default for MetricStats
Source§fn default() -> MetricStats
fn default() -> MetricStats
Source§impl<'de> Deserialize<'de> for MetricStats
impl<'de> Deserialize<'de> for MetricStats
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<MetricStats, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<MetricStats, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Display for MetricStats
impl Display for MetricStats
Source§impl PartialEq for MetricStats
impl PartialEq for MetricStats
Source§impl Serialize for MetricStats
impl Serialize for MetricStats
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Copy for MetricStats
impl StructuralPartialEq for MetricStats
Auto Trait Implementations§
impl Freeze for MetricStats
impl RefUnwindSafe for MetricStats
impl Send for MetricStats
impl Sync for MetricStats
impl Unpin for MetricStats
impl UnsafeUnpin for MetricStats
impl UnwindSafe for MetricStats
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read moreSource§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.