pub struct ExperimentAnalyzer { /* private fields */ }Expand description
The sequential analysis of a web experiment with one control and one variant (spec 3.5 §7.12, A-I15, §13 Q8).
Each call to observe analyses one look at the cumulative data and returns
an ExperimentReport. Looks may come as often as the caller likes — daily is typical —
without spending more than the ErrorBudget. Guardrails are checked
first at every look; a breach stops the experiment and keeps the control whatever the
primary metric shows. A final decision is kept: later looks return the same report.
See the module documentation for the method and its assumptions.
§Example
use adk_eval::experiments::{
Decision, ExperimentAnalyzer, ExperimentConfig, GuardrailSpec, Look, MetricDirection,
MetricSpec, Sample, StopReason, Tolerance,
};
let config = ExperimentConfig::new(
"headline",
MetricSpec::proportion("signups", MetricDirection::HigherIsBetter),
)
.with_guardrail(GuardrailSpec::new(
MetricSpec::proportion("unsubscribes", MetricDirection::LowerIsBetter),
Tolerance::Relative(0.1),
));
let mut analyzer = ExperimentAnalyzer::new(config).unwrap();
// Each day's look carries the totals so far: B lifts sign-ups from 4% to 5% but doubles
// unsubscribes from 0.5% to 1%.
let mut decision = Decision::Continue;
for day in 1..=28 {
let visitors = 600 * day;
let look = Look::new()
.with_metric(
"signups",
Sample::proportion(visitors, 24 * day),
Sample::proportion(visitors, 30 * day),
)
.with_metric(
"unsubscribes",
Sample::proportion(visitors, 3 * day),
Sample::proportion(visitors, 6 * day),
);
let report = analyzer.observe(&look).unwrap();
decision = report.decision;
if decision.is_final() {
break;
}
}
assert_eq!(
decision,
Decision::KeepControl {
reason: StopReason::GuardrailBreach { guardrails: vec!["unsubscribes".into()] }
}
);Implementations§
Source§impl ExperimentAnalyzer
impl ExperimentAnalyzer
Sourcepub fn new(config: ExperimentConfig) -> Result<Self>
pub fn new(config: ExperimentConfig) -> Result<Self>
Creates an analyzer for a new experiment.
§Errors
Returns EvalError::ConfigError when the configuration is invalid; see
ExperimentConfig::validate.
Sourcepub fn resume(config: ExperimentConfig, state: ExperimentState) -> Result<Self>
pub fn resume(config: ExperimentConfig, state: ExperimentState) -> Result<Self>
Resumes an experiment from its saved state.
§Errors
Returns EvalError::ConfigError when the configuration is invalid or the state
belongs to another experiment or another set of guardrails, and
EvalError::StatisticsError when a saved p-value is outside [0, 1].
Sourcepub fn config(&self) -> &ExperimentConfig
pub fn config(&self) -> &ExperimentConfig
Returns the configuration.
Sourcepub fn state(&self) -> &ExperimentState
pub fn state(&self) -> &ExperimentState
Returns the state to save between looks.
Sourcepub fn is_stopped(&self) -> bool
pub fn is_stopped(&self) -> bool
Returns whether the experiment has reached a final decision.
Sourcepub fn observe(&mut self, look: &Look) -> Result<ExperimentReport>
pub fn observe(&mut self, look: &Look) -> Result<ExperimentReport>
Analyses one look at the cumulative data and returns the decision with its evidence.
Once a look reaches a final decision, every later look returns that look’s report unchanged.
§Errors
Returns EvalError::StatisticsError when the look misses the primary metric or a
guardrail, carries a sample of the wrong kind or an invalid sample, or has fewer units
or events than the previous look (looks are cumulative). A refused look leaves the
state unchanged.