#[non_exhaustive]pub enum Sample {
Proportion {
units: u64,
events: u64,
},
Mean {
units: u64,
mean: f64,
variance: f64,
},
}Expand description
The cumulative data of one metric in one arm (spec 3.5 §7.12).
Samples are cumulative from the start of the experiment: each look carries the totals so far,
never one day’s increment, so sending the same look twice changes nothing. Sample::merge
adds an increment to a running total.
§Example
use adk_eval::experiments::Sample;
let monday = Sample::proportion(500, 20);
let tuesday = Sample::proportion(480, 25);
let total = monday.merge(&tuesday).unwrap();
assert_eq!(total, Sample::proportion(980, 45));
let revenue = Sample::from_values(&[0.0, 12.5, 0.0, 30.0]);
assert_eq!(revenue.units(), 4);
assert_eq!(revenue.estimate(), 10.625);Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Proportion
Units exposed, and how many of them had the event.
Fields
Mean
Units exposed, and the mean and sample variance of their per-unit values.
Implementations§
Source§impl Sample
impl Sample
Sourcepub fn proportion(units: u64, events: u64) -> Self
pub fn proportion(units: u64, events: u64) -> Self
Creates a proportion sample: events of units had the event.
Sourcepub fn mean(units: u64, mean: f64, variance: f64) -> Self
pub fn mean(units: u64, mean: f64, variance: f64) -> Self
Creates a mean sample from its summary statistics.
Sourcepub fn from_values(values: &[f64]) -> Self
pub fn from_values(values: &[f64]) -> Self
Summarises per-unit values as a mean sample.
Sourcepub fn kind(&self) -> MetricKind
pub fn kind(&self) -> MetricKind
Returns how the sample is measured.
Sourcepub fn estimate(&self) -> f64
pub fn estimate(&self) -> f64
Returns the rate of a proportion or the mean of a mean sample; 0.0 with no units.
Sourcepub fn merge(&self, other: &Sample) -> Result<Sample>
pub fn merge(&self, other: &Sample) -> Result<Sample>
Adds an increment of the same kind to this sample.
Mean samples combine with the parallel update of Chan, Golub and LeVeque, so merging daily summaries gives the same mean and variance as summarising every value at once.
§Errors
Returns EvalError::StatisticsError when the samples are of different kinds or either
is invalid.