Skip to main content

ExperimentAnalyzer

Struct ExperimentAnalyzer 

Source
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

Source

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.

Source

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].

Source

pub fn config(&self) -> &ExperimentConfig

Returns the configuration.

Source

pub fn state(&self) -> &ExperimentState

Returns the state to save between looks.

Source

pub fn is_stopped(&self) -> bool

Returns whether the experiment has reached a final decision.

Source

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.

Trait Implementations§

Source§

impl Clone for ExperimentAnalyzer

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ExperimentAnalyzer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Forget for ExperimentAnalyzer

§

impl Freeze for ExperimentAnalyzer

§

impl Move for ExperimentAnalyzer

§

impl RefUnwindSafe for ExperimentAnalyzer

§

impl Send for ExperimentAnalyzer
where RawVecInner: Send, NodeRef<Owned, String, ArmSamples, LeafOrInternal>: Send, BoxRaw<(String, ArmSamples)>: Send, NodeRef<Owned, String, f64, LeafOrInternal>: Send, BoxRaw<(String, f64)>: Send,

§

impl Sync for ExperimentAnalyzer
where RawVecInner: Sync, NodeRef<Owned, String, ArmSamples, LeafOrInternal>: Sync, BoxRaw<(String, ArmSamples)>: Sync, NodeRef<Owned, String, f64, LeafOrInternal>: Sync, BoxRaw<(String, f64)>: Sync,

§

impl Unpin for ExperimentAnalyzer
where *const u8 is !null: Unpin, *const LeafNode<String, ArmSamples> is !null: Unpin, Box<(String, ArmSamples)>: Unpin, *const LeafNode<String, f64> is !null: Unpin, Box<(String, f64)>: Unpin,

§

impl UnsafeUnpin for ExperimentAnalyzer

§

impl UnwindSafe for ExperimentAnalyzer

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more