clophfit.fitting.ctr_validation#

Control holdout / leave-one-control-out validation helpers.

Functions#

ctr_param_name(group_name)

Return the shared-control K parameter name used by Bayesian multi-fit.

free_ctr_param_name(group_name, well)

Return the free-control K parameter name used by Bayesian multi-fit.

make_ctr_holdout_scheme(scheme, *, group_name, ...)

Return a PlateScheme copy with one control well removed.

iter_ctr_holdouts(scheme, *[, min_remaining])

Yield holdout tasks from all named control groups.

widen_heldout_k_prior(results, heldout_well, *, n_sd)

Return a deepcopy with the heldout well's K prior widened.

weighted_mean_reference(arrays)

Return an inverse-variance weighted posterior reference per draw.

summarize_bayesian_ctr_holdout(trace, *, trace_id, ...)

Summarize posterior CTR holdout ΔK.

summarize_ctr_loo_table(ctr_loo_df)

Collapse individual holdout rows into one row per model condition.

classical_ctr_holdout_rows(results, scheme, *, trace_id)

Post-hoc CTR holdout table for classical fits.

Module Contents#

clophfit.fitting.ctr_validation.ctr_param_name(group_name)#

Return the shared-control K parameter name used by Bayesian multi-fit.

Parameters:

group_name (str)

Return type:

str

clophfit.fitting.ctr_validation.free_ctr_param_name(group_name, well)#

Return the free-control K parameter name used by Bayesian multi-fit.

Parameters:
  • group_name (str)

  • well (str)

Return type:

str

clophfit.fitting.ctr_validation.make_ctr_holdout_scheme(scheme, *, group_name, heldout_well)#

Return a PlateScheme copy with one control well removed.

PlateScheme.names validates strictly as dict[str, set[str]] in ClopHfit, so this helper preserves that type.

Parameters:
  • scheme (Any)

  • group_name (str)

  • heldout_well (str)

Return type:

Any

clophfit.fitting.ctr_validation.iter_ctr_holdouts(scheme, *, min_remaining=1)#

Yield holdout tasks from all named control groups.

Parameters:
  • scheme (Any)

  • min_remaining (int)

Return type:

Iterator[dict[str, Any]]

clophfit.fitting.ctr_validation.widen_heldout_k_prior(results, heldout_well, *, n_sd, prior_sigma=0.6)#

Return a deepcopy with the heldout well’s K prior widened.

fit_binding_pymc_multi uses p.stderr * n_sd as the prior sigma for unknown wells. Increasing stderr avoids a control-LOO posterior that is dominated by a tiny preliminary-fit uncertainty.

Parameters:
  • results (Any)

  • heldout_well (str)

  • n_sd (float)

  • prior_sigma (float)

Return type:

Any

clophfit.fitting.ctr_validation.weighted_mean_reference(arrays)#

Return an inverse-variance weighted posterior reference per draw.

Parameters:

arrays (list[numpy.ndarray])

Return type:

tuple[numpy.ndarray, numpy.ndarray]

clophfit.fitting.ctr_validation.summarize_bayesian_ctr_holdout(trace, *, trace_id, ctr_group, heldout_well, remaining_ctr_wells=None, reference_mode='shared', rope=0.1)#

Summarize posterior CTR holdout ΔK.

reference_mode="shared" compares heldout K to K_ctr_{group}. reference_mode="weighted_mean" compares it to the inverse-variance weighted posterior mean of the remaining free-control K variables.

Parameters:
  • trace (Any)

  • trace_id (str)

  • ctr_group (str)

  • heldout_well (str)

  • remaining_ctr_wells (list[str] | None)

  • reference_mode (str)

  • rope (float)

Return type:

dict[str, Any]

clophfit.fitting.ctr_validation.summarize_ctr_loo_table(ctr_loo_df)#

Collapse individual holdout rows into one row per model condition.

Parameters:

ctr_loo_df (pandas.DataFrame)

Return type:

pandas.DataFrame

clophfit.fitting.ctr_validation.classical_ctr_holdout_rows(results, scheme, *, trace_id, rope=0.1)#

Post-hoc CTR holdout table for classical fits.

For each control well, compare its fitted K to the inverse-variance weighted mean K of the remaining control wells in the same group.

Parameters:
  • results (dict[str, Any])

  • scheme (Any)

  • trace_id (str)

  • rope (float)

Return type:

pandas.DataFrame