pytyche.experiment.experiment¶
Per-round experiment snapshot: Experiment, CellObservation,
and the per-cell observed-performance computation.
An Experiment is one completed round of a sequential experiment —
the fitted posterior, its analysis, the cells that shipped, what each cell
observed, and the recommendation engine’s plan for the next round.
compute_cell_observations() produces the per-cell scoreboard from the
joint posterior conditioned on the actual cell-assignment indicators.
Functions
|
Per-cell observed performance from the joint posterior. |
Classes
|
Observed per-cell performance for one round. |
|
One round of a sequential experiment. |
- class pytyche.experiment.experiment.CellObservation(id, n_visitors, observed_rpv, observed_rpv_ci, lift_vs_control, lift_vs_control_ci, lift_vs_other_cells, policy_summary)[source]¶
Bases:
objectObserved per-cell performance for one round.
The scoreboard for the cells-as-blend story: when an operator ships a hypothesis cell alongside the recommendation engine’s cell, this is where per-cell RPV and cross-cell lift appear. All intervals follow the library-wide 80% credible convention.
- id¶
Matches the cell’s id.
- n_visitors¶
Visitors actually assigned to this cell this round.
- observed_rpv¶
Empirical revenue per visitor over the cell’s members.
- observed_rpv_ci¶
80% credible interval on the cell’s mean RPV from the joint posterior conditioned on the member rows.
- lift_vs_control¶
Point estimate of
observed_rpvminus the Control cell’s; exactly0.0on the Control cell itself.
- lift_vs_control_ci¶
80% credible interval on the lift;
(0.0, 0.0)on the Control cell.
- lift_vs_other_cells¶
Point estimates of lift vs each other non-Control cell, keyed by cell id (no self key, no control key). Empty on the Control cell — Control IS the reference, so per-cell lifts vs Control live on those cells’
lift_vs_control, not redundantly reversed here.
- policy_summary¶
cell.policy.describe().
- Parameters:
id (
str)n_visitors (
int)observed_rpv (
float)observed_rpv_ci (
tuple[float,float])lift_vs_control (
float)lift_vs_control_ci (
tuple[float,float])lift_vs_other_cells (
dict[str,float])policy_summary (
str)
- class pytyche.experiment.experiment.Experiment(round_idx, posterior, analysis, cells_shipped, cell_observations, next_recommendation, truth_comparison)[source]¶
Bases:
objectOne round of a sequential experiment.
Composes the existing public single-shot types (the fitted posterior and its
AnalysisResult) with the sequential-specific context: cells shipped, per-cell observations, the next-round recommendation, and the sim-only truth comparison.- round_idx¶
Zero-based round index.
- posterior¶
The round’s fitted posterior (fit on cumulative data); identical to
analysis.posterior.
- analysis¶
The round’s analysis summary.
- cells_shipped¶
The cell structure that actually served traffic.
- cell_observations¶
Per-cell observed performance, matching
cells_shippedorder.
- next_recommendation¶
The engine’s plan for the next round.
Noneonly on the engine’s provisional in-flight view; yielded experiments always carry a plan.
- truth_comparison¶
Sim-mode truth metrics;
Nonein real-data mode.
- Parameters:
round_idx (
int)posterior (
HurdleBCFResult|ContinuousBCFResult|BinaryBCFResult)analysis (
AnalysisResult)cells_shipped (
list[Cell])cell_observations (
list[CellObservation])next_recommendation (
NextRoundPlan|None)truth_comparison (
TruthComparison|None)
- property observed: ObservedExperimentData | None¶
The observed data the round’s posterior was fit on.
Read-only alias of
posterior.observed.
- pytyche.experiment.experiment.compute_cell_observations(posterior, cells, cell_assignment)[source]¶
Per-cell observed performance from the joint posterior.
cell_assignmentholds one cell id per concatenated visitor row (the extraction-adapter row order:observed.variantsframes concatenated in variant-list order). Point estimates are empirical means of the members’revenuecolumn; intervals condition the joint posterior on the membership indicators — each visitor contributes the level draws of its REALIZED arm (K = 2: thep0/p1×sev0/sev1channel selected by the row’s treatment indicator; K >= 3: thep_samples/sev_samples(n, S, K)slice at the realized arm), each cell’s per-draw member mean is reduced through the calibration-aware 80% interval path (pytyche.analysis._intervals.credible_interval).- Parameters:
posterior (
HurdleBCFResult) – The round’s hurdle posterior, carrying observed data and retained per-visitor level draws.cells (
list[Cell]) – The round’s cells; the output matches this order. Must include the'control'cell (the lift reference).cell_assignment (
ndarray) – Array of cell ids, one per concatenated visitor row.
- Return type:
list[CellObservation]- Returns:
One
CellObservationper cell, incellsorder.- Raises:
ValueError – When the posterior carries no observed data or no per-visitor level draws (neither the K = 2 channel arrays nor the K >= 3
p_samples/sev_samples), whencell_assignmentlength mismatches the visitor rows, when a cell has no assigned visitors, or when no cell has id'control'.