pytyche.generators.api¶
v2 data generator — typed output via CalibrationBundle.
Adapts the v1 segment experiment generator (simulation.core) to produce
v2 typed contracts. Key differences from v1:
convertedcolumn isbool(notint).Returns
CalibrationBundle(observed, truth)instead ofExperimentDatawith an untypedground_truthdict.CalibrationTruth.metric_familyis a typedMetricFamilyenum — no dependency on v1get_metric_spec().validate_observed_data()runs before return — fail-closed.
Functions
|
Generate segment-aware experiment data with typed v2 output. |
- pytyche.generators.api.generate(n_visitors, segments, metric='conversion_rate', seed=42, experiment_id='sim-exp')[source]¶
Generate segment-aware experiment data with typed v2 output.
Statistical model is identical to v1
generate_segment_experiment: segment assignment via weightedrng.choice, per-segment Bernoulli conversion, per-segment LogNormal revenue for converters. Ground truth is computed analytically from planted parameters.- Parameters:
n_visitors (
int) – Total visitors, split evenly between control and treatment.segments (
dict[str,dict]) – Mapping of segment name to config dict. Each config must have:pct,base_conv,treatment_effect. Forrevenue_per_visitor: alsoaov_mu,aov_sigma, and optionallytreatment_aov_mu_shift.metric (
str) –"conversion_rate"or"revenue_per_visitor".seed (
int) – Random seed for reproducibility.experiment_id (
str) – Identifier stored on the returned data.
- Returns:
(observed, truth)— observed data validated viavalidate_observed_databefore return.- Return type: